PipProcessDevNodeTree

INT64 __fastcall PipProcessDevNodeTree(INT64 a1, INT64 a2, INT64 a3, INT64 a4, CHAR a5, UINT8 a6, CHAR a7){
  CHAR v7; 
  INT64 v8; 
  unsigned int v9; 
  INT64 v10; 
  char *v11; 
  char v12; 
  unsigned __int8 v13; 
  INT64 v14; 
  INT64 v15; 
  ULONG_PTR v16; 
  int v17; 
  int v18; 
  int started; 
  int restarted; 
  UINT64 v21; 
  int v22; 
  int v23; 
  ULONG_PTR v24; 
  INT64 v25; 
  __int64 v27; 
  NTSTATUS v28; 
  UNICODE_STRING *v29; 
  _QWORD *v30; 
  char v31; 
  char v32; 
  unsigned int v33; 
  INT64 v34; 
  struct _UNICODE_STRING DestinationString; 
  struct _KEVENT Event; 
  UINT64 Completed; 
  char v38; 
  INT64 v39; 
  unsigned int v40; 
  v40 = a4;
  v39 = a3;
  v7 = a7;
  v8 = a3;
  v34 = a1;
  LOBYTE(Completed) = 0;
  v9 = a4;
  v10 = a2;
  v11 = (char *)a1;
  DestinationString = 0i64;
  if( a2 && !*(_BYTE *)(a2 + 28) && (_DWORD)a4 != 1 && !a7 && PiCollapseEnumRequests((_LIST_ENTRY *)a2) )
    v11 = (char *)IopRootDeviceNode;
  v12 = 0;
  v33 = 0;
  v32 = 0;
  v13 = 0;
  v31 = 0;
  while( 2 )
  {
    if( !v7 )
    {
      if( (byte_140C130BB & 8) != 0 )
        McTemplateK0z_EtwWriteTransfer(a1, &KMPnPEvt_AssignResources_Start, 0i64, *((const WCHAR **)v11 + 6));
      LOBYTE(a2) = a5;
      a7 = 0;
      v31 = PnpProcessAssignResources((INT64)v11, a2);
      if( (byte_140C130BB & 8) != 0 )
        McTemplateK0z_EtwWriteTransfer(v14, &KMPnPEvt_AssignResources_Stop, v15, *((const WCHAR **)v11 + 6));
      if( a7 )
      {
        if( (unsigned int)PipProcessDevNodeTree((INT64)IopRootDeviceNode, v10, v8, v9, 0, 0, 1) == -1073741106 )
          v12 = 1;
        v32 = v12;
      }
    }
    a7 = 0;
    v16 = (ULONG_PTR)v11;
    v38 = 1;
    do
    {
      v17 = 1;
      if( v32 )
        goto LABEL_105;
      if( *(_DWORD *)(v16 + 300) != 769
        && (*(_DWORD *)(v16 + 396) & 0x6000) == 0
        && PnpCheckForActiveDependencies(v16, 2u) )
      {
        PipSetDevNodeProblem(v16, 51, 0);
      }
      a2 = *(unsigned int *)(v16 + 396);
      if( (a2 & 0x6000) != 0 )
        goto LABEL_75;
      switch( *(_DWORD *)(v16 + 300) )
      {
        case 0x301:
          if( v9 == 3 && (a2 & 0x2000000) != 0 || v7 )
            goto LABEL_68;
          if( PnpCheckForActiveDependencies(v16, 1u) )
          {
            PipSetDevNodeProblem(v16, 51, 0);
            goto LABEL_68;
          }
          PiProcessNewDeviceNode((_DEVICE_NODE *)v16);
          v18 = v22;
          if( v22 >= 0 )
            v17 = 0;
          goto LABEL_67;
        case 0x302:
          if( v7 )
            goto LABEL_68;
          v18 = PipCallDriverAddDevice(v16, v39);
          if( v18 >= 0 )
          {
            PoFxPrepareDevice(v16, 0);
            v17 = 0;
            v31 = 1;
          }
          goto LABEL_67;
        case 0x304:
          if( v7 )
            goto LABEL_68;
          PoFxActivateDevice(*(DEVICE_OBJECT **)(v16 + 32));
          v21 = a6;
          *(_DWORD *)(v16 + 704) |= 0x200u;
          PipProcessStartPhase1((_DEVICE_NODE *)v16, v21, v13);
LABEL_40:
          v18 = restarted;
          if( restarted == 259 )
          {
            v13 = 1;
LABEL_68:
            LOBYTE(Completed) = 0;
            v18 = PnpDeviceCompletionProcessCompletedRequests(0i64, 0i64, &Completed);
            if( v18 != -1073741106 )
            {
              if( !(_BYTE)Completed && a7 )
              {
                a7 = 0;
                v18 = PnpDeviceCompletionProcessCompletedRequests(0i64, 1ui64, &Completed);
                v13 &= -((_BYTE)Completed != 0);
              }
              if( v18 != -1073741106 )
                goto LABEL_75;
            }
            goto LABEL_73;
          }
          v17 = 0;
          goto LABEL_67;
        case 0x306:
          started = PipProcessStartPhase2(v16, a2, 0i64);
          goto LABEL_37;
        case 0x307:
          if( (int)a2 < 0 )
          {
            v17 = 1;
            goto LABEL_68;
          }
          started = PipProcessStartPhase3(v16, v9 != 1, 0i64);
          goto LABEL_37;
      }
      if( *(_DWORD *)(v16 + 300) != 776 )
      {
        if( *(_DWORD *)(v16 + 300) != 778 )
        {
          if( *(_DWORD *)(v16 + 300) != 779 )
          {
            if( *(_DWORD *)(v16 + 300) != 781 )
              goto LABEL_68;
            if( (*(_DWORD *)(v16 + 704) & 0x200) != 0 )
            {
              PoFxIdleDevice(*(DEVICE_OBJECT **)(v16 + 32));
              *(_DWORD *)(v16 + 704) &= ~0x200u;
            }
            v18 = PipEnumerateCompleted(v16);
            v17 = 2;
            goto LABEL_67;
          }
          started = PipProcessRestartPhase2(v16, a2, 0i64);
LABEL_37:
          v18 = started;
          if( started < 0 )
          {
            v18 = -1073741106;
            goto LABEL_67;
          }
LABEL_49:
          v17 = 0;
          goto LABEL_67;
        }
        restarted = PipProcessRestartPhase1(v16, a6, v13);
        goto LABEL_40;
      }
      if( v9 == 1 && (char *)v16 != v11 )
        goto LABEL_68;
      v17 = 2;
      if( v7 || (a2 & 8) == 0 )
        goto LABEL_68;
      v18 = PipEnumerateDevice((_DEVICE_NODE *)v16, a6, v13);
      if( v18 == 259 )
      {
        v13 = 1;
        v17 = 1;
        goto LABEL_68;
      }
      if( v18 >= 0 )
        goto LABEL_49;
LABEL_67:
      if( v18 != -1073741106 )
        goto LABEL_68;
LABEL_73:
      if( v7 )
      {
        v33 = v18;
LABEL_75:
        a1 = 1i64;
        if( !v7 && (*(_DWORD *)(v16 + 704) & 1) != 0 )
        {
          PpDevCfgTraceDeviceStart((_DWORD *)v16);
          a1 = 1i64;
        }
        if( v13 && v17 && PnpAsyncOptions >= 0 )
          v17 = 1;
        v23 = v17 - 1;
        if( v23 )
        {
          if( v23 == 1 )
          {
            v24 = *(_QWORD *)(v16 + 8);
            if( !v24 )
              goto LABEL_92;
LABEL_85:
            v16 = v24;
          }
        }
        else
        {
          while( 1 )
          {
LABEL_92:
            if( (char *)v16 == v11 )
            {
              a7 = 1;
              LOBYTE(a1) = -(v13 != 0);
              v38 &= a1;
              goto LABEL_86;
            }
            v24 = *(_QWORD *)v16;
            if( *(_QWORD *)v16 )
              goto LABEL_85;
            if( v13 && PnpAsyncOptions && PnpAsyncOptions >= 0 )
              break;
            if( *(_QWORD *)(v16 + 16) )
              v16 = *(_QWORD *)(v16 + 16);
          }
          v27 = *(_QWORD *)(v16 + 16);
          if( v27 )
            v16 = *(_QWORD *)(v27 + 8);
          a7 = 1;
        }
LABEL_86:
        v25 = v34;
        v12 = v32;
        goto LABEL_87;
      }
      v9 = v40;
LABEL_105:
      v12 = 0;
      v32 = 0;
      PnpDeviceCompletionProcessCompletedRequests(1ui64, 1ui64, &Completed);
      v13 = 0;
      PipProcessDevNodeTree((INT64)IopRootDeviceNode, v10, v39, v9, a5, a6, 1);
      v28 = IopAllocateUnicodeString(&DestinationString, *((_WORD *)v11 + 20));
      if( v28 < 0 )
      {
        HalPutDmaAdapter(*(PADAPTER_OBJECT *)(v34 + 32));
        return(unsigned int)v28;
      }
      RtlCopyUnicodeString(&DestinationString, (UNICODE_STRING *)(v11 + 40), v29);
      HalPutDmaAdapter(*(PADAPTER_OBJECT *)(v34 + 32));
      PpDevNodeUnlockTree(1);
      LODWORD(v34) = 0;
      memset(&Event, 0, sizeof(Event));
      KeInitializeEvent(&Event, NotificationEvent, 0);
      if( (int)PnpInsertNoopEvent((INT64)&Event, (INT64)&v34) >= 0 )
        KeWaitForSingleObject(&Event, Executive, 0, 0, 0i64);
      PpDevNodeLockTree(1);
      v30 = PnpDeviceObjectFromDeviceInstanceWithTag((INT64)&DestinationString, 0x746C6644ui64);
      RtlFreeAnsiString(&DestinationString);
      if( !v30 )
        return 3221225473i64;
      v11 = *(char **)(v30[39] + 40i64);
      v25 = (INT64)v11;
      v16 = (ULONG_PTR)v11;
      v34 = (INT64)v11;
LABEL_87:
      v9 = v40;
    }
    while( v38 );
    v8 = v39;
    if( v31 )
      continue;
    break;
  }
  if( !v7 )
    HalPutDmaAdapter(*(PADAPTER_OBJECT *)(v25 + 32));
  return v33;
}

Referenced by:

PiProcessReenumeration
PiProcessResourceRequirementsChanged
PiProcessStartSystemDevices
PiRestartDevice
PipProcessDevNodeTree
PnpDeviceActionWorker
PnpProcessRebalance