PiCMDeleteDevice

VOID __fastcall PiCMDeleteDevice(
        VOID *IoctlInputBuffer,
        UINT64 IoctlInputBufferSize,
        VOID *IoctlOutputBuffer,
        UINT64 IoctlOutputBufferSize,
        INT64 Is32BitProcess,
        UINT64 *BytesUsed,
        INT64 a7,
        INT64 a8,
        INT64 a9,
        INT64 a10,
        INT64 a11,
        INT64 a12,
        INT64 a13,
        INT64 a14,
        INT64 a15,
        INT64 a16){
  UINT64 *v16; 
  unsigned int v17; 
  __int64 v19; 
  WCHAR *v20; 
  int inited; 
  _ETHREAD *v22; 
  WCHAR *v23; 
  _ETHREAD *CurrentThread; 
  INT64 v25; 
  unsigned int v26; 
  int v27; 
  int v28; 
  INT64 v29; 
  struct _UNICODE_STRING DestinationString; 
  INT64 v31[2]; 
  PCWSTR SourceString[2]; 
  UINT64 ExpectedOutputSize; 
  UNICODE_STRING DeviceInstance; 
  struct _UNICODE_STRING Buffer; 
  __int128 v36; 
  __int64 v37; 
  v16 = BytesUsed;
  v27 = 0;
  LODWORD(v29) = 0;
  v17 = IoctlOutputBufferSize;
  v28 = 0;
  *(_DWORD *)BytesUsed = 0;
  BytesUsed = 0i64;
  DestinationString = 0i64;
  ExpectedOutputSize = 0i64;
  *(_OWORD *)v31 = 0i64;
  v37 = 0i64;
  *(_OWORD *)SourceString = 0i64;
  Buffer = 0i64;
  v36 = 0i64;
  DeviceInstance = 0i64;
  if( (int)PiCMCaptureObjectInputData(
              (UINT64)IoctlInputBuffer,
              IoctlInputBufferSize,
              (unsigned int)Is32BitProcess,
              (INT64)v31) < 0 )
    goto LABEL_18;
  if( !PiAuDoesClientHaveAccess(2ui64) )
  {
    inited = -1073741790;
    goto LABEL_17;
  }
  v20 = (WCHAR *)SourceString[0];
  if( !SourceString[0]
    || *(INT64 *)((char *)v31 + 4) != 0x100000000i64
    || HIDWORD(SourceString[1])
    || !IoctlOutputBuffer
    || v17 < 8 )
  {
    goto LABEL_31;
  }
  inited = CmValidateDeviceName(v19, SourceString[0]);
  if( inited < 0 )
    goto LABEL_17;
  if( CmIsRootDevice(v20) )
  {
LABEL_31:
    inited = -1073741811;
    goto LABEL_17;
  }
  inited = PiPnpRtlBeginOperation((__int64 **)&BytesUsed);
  if( inited >= 0 )
  {
    if( (int)CmGetDeviceStatus(PiPnpRtlCtx, v20, 0i64, &v27, &v29, &v28, v26) >= 0 && (v27 & 2) != 0 )
    {
      if( (v27 & 0x2001) == 1 )
      {
        inited = -1073741808;
        goto LABEL_17;
      }
      inited = RtlInitUnicodeStringEx(&DestinationString, v20);
      if( inited < 0 )
        goto LABEL_17;
      PpDevNodeLockTree(3);
      CurrentThread = (_ETHREAD *)KeGetCurrentThread();
      --*((_WORD *)CurrentThread + 242);
      ExAcquireResourceExclusiveLite(&PnpRegistryDeviceResource, 1u);
      PpDeviceRegistration(&DestinationString, 0, 0i64, 1u);
      v23 = (WCHAR *)SourceString[0];
      inited = CmDeleteDevice(PiPnpRtlCtx, SourceString[0], 0);
      ExReleaseResourceLite(&PnpRegistryDeviceResource);
      KeLeaveCriticalRegion();
      PpDevNodeUnlockTree(3);
      if( inited < 0 )
        goto LABEL_17;
      if( (int)RtlInitUnicodeStringEx(&Buffer, v23) >= 0 )
      {
        *(_QWORD *)&v36 = 0x4000000000001i64;
        ZwPlugPlayControl();
      }
    }
    else
    {
      inited = RtlInitUnicodeStringEx(&DestinationString, v20);
      if( inited < 0 )
        goto LABEL_17;
      PpDevNodeLockTree(3);
      v22 = (_ETHREAD *)KeGetCurrentThread();
      --*((_WORD *)v22 + 242);
      ExAcquireResourceExclusiveLite(&PnpRegistryDeviceResource, 1u);
      PpDeviceRegistration(&DestinationString, 0, 0i64, 1u);
      v23 = (WCHAR *)SourceString[0];
      inited = CmDeleteDevice(PiPnpRtlCtx, SourceString[0], 0);
      ExReleaseResourceLite(&PnpRegistryDeviceResource);
      KeLeaveCriticalRegion();
      PpDevNodeUnlockTree(3);
      if( inited < 0 )
        goto LABEL_17;
      if( CmIsRootEnumeratedDevice(v23)
        && (int)RtlInitUnicodeStringEx(&DestinationString, (WCHAR *)L"HTREE\\ROOT\\0") >= 0 )
      {
        PiQueueDeviceRequest((INT64)&DestinationString, 8i64, v25, 1i64, 0i64);
      }
    }
    if( (int)RtlInitUnicodeStringEx(&DeviceInstance, v23) >= 0 )
      PnpSetDeviceInstancePropertyChangeEventFromDeviceInstance(&DeviceInstance);
  }
LABEL_17:
  PiCMReturnBasicResultData((unsigned int)inited, (unsigned int)ExpectedOutputSize, IoctlOutputBuffer, v17, v16);
LABEL_18:
  PiCMReleaseObjectInputData((INT64)v31);
  if( BytesUsed )
    PiPnpRtlEndOperation(BytesUsed);
}

Referenced by:

No references.