PiCMGetDeviceIdList

NTSTATUS __stdcall PiCMGetDeviceIdList(
        PVOID IoctlInputBuffer,
        UINT64 IoctlInputBufferSize,
        PVOID IoctlOutputBuffer,
        UINT64 IoctlOutputBufferSize,
        UINT64 *BytesUsed){
  UINT64 *v5; 
  unsigned int v6; 
  UINT8 *PoolWithTag; 
  INT64 v9; 
  INT64 v10; 
  NTSTATUS v11; 
  INT64 v12; 
  unsigned int v13; 
  unsigned int v14; 
  int v15; 
  int DeviceRelationsList; 
  int v17; 
  unsigned __int64 v18; 
  __int64 v19; 
  NTSTATUS v20; 
  const WCHAR *v22; 
  UINT64 BufferSize; 
  UINT64 ExpectedOutputSize; 
  UINT64 IoctlOutputBufferSizea; 
  int v26; 
  int v27; 
  __int128 v28; 
  UINT64 v29; 
  struct _SECURITY_SUBJECT_CONTEXT SubjectContext; 
  UINT64 *v31; 
  v5 = v31;
  v26 = 0;
  v6 = IoctlOutputBufferSize;
  v27 = 0;
  *(_DWORD *)v31 = 0;
  memset(&SubjectContext, 0, sizeof(SubjectContext));
  v29 = 0i64;
  PoolWithTag = 0i64;
  v28 = 0i64;
  v11 = PiCMCaptureDeviceListInputData(IoctlInputBuffer, IoctlInputBufferSize, (int)BytesUsed, (__int64)&v28);
  if( v11 < 0 )
    goto LABEL_22;
  v13 = DWORD1(v28);
  if( (byte_140C130BB & 2) != 0 )
  {
    if( WORD2(v28) )
    {
      switch( WORD2(v28) )
      {
        case 1u:
          v22 = L"Enum";
          break;
        case 2u:
          v22 = L"Service";
          break;
        case 4u:
          v22 = L"EjectRelations";
          break;
        case 8u:
          v22 = L"RemovalRelations";
          break;
        case 0x10u:
          v22 = L"PowerRelations";
          break;
        case 0x20u:
          v22 = L"BusRelations";
          break;
        case 0x40u:
          v22 = L"TransportRelations";
          break;
        case 0x80u:
          v22 = L"Class";
          break;
        default:
          v22 = L"Unknown";
          break;
      }
    }
    else
    {
      v22 = (const WCHAR *)L"None";
    }
    McTemplateK0zzt_EtwWriteTransfer((INT64)v22, v9, v12, *((const WCHAR **)&v28 + 1), v22, BYTE6(v28) & 1);
  }
  if( !IoctlOutputBuffer || v6 < 0x14 )
  {
    DeviceRelationsList = -1073741811;
LABEL_18:
    if( DeviceRelationsList >= 0 )
    {
      LODWORD(IoctlOutputBufferSizea) = v6;
      LODWORD(ExpectedOutputSize) = HIDWORD(v29);
      LODWORD(BufferSize) = 2 * v26;
      v20 = PiCMReturnBufferResultData(
              (unsigned int)DeviceRelationsList,
              (unsigned int)(2 * v26),
              0i64,
              PoolWithTag,
              BufferSize,
              ExpectedOutputSize,
              IoctlOutputBuffer,
              IoctlOutputBufferSizea,
              v5);
      goto LABEL_20;
    }
    goto LABEL_28;
  }
  v14 = 0;
  if( v6 - 20 >= 2 )
    v14 = v6 - 20;
  if( v14 )
  {
    PoolWithTag = (UINT8 *)ExAllocatePoolWithTag(PagedPool, v14, 0x34706E50ui64);
    if( !PoolWithTag )
    {
      DeviceRelationsList = -1073741670;
      goto LABEL_28;
    }
    v15 = v14 >> 1;
  }
  else
  {
    v15 = 0;
  }
  v26 = v15;
  DeviceRelationsList = PiCMConvertDeviceListFilters(v13, (INT64 *)&v27);
  if( DeviceRelationsList >= 0 )
  {
    v18 = (unsigned int)(unsigned __int16)v13 - 4;
    if( (unsigned int)v18 <= 0x3C && (v19 = 0x1000000010001011i64, _bittest64(&v19, v18)) )
    {
      if( !*((_QWORD *)&v28 + 1) )
      {
        DeviceRelationsList = -1073741811;
        goto LABEL_28;
      }
      DeviceRelationsList = CmGetDeviceRelationsList(
                              PiPnpRtlCtx,
                              *((const WCHAR **)&v28 + 1),
                              v27 & 0xFFFFFEFF,
                              (__int64)PoolWithTag,
                              v17,
                              (__int64)&v26);
      if( DeviceRelationsList < 0 )
        goto LABEL_28;
    }
    else
    {
      SeCaptureSubjectContext(&SubjectContext);
      DeviceRelationsList = CmGetMatchingFilteredDeviceList(
                              PiPnpRtlCtx,
                              *((__int64 *)&v28 + 1),
                              v27,
                              (__int64)PiCMMandatoryFilterCallback,
                              (__int64)&SubjectContext,
                              (__int64)PoolWithTag,
                              v26,
                              (__int64)&v26);
      SeReleaseSubjectContext(&SubjectContext);
      if( DeviceRelationsList < 0 )
      {
LABEL_17:
        v5 = v31;
        goto LABEL_18;
      }
    }
    if( !v26 )
    {
      v26 = 1;
      if( v14 < 2 )
      {
        DeviceRelationsList = -1073741789;
        goto LABEL_28;
      }
      *(_WORD *)PoolWithTag = 0;
    }
    goto LABEL_17;
  }
LABEL_28:
  LODWORD(IoctlOutputBufferSizea) = v6;
  LODWORD(ExpectedOutputSize) = HIDWORD(v29);
  LODWORD(BufferSize) = 0;
  v20 = PiCMReturnBufferResultData(
          (unsigned int)DeviceRelationsList,
          (unsigned int)(2 * v26),
          0i64,
          0i64,
          BufferSize,
          ExpectedOutputSize,
          IoctlOutputBuffer,
          IoctlOutputBufferSizea,
          v31);
LABEL_20:
  v11 = v20;
  if( PoolWithTag )
    ExFreePoolWithTag(PoolWithTag, 0x34706E50u);
LABEL_22:
  if( *((_QWORD *)&v28 + 1) )
    PiControlFreeUserModeCallersBuffer(*((_BYTE *)KeGetCurrentThread() + 562), *((PVOID *)&v28 + 1));
  if( (byte_140C130BB & 2) != 0 )
    McTemplateK0d_EtwWriteTransfer(v10, &KMPnPEvt_CfgMgr_DeviceList_Stop, v12, (unsigned int)v11);
  return v11;
}

Referenced by:

No references.