PopFxUnregisterDevice

VOID __stdcall PopFxUnregisterDevice(_POP_FX_DEVICE *FxDevice){
  INT64 *v1; 
  unsigned int v3; 
  unsigned int i; 
  unsigned int v5; 
  struct _KEVENT *v6; 
  EVENT_DESCRIPTOR *v7; 
  UINT64 v8; 
  unsigned int j; 
  UINT64 v10; 
  __int64 v11; 
  UINT16 *v12; 
  int v13; 
  int v14; 
  INT64 v15; 
  unsigned int v16; 
  __int64 v17; 
  int v18; 
  unsigned __int64 k; 
  int v20; 
  UINT64 a3; 
  unsigned int v22; 
  int v23; 
  unsigned int v24; 
  __int64 v25; 
  struct _KEVENT *v26; 
  struct _EVENT_DATA_DESCRIPTOR UserData; 
  struct _EVENT_DATA_DESCRIPTOR v28; 
  int *v29; 
  __int64 v30; 
  int *v31; 
  __int64 v32; 
  __int64 v33; 
  int v34[2]; 
  int *v35; 
  __int64 v36; 
  int *v37; 
  __int64 v38; 
  int *v39; 
  __int64 v40; 
  __int64 *v41; 
  __int64 v42; 
  if( (*((_DWORD *)FxDevice + 206) & 1) == 0 )
  {
    v3 = *((_DWORD *)FxDevice + 207);
    for( i = 0; i < v3; ++i )
    {
      PoFxActivateComponent((POHANDLE *)FxDevice, i, 2ui64);
      v3 = *((_DWORD *)FxDevice + 207);
    }
    v5 = 0;
    if( v3 )
    {
      do
        KeWaitForSingleObject(
          (PVOID)(*(_QWORD *)(*((_QWORD *)FxDevice + 104) + 8i64 * v5++) + 104i64),
          Executive,
          0,
          0,
          0i64);
      while( v5 < *((_DWORD *)FxDevice + 207) );
    }
  }
  v6 = (struct _KEVENT *)*((_QWORD *)FxDevice + 6);
  if( v6 )
  {
    PopFxRemoveDevice((INT64)FxDevice, (INT64)FxDevice, v1);
    v26 = v6;
    PopFxAddLogEntry((INT64)v6, 0, 2, 0i64);
    if( PopDiagHandleRegistered )
    {
      v8 = PopDiagHandle;
      if( EtwEventEnabled(PopDiagHandle, (EVENT_DESCRIPTOR *)&POP_ETW_EVENT_DEVICE_UNREGISTRATION, v7) )
      {
        *(_QWORD *)&UserData.Size = 8i64;
        UserData.Ptr = (unsigned __int64)&v26;
        EtwWrite(v8, (EVENT_DESCRIPTOR *)&POP_ETW_EVENT_DEVICE_UNREGISTRATION, 0i64, 1ui64, &UserData);
      }
    }
    PopFxAssignDeviceToDevNode((__int64)v6, 0i64);
  }
  for( j = 0; j < *((_DWORD *)FxDevice + 207); ++j )
  {
    if( *(int *)(*(_QWORD *)(*((_QWORD *)FxDevice + 104) + 8i64 * j) + 96i64) > 0 )
      _InterlockedDecrement(&PopFxResidentComponentCount);
  }
  IoReleaseRemoveLockAndWaitEx((char *)FxDevice + 240, 0);
  PopPepUnregisterDevice(*((PVOID *)FxDevice + 7));
  v10 = *((_QWORD *)FxDevice + 8);
  if( v10 )
    PopPluginUnregisterDevice(v10, *((_QWORD *)FxDevice + 9));
  v11 = *((_QWORD *)FxDevice + 148);
  if( v11 )
  {
    v12 = *(UINT16 **)(v11 + 16);
    PopPlLockPowerPlane((INT64)v12);
    v13 = *(_DWORD *)(v11 + 32);
    a3 = 0x100000000i64;
    v14 = PopPlCalculateDevicePowerDraw((INT64)FxDevice, (INT64 *)((char *)&a3 + 4), &a3, 0i64);
    *(_DWORD *)(v11 + 32) = v14;
    v16 = v14 - v13;
    if( (unsigned int)dword_140C021E8 > 5 )
    {
      v23 = v14;
      v30 = 2i64;
      LOWORD(v20) = 1;
      v32 = 2i64;
      v29 = &v20;
      v34[1] = 0;
      v31 = v34;
      v33 = *((_QWORD *)FxDevice + 28);
      v34[0] = *((unsigned __int16 *)FxDevice + 108);
      v35 = (int *)&v22;
      v37 = &v23;
      v39 = (int *)&v24;
      v17 = *(_QWORD *)(v11 + 16);
      v22 = v16;
      v36 = 4i64;
      v38 = 4i64;
      v24 = v16;
      v40 = 4i64;
      v18 = *(_DWORD *)(v17 + 28);
      v41 = &v25;
      LODWORD(v25) = v16 + v18;
      v42 = 4i64;
      tlgWriteTransfer_EtwWriteTransfer(
        (__int64)&dword_140C021E8,
        (unsigned __int8 *)byte_140029325,
        0i64,
        0i64,
        9u,
        &v28);
    }
    PopPlPublishSystemPowerChange(v12, v16, v15);
    for( k = 0i64;
          k < *((unsigned int *)FxDevice + 207);
          PopPlUnregisterComponent(*(_QWORD *)(*((_QWORD *)FxDevice + 104) + 8 * k++)) )
    {
      ;
    }
    *(_QWORD *)(v11 + 24) = 0i64;
    *((_QWORD *)FxDevice + 148) = 0i64;
    PopPlUnlockPowerPlane((INT64)v12);
  }
  if( v6 )
    KeSetEvent(v6 + 4, 0);
  if( (*((_DWORD *)FxDevice + 206) & 1) != 0 )
    PopFxDestroyDeviceDpm((__int64)v6, (__int64)FxDevice);
}

Referenced by:

PoFxUnregisterDevice
PopFxUnregisterDeviceOrWait