PnpDeviceEventWorker

VOID __stdcall PnpDeviceEventWorker(PVOID Context){
  char v2; 
  __int64 v3; 
  _QWORD *v4; 
  _QWORD *v5; 
  __int64 v6; 
  _BYTE *v7; 
  __int64 v8; 
  __int64 v9; 
  int v10; 
  WCHAR v11; 
  int v12; 
  int v13; 
  int v14; 
  int v15; 
  _QWORD *v16; 
  INT64 v17; 
  _BYTE *v18; 
  PVOID P; 
  struct _UNICODE_STRING DestinationString; 
  _GUID ActivityId; 
  ActivityId = 0i64;
  P = 0i64;
  DestinationString = 0i64;
  PnpDeviceEventThread = (__int64)KeGetCurrentThread();
  if( KeWaitForSingleObject((PVOID)(PnpDeviceEventList + 8), Executive, 0, 0, 0i64) < 0 )
  {
    KeAcquireGuardedMutex(&PnpNotificationInProgressLock);
    KeSetEvent(&PnpEventQueueEmpty, 0);
    BYTE2(NlsMbCodePageTag) = 0;
    KeReleaseGuardedMutex(&PnpNotificationInProgressLock);
    PnpDeviceEventThread = 0i64;
    return;
  }
  while( 1 )
  {
    v2 = 0;
    KeAcquireGuardedMutex((FAST_MUTEX *)(PnpDeviceEventList + 64));
    v3 = PnpDeviceEventList;
    v4 = (_QWORD *)(PnpDeviceEventList + 120);
    v5 = *(_QWORD **)(PnpDeviceEventList + 120);
    if( v5 == (_QWORD *)(PnpDeviceEventList + 120) )
      break;
    if( (_QWORD *)v5[1] != v4 || (v6 = *v5, *(_QWORD **)(*v5 + 8i64) != v5) )
      __fastfail(3u);
    *v4 = v6;
    *(_QWORD *)(v6 + 8) = v4;
    v5[1] = v5;
    *v5 = v5;
    KeReleaseGuardedMutex((_FAST_MUTEX *)(v3 + 64));
    P = v5;
    v8 = *(_QWORD *)&NullGuid.Data1 - v5[11];
    if( *(_QWORD *)&NullGuid.Data1 == v5[11] )
      v8 = *(_QWORD *)NullGuid.Data4 - v5[12];
    if( v8 )
    {
      ActivityId = *(_GUID *)(v5 + 11);
      IoSetActivityIdThread(&ActivityId, v7);
      v2 = 1;
    }
    v9 = v5[19];
    v10 = 0;
    if( v9 && !*(_QWORD *)(*(_QWORD *)(v9 + 312) + 40i64) )
      v10 = -1073741810;
    if( PnpShutdownEvent.Header.SignalState
      && !_InterlockedCompareExchange64((volatile signed __int64 *)PnpDeviceActionThread, 0i64, 0i64) )
    {
      v10 = -1073741431;
    }
    if( v10 < 0 )
      goto LABEL_25;
    v5[13] = PnpEnableWatchdog(1i64, (INT64)v5);
    v12 = *((_DWORD *)v5 + 32);
    if( v12 > 4 )
    {
      if( v12 < 6 )
        goto LABEL_40;
      if( v12 > 8 )
      {
        if( v12 != 11 && v12 != 9 && v12 != 10 )
        {
LABEL_40:
          v10 = -1073741823;
          goto LABEL_25;
        }
        v15 = PiUEventNotifyUserMode((__int64)v5);
LABEL_24:
        v10 = v15;
      }
LABEL_25:
      if( v10 == 259 )
        goto LABEL_29;
      goto LABEL_26;
    }
    if( v12 != 4 )
    {
      if( !v12 )
      {
        v10 = PiUEventNotifyUserMode((__int64)v5);
        if( v10 >= 0 )
          PnpNotifyHwProfileChange((GUID *)v5 + 7, (PNP_VETO_TYPE *)v5[6], (UNICODE_STRING *)v5[7]);
        goto LABEL_25;
      }
      v13 = v12 - 1;
      if( !v13 )
      {
        v15 = PnpProcessTargetDeviceEvent((const void **)&P);
        goto LABEL_24;
      }
      v14 = v13 - 1;
      if( v14 )
      {
        if( v14 != 1 )
          goto LABEL_40;
        v15 = PnpProcessCustomDeviceEvent((__int64 *)&P);
        goto LABEL_24;
      }
      RtlInitUnicodeString(&DestinationString, (PCWSTR)v5 + 88, v11);
      PnpNotifyDeviceClassChange((GUID *)v5 + 7, (GUID *)v5 + 10, &DestinationString);
    }
    PiUEventNotifyUserMode((__int64)v5);
    v10 = 0;
LABEL_26:
    v16 = P;
    v17 = *((_QWORD *)P + 13);
    if( v17 )
    {
      PnpDisableWatchdog(v17);
      v16[13] = 0i64;
    }
    PnpCompleteDeviceEvent(P, v10);
LABEL_29:
    PnpProcessDeferredRegistrations();
    if( v2 )
      IoSetActivityIdThread(0i64, v18);
  }
  KeAcquireGuardedMutex(&PnpNotificationInProgressLock);
  KeSetEvent(&PnpEventQueueEmpty, 0);
  BYTE2(NlsMbCodePageTag) = 0;
  PnpProcessDeferredRegistrations();
  KeReleaseGuardedMutex(&PnpNotificationInProgressLock);
  KeReleaseGuardedMutex((_FAST_MUTEX *)(PnpDeviceEventList + 64));
  if( Context )
    ExFreePoolWithTag(Context, 0x4C706E50u);
  PnpDeviceEventThread = 0i64;
  KeReleaseMutex((PRKMUTEX)(PnpDeviceEventList + 8), 0);
}

Referenced by:

No references.