PiSwCompleteCreate

VOID __stdcall PiSwCompleteCreate(_DEVICE_OBJECT *DeviceObject){
  UINT64 v1; 
  _ETHREAD *CurrentThread; 
  __int64 v4; 
  _DEVICE_OBJECT *v5; 
  __int64 *v6; 
  __int64 v7; 
  void *v8; 
  WCHAR **v9; 
  WCHAR *v10; 
  UINT64 v11; 
  int PWSTR; 
  WCHAR v13; 
  UINT64 *v14; 
  __int64 v15; 
  __int64 v16; 
  __int64 *v17; 
  __int64 *i; 
  __int64 v19; 
  DEVPROPERTY *v20; 
  _LIST_ENTRY *j; 
  _LIST_ENTRY *Blink; 
  _LIST_ENTRY *v23; 
  __int64 v24; 
  int DeviceInterfaceReferenceString; 
  WCHAR v26; 
  char v27; 
  DEVPROPERTY *OutProperties; 
  _LIST_ENTRY InterfaceList; 
  __int64 v30; 
  PCWSTR SourceString; 
  CHAR *v32; 
  INT64 v33; 
  WCHAR **v34; 
  UINT64 pcbLength[3]; 
  struct _UNICODE_STRING UnicodeString; 
  GUID InterfaceClassGuid; 
  WCHAR v38[264]; 
  v1 = 0i64;
  InterfaceList.Blink = &InterfaceList;
  v34 = 0i64;
  InterfaceList.Flink = &InterfaceList;
  InterfaceClassGuid = 0i64;
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  v4 = 0i64;
  v33 = 0i64;
  LODWORD(OutProperties) = 0;
  v5 = 0i64;
  LODWORD(v30) = 0;
  --*((_WORD *)CurrentThread + 242);
  memset(pcbLength, 0, sizeof(pcbLength));
  v32 = 0i64;
  UnicodeString = 0i64;
  ExAcquireResourceExclusiveLite((ERESOURCE *)PiSwLockObj, 1u);
  v6 = (__int64 *)*((_QWORD *)DeviceObject + 8);
  v7 = *v6;
  if( *v6 )
  {
    *((_DWORD *)v6 + 2) &= 0xFFFFFFF9;
    v8 = *(void **)(v7 + 80);
    v9 = (WCHAR **)(*(_QWORD *)(*((_QWORD *)DeviceObject + 39) + 40i64) + 40i64);
    v34 = v9;
    if( v8 )
    {
      ExFreePoolWithTag(v8, 0x57706E50u);
      *(_OWORD *)(v7 + 72) = 0i64;
    }
    v10 = v9[1];
    v11 = ((unsigned __int64)*(unsigned __int16 *)v9 >> 1) + 1;
    SourceString = 0i64;
    PWSTR = PnpAllocatePWSTR(v10, v11, 0x57706E50ui64, (WCHAR **)&SourceString);
    if( PWSTR >= 0 )
    {
      RtlInitUnicodeString((PUNICODE_STRING)(v7 + 72), SourceString, v13);
      *(_DWORD *)(v7 + 4) |= 4u;
      if( !*(_QWORD *)(v7 + 88) )
      {
        v15 = *(_QWORD *)(v7 + 144);
        if( !v15
          || !_InterlockedExchange64((volatile __int64 *)(v15 + 104), 0i64)
          || (v4 = *(_QWORD *)(v7 + 144), *(_QWORD *)(v7 + 144) = 0i64, !v4)
          || (v16 = *(_QWORD *)(v4 + 184),
              PWSTR = RtlStringCbCopyW(*(PWCHAR *)(v4 + 24), *(unsigned int *)(v16 + 8), *(PWCHAR *)(v7 + 80)),
              PWSTR >= 0)
          && (PWSTR = RtlStringCbLengthW(*(const WCHAR **)(v4 + 24), *(unsigned int *)(v16 + 8), pcbLength), PWSTR >= 0) )
        {
          PWSTR = PnpCopyDevPropertyArray(*(unsigned int *)(v7 + 176), *(DEVPROPERTY **)(v7 + 168), v14, &OutProperties);
          if( PWSTR >= 0 )
          {
            v17 = (__int64 *)(v7 + 184);
            for( i = *(__int64 **)(v7 + 184); i != v17; i = (__int64 *)*i )
            {
              PWSTR = PiSwInterfaceCreate((WCHAR *)i[2], (DEVPROPERTY *)i[3], *((unsigned int *)i + 8), &v32);
              if( PWSTR < 0 )
                goto LABEL_15;
              Blink = InterfaceList.Blink;
              if( InterfaceList.Blink->Flink != &InterfaceList )
                __fastfail(3u);
              v23 = (_LIST_ENTRY *)v32;
              *(_QWORD *)v32 = &InterfaceList;
              v23->Blink = Blink;
              Blink->Flink = v23;
              InterfaceList.Blink = v23;
            }
            v5 = DeviceObject;
            ObfReferenceObject(DeviceObject);
          }
        }
      }
    }
  }
  else
  {
    PWSTR = -1073741811;
  }
LABEL_15:
  ExReleaseResourceLite((PERESOURCE)PiSwLockObj);
  KeLeaveCriticalRegionThread((__int64)KeGetCurrentThread());
  v20 = (DEVPROPERTY *)v33;
  if( PWSTR >= 0 )
  {
    if( !v33
      || (PWSTR = PiSwPropertySet(v34[1], (PVOID)1, v33, (DEVPROPERTY *)(unsigned int)OutProperties), PWSTR >= 0) )
    {
      for( j = InterfaceList.Flink; j != &InterfaceList; j = j->Flink )
      {
        PWSTR = CmGetDeviceInterfaceClassGuid(v19, (const WCHAR *)j[1].Flink, &InterfaceClassGuid);
        if( PWSTR < 0 )
          break;
        DeviceInterfaceReferenceString = CmGetDeviceInterfaceReferenceString(
                                           v24,
                                           (const WCHAR *)j[1].Flink,
                                           v38,
                                           0x104u,
                                           &v30);
        PWSTR = DeviceInterfaceReferenceString;
        if( DeviceInterfaceReferenceString == -1073741772 )
        {
          v27 = 0;
        }
        else
        {
          if( DeviceInterfaceReferenceString < 0 )
            break;
          v27 = 1;
          RtlInitUnicodeString((PUNICODE_STRING)&pcbLength[1], v38, v26);
        }
        PWSTR = IoRegisterDeviceInterface(
                  v5,
                  &InterfaceClassGuid,
                  (UNICODE_STRING *)((unsigned __int64)&pcbLength[1] & -(__int64)(v27 != 0)),
                  &UnicodeString);
        if( PWSTR < 0 )
          break;
        PWSTR = PiSwPropertySet(
                  (WCHAR *)j[1].Flink,
                  (PVOID)3,
                  (const INT64)j[1].Blink,
                  (DEVPROPERTY *)LODWORD(j[2].Flink));
        if( PWSTR < 0 )
          break;
      }
    }
  }
  if( v5 )
    HalPutDmaAdapter((PADAPTER_OBJECT)v5);
  if( v20 )
    PnpFreeDevPropertyArray((unsigned int)OutProperties, v20, 0x57706E50ui64);
  PiSwFreeInterfaceList(&InterfaceList);
  RtlFreeAnsiString(&UnicodeString);
  if( v4 )
  {
    if( PWSTR >= 0 )
      v1 = pcbLength[0] + 2;
    *(_QWORD *)(v4 + 56) = v1;
    *(_DWORD *)(v4 + 48) = PWSTR;
    IofCompleteRequest((_IRP *)v4, 0);
  }
}

Referenced by:

PiSwPdoPnPDispatch