PnpDeviceEventWorker

void __fastcall PnpDeviceEventWorker(PVOID P){
  char v2; 
  __int64 v3; 
  _QWORD *v4; 
  _QWORD *v5; 
  __int64 v6; 
  __int64 v7; 
  __int64 v8; 
  int v9; 
  int v10; 
  int v11; 
  int v12; 
  int v13; 
  _QWORD *v14; 
  __int64 v15; 
  PVOID Pa; 
  _UNICODE_STRING DestinationString; 
  _GUID ActivityId; 

  ActivityId = 0i64;
  Pa = 0i64;
  DestinationString = 0i64;
  PnpDeviceEventThread = (__int64)KeGetCurrentThread();
  if( KeWaitForSingleObject(PnpDeviceEventList + 8, 0, 0, 0, 0i64) < 0 )
  {
    KeAcquireGuardedMutex((PKGUARDED_MUTEX)((char *)&PnpReplaceEvent + 64));
    KeSetEvent((PRKEVENT)((char *)&PnpReplaceEvent + 32), 0, 0);
    BYTE2(NlsMbCodePageTag) = 0;
    KeReleaseGuardedMutex((PKGUARDED_MUTEX)((char *)&PnpReplaceEvent + 64));
    PnpDeviceEventThread = 0i64;
    return;
  }
  while( 1 )
  {
    v2 = 0;
    KeAcquireGuardedMutex((PKGUARDED_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((PKGUARDED_MUTEX)(v3 + 64));
    Pa = v5;
    v7 = *(_QWORD *)&NullGuid.Data1 - v5[11];
    if( *(_QWORD *)&NullGuid.Data1 == v5[11] )
      v7 = *(_QWORD *)NullGuid.Data4 - v5[12];
    if( v7 )
    {
      ActivityId = *(_GUID *)(v5 + 11);
      IoSetActivityIdThread((INT64)&ActivityId);
      v2 = 1;
    }
    v8 = v5[19];
    v9 = 0;
    if( v8 && !*(_QWORD *)(*(_QWORD *)(v8 + 312) + 40i64) )
      v9 = -1073741810;
    if( *(&PnpReplaceEvent + 1665)
      && !_InterlockedCompareExchange64((volatile signed __int64 *)qword_140CEC8C0, 0i64, 0i64) )
    {
      v9 = -1073741431;
    }
    if( v9 < 0 )
      goto LABEL_25;
    v5[13] = PnpEnableWatchdog(1, (__int64)v5);
    v10 = *((_DWORD *)v5 + 32);
    if( v10 > 4 )
    {
      if( v10 < 6 )
        goto LABEL_40;
      if( v10 > 8 )
      {
        if( v10 != 11 && v10 != 9 && v10 != 10 )
        {
LABEL_40:
          v9 = -1073741823;
          goto LABEL_25;
        }
        v13 = PiUEventNotifyUserMode((__int64)v5);
LABEL_24:
        v9 = v13;
      }
LABEL_25:
      if( v9 == 259 )
        goto LABEL_29;
      goto LABEL_26;
    }
    if( v10 != 4 )
    {
      if( !v10 )
      {
        v9 = PiUEventNotifyUserMode((__int64)v5);
        if( v9 >= 0 )
          PnpNotifyHwProfileChange(v5 + 14, (_DWORD *)v5[6], (_UNICODE_STRING *)v5[7]);
        goto LABEL_25;
      }
      v11 = v10 - 1;
      if( !v11 )
      {
        v13 = PnpProcessTargetDeviceEvent((const VOID **)&Pa);
        goto LABEL_24;
      }
      v12 = v11 - 1;
      if( v12 )
      {
        if( v12 != 1 )
          goto LABEL_40;
        v13 = PnpProcessCustomDeviceEvent((__int64 *)&Pa);
        goto LABEL_24;
      }
      RtlInitUnicodeString(&DestinationString, (PCWSTR)v5 + 88);
      PnpNotifyDeviceClassChange((__int128 *)v5 + 7, (__int128 *)v5 + 10, &DestinationString);
    }
    PiUEventNotifyUserMode((__int64)v5);
    v9 = 0;
LABEL_26:
    v14 = Pa;
    v15 = *((_QWORD *)Pa + 13);
    if( v15 )
    {
      PnpDisableWatchdog(v15);
      v14[13] = 0i64;
    }
    PnpCompleteDeviceEvent(Pa, v9);
LABEL_29:
    PnpProcessDeferredRegistrations();
    if( v2 )
      IoSetActivityIdThread(0i64);
  }
  KeAcquireGuardedMutex((PKGUARDED_MUTEX)((char *)&PnpReplaceEvent + 64));
  KeSetEvent((PRKEVENT)((char *)&PnpReplaceEvent + 32), 0, 0);
  BYTE2(NlsMbCodePageTag) = 0;
  PnpProcessDeferredRegistrations();
  KeReleaseGuardedMutex((PKGUARDED_MUTEX)((char *)&PnpReplaceEvent + 64));
  KeReleaseGuardedMutex((PKGUARDED_MUTEX)(PnpDeviceEventList + 64));
  if( P )
    ExFreePoolWithTag(P, 0x4C706E50u);
  PnpDeviceEventThread = 0i64;
  KeReleaseMutex((_KMUTANT *)(PnpDeviceEventList + 8), 0);
}

Referenced by:

No references.