PnpDeviceActionWorker

void PnpDeviceActionWorker(){
  char v0; 
  char v1; 
  char v2; 
  NTSTATUS v3; 
  char v4; 
  _KIRQL v5; 
  __int64 v6; 
  char v7; 
  __int64 v8; 
  __int64 v9; 
  _ETHREAD *CurrentThread; 
  char v11; 
  _QWORD *v12; 
  __int64 v13; 
  __int64 v14; 
  int v15; 
  NTSTATUS started; 
  _KIRQL v17; 
  NTSTATUS PowerRelations; 
  int v19; 
  volatile signed __int32 *v20; 
  __int64 v21; 
  NTSTATUS *v22; 
  _KEVENT *v23; 
  __int64 v24; 
  _DEVICE_NODE *v25; 
  int v26; 
  int v27; 
  int v28; 
  int v29; 
  int v30; 
  int v31; 
  int v32; 
  INT64 v33; 
  UINT64 ReallocateResources; 
  UINT64 Synchronous; 
  UINT64 ProcessOnlyIntermediateStates; 
  char v37; 
  char v38; 
  char v39; 
  _ADD_CONTEXT AddContext; 
  __int128 NotificationStructure[2]; 
  __int64 v42; 
  __int128 v43; 

  AddContext = 0i64;
  memset(NotificationStructure, 0, sizeof(NotificationStructure));
  v42 = 0i64;
  v0 = 0;
  v37 = 0;
  v43 = 0i64;
  v1 = 0;
  _InterlockedExchange64((volatile __int64 *)qword_140CEC8C0, (__int64)KeGetCurrentThread());
  v2 = 0;
  PpDevNodeLockTree(PPL_TREEOP_ALLOW_READS);
  while( 1 )
  {
    v39 = 0;
    v3 = 0;
    v38 = 1;
    v4 = KeAcquireSpinLockRaiseToDpc((UINT64 *)&PnpReplaceEvent + 50);
    v6 = *(&PnpReplaceEvent + 48);
    v7 = v4;
    if( (_UNKNOWN *)*(&PnpReplaceEvent + 48) != (_UNKNOWN *)((char *)&PnpReplaceEvent + 384) )
    {
      if( *(_UNKNOWN **)(*(&PnpReplaceEvent + 48) + 8i64) != (_UNKNOWN *)((char *)&PnpReplaceEvent + 384)
        || (v8 = **(&PnpReplaceEvent + 48), *(_QWORD *)(**(&PnpReplaceEvent + 48) + 8i64) != *(&PnpReplaceEvent + 48)) )
      {
LABEL_99:
        __fastfail(3u);
      }
      *(&PnpReplaceEvent + 48) = **(&PnpReplaceEvent + 48);
      *(_QWORD *)(v8 + 8) = (char *)&PnpReplaceEvent + 384;
      *(_BYTE *)(v6 + 76) = 1;
      goto LABEL_6;
    }
    if( !v0 && !v1 && !v2 )
      break;
    v6 = 0i64;
LABEL_6:
    LOBYTE(v5) = v7;
    KeReleaseSpinLock((PKSPIN_LOCK)&PnpReplaceEvent + 50, v5);
    if( v6 )
    {
      v9 = *(_QWORD *)&NullGuid.Data1 - *(_QWORD *)(v6 + 56);
      if( *(_QWORD *)&NullGuid.Data1 == *(_QWORD *)(v6 + 56) )
        v9 = *(_QWORD *)NullGuid.Data4 - *(_QWORD *)(v6 + 64);
      if( v9 )
      {
        v39 = 1;
        v43 = *(_OWORD *)(v6 + 56);
        KeGetCurrentThread()[1].WaitBlock[1].WaitListEntry.Flink = (_LIST_ENTRY *)&v43;
      }
      CurrentThread = (_ETHREAD *)KeGetCurrentThread();
      --CurrentThread->Tcb.KernelApcDisable;
      ExAcquirePushLockExclusiveEx((_EX_PUSH_LOCK *)(v6 + 80), 0i64);
      v11 = *(_BYTE *)(v6 + 88);
      ExReleasePushLockEx(v6 + 80, 0);
      KeLeaveCriticalRegion();
      PoNotifyPnpActionQueueEvent(2i64, *(unsigned int *)(v6 + 24));
      *(_QWORD *)(v6 + 8) = v6;
      *(_QWORD *)v6 = v6;
      if( *(&PnpReplaceEvent + 1665) )
      {
        v3 = -1073741431;
      }
      else if( v11 )
      {
        v3 = -1073741536;
      }
      else
      {
        v12 = *(_QWORD **)(v6 + 16);
        if( v12 )
          v13 = *(_QWORD *)(v12[39] + 40i64);
        else
          v13 = 0i64;
        if( *(_DWORD *)(v13 + 300) != 788 )
        {
          if( v12 )
            v14 = *(_QWORD *)(v12[39] + 40i64);
          else
            v14 = 0i64;
          if( v14 )
          {
            ObfReferenceObjectWithTag(v12, 0x65706E50ui64);
            PnpLogActionQueueEvent(v14, *(_DWORD *)(v6 + 24), 1i64, 0);
          }
          v15 = *(_DWORD *)(v6 + 24);
          if( v15 <= 12 )
          {
            if( v15 != 12 )
            {
              if( v15 > 5 )
              {
                if( v15 == 6 )
                {
                  PowerRelations = PnpProcessRebalance((_PNP_DEVICE_ACTION_ENTRY *)v6);
                  goto LABEL_33;
                }
                if( v15 == 7 )
                {
                  v1 = 1;
                }
                else
                {
                  if( v15 <= 10 )
                    goto LABEL_26;
                  PowerRelations = PiProcessRequeryDeviceState((_PNP_DEVICE_ACTION_ENTRY *)v6);
LABEL_33:
                  v3 = PowerRelations;
                }
LABEL_34:
                if( v14 )
                {
                  PnpLogActionQueueEvent(v14, *(_DWORD *)(v6 + 24), 2i64, v3);
                  ObfDereferenceObjectWithTag(*(VOID **)(v6 + 16), 0x65706E50ui64);
                }
                goto LABEL_36;
              }
              if( v15 == 5 )
              {
                v24 = *(_QWORD *)(v6 + 16);
                if( v24 )
                  v25 = *(_DEVICE_NODE **)(*(_QWORD *)(v24 + 312) + 40i64);
                else
                  v25 = 0i64;
                PowerRelations = PiQueryPowerRelations(v25, 0);
                goto LABEL_33;
              }
              if( !v15 )
              {
                v0 = 1;
                goto LABEL_34;
              }
              v26 = v15 - 1;
              if( v26 )
              {
                v27 = v26 - 1;
                if( !v27 )
                {
                  PowerRelations = PpProcessClearProblem((_PNP_DEVICE_ACTION_ENTRY *)v6);
                  goto LABEL_33;
                }
                v32 = v27 - 1;
                if( v32 )
                {
                  if( v32 == 1 )
                  {
                    PowerRelations = PiProcessHaltDevice((_PNP_DEVICE_ACTION_ENTRY *)v6);
                    goto LABEL_33;
                  }
                  goto LABEL_80;
                }
              }
LABEL_70:
              PiProcessClearDeviceProblem((_PNP_DEVICE_ACTION_ENTRY *)v6);
              goto LABEL_33;
            }
LABEL_69:
            PowerRelations = PiRestartDevice((_PNP_DEVICE_ACTION_ENTRY *)v6);
            goto LABEL_33;
          }
          if( v15 <= 18 )
          {
            if( v15 == 18 )
            {
              v37 = 1;
              goto LABEL_34;
            }
            v28 = v15 - 13;
            if( !v28 )
            {
              v3 = PiProcessResourceRequirementsChanged((_PNP_DEVICE_ACTION_ENTRY *)v6);
              if( v3 < 0 )
              {
                v0 = 1;
                v3 = 0;
              }
              goto LABEL_34;
            }
            v29 = v28 - 1;
            if( !v29 )
            {
LABEL_26:
              started = PiProcessReenumeration((_PNP_DEVICE_ACTION_ENTRY *)v6);
LABEL_27:
              v3 = started;
              v38 = 0;
              goto LABEL_34;
            }
            v30 = v29 - 1;
            if( !v30 )
            {
              PiProcessSetDeviceProblem((_PNP_DEVICE_ACTION_ENTRY *)v6);
              goto LABEL_33;
            }
            v31 = v30 - 1;
            if( !v31 )
              goto LABEL_69;
            if( v31 == 1 )
            {
              started = PiProcessStartSystemDevices((_PNP_DEVICE_ACTION_ENTRY *)v6);
              goto LABEL_27;
            }
LABEL_80:
            v3 = -1073741823;
            goto LABEL_34;
          }
          if( v15 == 19 )
          {
            DWORD1(NotificationStructure[1]) = 0;
            *(GUID *)((char *)NotificationStructure + 4) = GUID_TARGET_DEVICE_TRANSPORT_RELATIONS_CHANGED;
            LODWORD(NotificationStructure[0]) = 2359297;
            *((_QWORD *)&NotificationStructure[1] + 1) = 0i64;
            v42 = 0xFFFFFFFFi64;
            IoReportTargetDeviceChangeAsynchronous(*(_QWORD *)(v6 + 16), (INT64)NotificationStructure, 0i64, 0i64);
            v33 = 21i64;
          }
          else
          {
            if( v15 != 20 )
            {
              if( v15 <= 24 )
              {
                PiConfigureDevice((_PNP_DEVICE_ACTION_ENTRY *)v6);
                goto LABEL_33;
              }
              if( v15 == 25 )
                goto LABEL_70;
              goto LABEL_80;
            }
            v33 = 17i64;
          }
          PiPnpRtlPdoRaiseNtPlugPlayPropertyChangeEvent(*(PVOID *)(v6 + 16), v33);
          goto LABEL_34;
        }
        v3 = -1073741823;
      }
LABEL_36:
      PoNotifyPnpActionQueueEvent(3i64, *(unsigned int *)(v6 + 24));
      v19 = 1;
      do
      {
        v20 = *(volatile signed __int32 **)v6;
        if( *(_QWORD *)(*(_QWORD *)v6 + 8i64) != v6 )
          goto LABEL_99;
        v21 = *(_QWORD *)v20;
        if( *(volatile signed __int32 **)(*(_QWORD *)v20 + 8i64) != v20 )
          goto LABEL_99;
        *(_QWORD *)v6 = v21;
        *(_QWORD *)(v21 + 8) = v6;
        PoNotifyPnpActionQueueEvent(1i64, *((unsigned int *)v20 + 6));
        v22 = (NTSTATUS *)*((_QWORD *)v20 + 6);
        if( v22 )
          *v22 = v3;
        v23 = (_KEVENT *)*((_QWORD *)v20 + 5);
        if( v23 )
          KeSetEvent(v23, 0, 0);
        if( v20 == (volatile signed __int32 *)v6 )
        {
          v19 = 0;
          if( v38 )
            HalPutDmaAdapter(*((PADAPTER_OBJECT *)v20 + 2));
        }
        PnpDeleteDeviceActionRequest(v20);
      }
      while( v19 );
      v2 = v37;
      if( v39 )
        KeGetCurrentThread()[1].WaitBlock[1].WaitListEntry.Flink = 0i64;
    }
    else if( v0 || v1 )
    {
      AddContext.DriverStartType = 3;
      AddContext.LoadDriver = *(&PnpReplaceEvent + 6682);
      ObfReferenceObject(*(PVOID *)(*(&PnpReplaceEvent + 831) + 32i64));
      LOBYTE(ProcessOnlyIntermediateStates) = 0;
      LOBYTE(Synchronous) = 0;
      LOBYTE(ReallocateResources) = v0;
      PipProcessDevNodeTree(
        *(&PnpReplaceEvent + 831),
        0i64,
        &AddContext,
        v1 == 0 ? EnumTypeIgnoreUninstalledDevices : EnumTypeNone,
        ReallocateResources,
        Synchronous,
        ProcessOnlyIntermediateStates);
      v0 = 0;
      v1 = 0;
    }
    else
    {
      PnpCompleteSystemStartProcess();
      v2 = 0;
      v37 = 0;
    }
  }
  *(&PnpReplaceEvent + 289) = 0;
  KeSetEvent((PRKEVENT)((char *)&PnpReplaceEvent + 352), 0, 0);
  LOBYTE(v17) = v7;
  KeReleaseSpinLock((PKSPIN_LOCK)&PnpReplaceEvent + 50, v17);
  _InterlockedExchange64((volatile __int64 *)qword_140CEC8C0, 0i64);
  PpDevNodeUnlockTree(PPL_TREEOP_ALLOW_READS);
}

Referenced by:

PnpRequestDeviceAction