PnpGetDeviceResourcesFromRegistry

NTSTATUS __fastcall PnpGetDeviceResourcesFromRegistry(__int64 a1, int a2, char a3, VOID **a4, ULONG *a5){
  ULONG *v5; 
  int RegistryValue; 
  void *v10; 
  __int64 v11; 
  NTSTATUS result; 
  int v13; 
  __int64 v14; 
  __int64 v15; 
  int DeviceConfiguration; 
  wchar_t *v17; 
  __int64 v18; 
  _KEY_VALUE_FULL_INFORMATION *v19; 
  ULONG DataLength; 
  VOID **PoolWithTag; 
  _DWORD *v22; 
  UINT64 DesiredAccess; 
  _KEY_VALUE_FULL_INFORMATION *Information; 
  VOID *Handle; 

  v5 = a5;
  *a4 = 0i64;
  Handle = 0i64;
  RegistryValue = 0;
  *v5 = 0;
  Information = 0i64;
  if( a2 )
  {
    if( a1 )
      v14 = *(_QWORD *)(*(_QWORD *)(a1 + 312) + 40i64);
    else
      v14 = 0i64;
    LODWORD(DesiredAccess) = 131097;
    RegistryValue = CmOpenDeviceRegKey(
                      *(&stru_140CF2E80 + 607),
                      *(WCHAR **)(v14 + 48),
                      CM_KEY_TYPE_DEVICE_LOGCONF,
                      0i64,
                      DesiredAccess,
                      0,
                      &Handle,
                      0i64);
    if( RegistryValue < 0 )
      return RegistryValue;
    if( (a3 & 1) != 0 )
    {
      v17 = (wchar_t *)L"OverrideConfigVector";
    }
    else
    {
      if( (a3 & 2) == 0 )
      {
LABEL_26:
        LODWORD(v10) = (_DWORD)Handle;
        goto LABEL_12;
      }
      v17 = (wchar_t *)L"BasicConfigVector";
    }
    RegistryValue = IopGetRegistryValue(Handle, v17, 0i64, &Information);
    if( RegistryValue >= 0 )
    {
      v19 = Information;
      if( Information->Type == 10 )
      {
        DataLength = Information->DataLength;
        if( DataLength )
        {
          PoolWithTag = ExAllocatePoolWithTag(1ui64, DataLength, 1970499664i64);
          *a4 = PoolWithTag;
          if( PoolWithTag )
          {
            *v5 = v19->DataLength;
            memmove(*a4, (char *)v19 + v19->DataOffset, v19->DataLength);
            v22 = *a4;
            if( *((_DWORD *)*a4 + 1) == -1 )
            {
              v22[2] = 0;
              v22[1] = 1;
            }
          }
          else
          {
            RegistryValue = -1073741584;
          }
        }
      }
      ExFreePoolWithTag(v19, 0);
    }
    goto LABEL_26;
  }
  if( (a3 & 1) != 0 )
  {
    v18 = a1 ? *(_QWORD *)(*(_QWORD *)(a1 + 312) + 40i64) : 0i64;
    LODWORD(DesiredAccess) = 131097;
    RegistryValue = CmOpenDeviceRegKey(
                      *(&stru_140CF2E80 + 607),
                      *(WCHAR **)(v18 + 48),
                      CM_KEY_TYPE_DEVICE_CONTROL,
                      0i64,
                      DesiredAccess,
                      0,
                      &Handle,
                      0i64);
    if( RegistryValue >= 0 )
    {
      RegistryValue = PnpReadDeviceConfiguration(Handle, 1, a4, v5);
      ZwClose((_HANDLE)Handle);
      if( RegistryValue >= 0 )
        return RegistryValue;
    }
  }
  v10 = 0i64;
  Handle = 0i64;
  if( (a3 & 2) != 0 )
  {
    if( a1 )
      v15 = *(_QWORD *)(*(_QWORD *)(a1 + 312) + 40i64);
    else
      v15 = 0i64;
    LODWORD(DesiredAccess) = 131097;
    result = CmOpenDeviceRegKey(
               *(&stru_140CF2E80 + 607),
               *(WCHAR **)(v15 + 48),
               CM_KEY_TYPE_DEVICE_LOGCONF,
               0i64,
               DesiredAccess,
               0,
               &Handle,
               0i64);
    if( result < 0 )
      return result;
    DeviceConfiguration = PnpReadDeviceConfiguration(Handle, 2, a4, v5);
    v10 = Handle;
    RegistryValue = DeviceConfiguration;
    if( DeviceConfiguration >= 0 )
      goto LABEL_12;
  }
  if( (a3 & 4) == 0 )
    goto LABEL_11;
  if( v10 )
  {
LABEL_10:
    v13 = PnpReadDeviceConfiguration(v10, 4, a4, v5);
    v10 = Handle;
    RegistryValue = v13;
LABEL_11:
    if( !v10 )
      return RegistryValue;
LABEL_12:
    ZwClose((_HANDLE)v10);
    return RegistryValue;
  }
  if( a1 )
    v11 = *(_QWORD *)(*(_QWORD *)(a1 + 312) + 40i64);
  else
    v11 = 0i64;
  LODWORD(DesiredAccess) = 131097;
  result = CmOpenDeviceRegKey(
             *(&stru_140CF2E80 + 607),
             *(WCHAR **)(v11 + 48),
             CM_KEY_TYPE_DEVICE_LOGCONF,
             0i64,
             DesiredAccess,
             0,
             &Handle,
             0i64);
  if( result >= 0 )
  {
    v10 = Handle;
    goto LABEL_10;
  }
  return result;
}

Referenced by:

IopInitializeDeviceInstanceKey
IopPnPDispatch
IopQueryDeviceResources