PiCMGetRelatedDeviceInstance

NTSTATUS __stdcall PiCMGetRelatedDeviceInstance(
        VOID *IoctlInputBuffer,
        UINT64 IoctlInputBufferSize,
        VOID *IoctlOutputBuffer,
        UINT64 IoctlOutputBufferSize,
        UINT64 *BytesUsed){
  unsigned int v5; 
  VOID *v6; 
  VOID **PoolWithTag; 
  unsigned int v8; 
  WCHAR *v9; 
  WCHAR *v10; 
  int inited; 
  unsigned int v12; 
  unsigned int v13; 
  unsigned int v14; 
  NTSTATUS DeviceParent; 
  NTSTATUS v16; 
  VOID **v18; 
  UINT64 BufferSize; 
  UINT64 ExpectedOutputSize; 
  UINT64 IoctlOutputBufferSizea; 
  UINT64 ParentDeviceInstanceIdLength; 
  _UNICODE_STRING DestinationString; 
  _CMAPI_INPUT_OBJECT_DATA ObjectData[4]; 
  WCHAR *DeviceInstanceId[2]; 
  UINT64 v26; 
  unsigned int v28; 
  UINT64 *v29; 

  v28 = IoctlOutputBufferSize;
  v26 = 0i64;
  v5 = IoctlOutputBufferSize;
  v6 = IoctlOutputBuffer;
  PoolWithTag = 0i64;
  v8 = 0;
  *(_OWORD *)ObjectData = 0i64;
  *(_DWORD *)v29 = 0;
  v9 = 0i64;
  *(_OWORD *)DeviceInstanceId = 0i64;
  DestinationString = 0i64;
  inited = PiCMCaptureObjectInputData(
             IoctlInputBuffer,
             IoctlInputBufferSize,
             (_CMAPI_INPUT_OBJECT_DATA *)(unsigned int)BytesUsed);
  if( inited < 0 )
    goto LABEL_23;
  if( DeviceInstanceId[0] && !ObjectData[1] && ObjectData[2] == 1 )
  {
    if( v6 && v5 >= 0x14 )
    {
      v12 = v5 - 20;
      v13 = 0;
      v14 = 2;
      if( v12 >= 2 )
        v13 = v12;
      if( v13 )
      {
        PoolWithTag = ExAllocatePoolWithTag(1ui64, v13, 879783504i64);
        if( !PoolWithTag )
          inited = -1073741670;
      }
      if( inited < 0 )
        goto LABEL_35;
      inited = CmValidateDeviceName(v10);
      if( inited < 0 )
        goto LABEL_35;
      switch( HIDWORD(DeviceInstanceId[1]) )
      {
        case 1:
          LODWORD(ParentDeviceInstanceIdLength) = v13 >> 1;
          DeviceParent = CmGetDeviceParent(
                           *(&stru_140CF2E80 + 607),
                           DeviceInstanceId[0],
                           (WCHAR *)PoolWithTag,
                           &ParentDeviceInstanceIdLength);
          v8 = ParentDeviceInstanceIdLength;
          inited = DeviceParent;
LABEL_16:
          v5 = v28;
          v6 = IoctlOutputBuffer;
          goto LABEL_17;
        case 2:
LABEL_25:
          inited = RtlInitUnicodeStringEx(&DestinationString, DeviceInstanceId[0]);
          if( inited < 0 )
            goto LABEL_35;
          LODWORD(ParentDeviceInstanceIdLength) = 400;
          v18 = ExAllocatePoolWithTag(1ui64, 0x190ui64, 879783504i64);
          v9 = (WCHAR *)v18;
          if( !v18 )
          {
            inited = -1073741670;
            goto LABEL_35;
          }
          inited = PiGetRelatedDevice(&DestinationString, (WCHAR *)v18, &ParentDeviceInstanceIdLength, v14);
          if( inited < 0 )
          {
LABEL_35:
            LODWORD(IoctlOutputBufferSizea) = v28;
            LODWORD(ExpectedOutputSize) = v26;
            LODWORD(BufferSize) = 0;
            v16 = PiCMReturnBufferResultData(
                    (unsigned int)inited,
                    2 * v8,
                    0i64,
                    0i64,
                    BufferSize,
                    ExpectedOutputSize,
                    IoctlOutputBuffer,
                    IoctlOutputBufferSizea,
                    v29);
            goto LABEL_19;
          }
          LODWORD(ExpectedOutputSize) = 2048;
          inited = RtlStringCbCopyExW((WCHAR *)PoolWithTag, v13, v9, 0i64, 0i64, ExpectedOutputSize);
          if( inited == -2147483643 )
            inited = -1073741789;
          v8 = ((unsigned int)ParentDeviceInstanceIdLength >> 1) + 1;
          goto LABEL_16;
        case 3:
          if( CmIsRootDevice(DeviceInstanceId[0]) )
          {
            inited = -1073741810;
            goto LABEL_35;
          }
          v14 = 3;
          goto LABEL_25;
      }
    }
    inited = -1073741811;
    goto LABEL_35;
  }
  inited = -1073741811;
LABEL_17:
  if( inited < 0 )
    goto LABEL_35;
  LODWORD(IoctlOutputBufferSizea) = v5;
  LODWORD(ExpectedOutputSize) = v26;
  LODWORD(BufferSize) = 2 * v8;
  v16 = PiCMReturnBufferResultData(
          (unsigned int)inited,
          2 * v8,
          0i64,
          PoolWithTag,
          BufferSize,
          ExpectedOutputSize,
          v6,
          IoctlOutputBufferSizea,
          v29);
LABEL_19:
  inited = v16;
  if( PoolWithTag )
    ExFreePoolWithTag(PoolWithTag, 0x34706E50u);
  if( v9 )
    ExFreePoolWithTag(v9, 0x34706E50u);
LABEL_23:
  PiCMReleaseObjectInputData(ObjectData);
  return inited;
}

Referenced by:

PiCMHandleIoctl