PiGetDeviceRegProperty

__int64 __fastcall PiGetDeviceRegProperty(const wchar_t *a1, __int64 a2, int a3, int a4, void *Src, __int64 a6){
  INT8 *v8; 
  int DeviceRegProp; 
  unsigned int v10; 
  UINT8 *PoolWithTag; 
  wchar_t *v13; 
  int AlternateStringData; 
  UINT64 v15; 
  wchar_t *v16; 
  char v17; 
  WCHAR *v18; 
  int v19; 
  __int64 v20; 
  WCHAR *v21; 
  INT8 *v22; 
  int v23; 
  WCHAR *v24; 
  UINT64 Length; 
  unsigned int NumberOfBytes; 
  UINT64 NumberOfBytes_4; 
  wchar_t *Str; 
  WCHAR *MessageFormat; 
  NTSTRSAFE_PWSTR Buffer; 
  INT8 *Arguments; 
  INT64 result[19]; 
  NumberOfBytes_4 = (unsigned int)a4;
  v8 = 0i64;
  NumberOfBytes = *(_DWORD *)a6;
  Buffer = (NTSTRSAFE_PWSTR)Src;
  DeviceRegProp = CmGetDeviceRegProp(
                    PiPnpRtlCtx,
                    a1,
                    0i64,
                    a4,
                    (__int64)&NumberOfBytes_4 + 4,
                    (__int64)Src,
                    (__int64)&NumberOfBytes,
                    0);
  v10 = DeviceRegProp;
  if( a3 == 1 )
  {
    if( DeviceRegProp < 0 )
    {
      if( DeviceRegProp != -1073741789 )
        return v10;
    }
    else if( HIDWORD(NumberOfBytes_4) != 1 )
    {
      return(unsigned int)-1073741584;
    }
    PoolWithTag = (UINT8 *)ExAllocatePoolWithTag(PagedPool, NumberOfBytes, 0x6F697050ui64);
    v13 = (wchar_t *)PoolWithTag;
    if( !PoolWithTag )
      return(unsigned int)-1073741670;
    if( v10 != -1073741789 )
    {
      memmove(PoolWithTag, (UINT8 *)Src, NumberOfBytes);
      goto LABEL_15;
    }
    v19 = CmGetDeviceRegProp(
            PiPnpRtlCtx,
            a1,
            0i64,
            NumberOfBytes_4,
            (__int64)&NumberOfBytes_4 + 4,
            (__int64)PoolWithTag,
            (__int64)&NumberOfBytes,
            0);
    v10 = v19;
    if( v19 < 0 )
    {
      if( v19 == -1073741789 )
        *(_DWORD *)a6 = NumberOfBytes;
    }
    else
    {
      if( HIDWORD(NumberOfBytes_4) == 1 )
      {
LABEL_15:
        LODWORD(NumberOfBytes_4) = NumberOfBytes;
        Str = v13;
        MessageFormat = v13;
        AlternateStringData = PnpFindAlternateStringData(v13, NumberOfBytes, &Str, &NumberOfBytes_4);
        v15 = (unsigned int)NumberOfBytes_4;
        v16 = Str;
        if( AlternateStringData )
        {
          MessageFormat = Str;
          v18 = wcsstr(Str, L";(");
          v8 = (INT8 *)v18;
          if( v18 )
          {
            v20 = ((unsigned int)v15 >> 1) - 2;
            if( v16[v20] == 41 )
            {
              *v18 = 0;
              v8 = (INT8 *)(v18 + 2);
              v16[v20] = 0;
              memset((INT64)result, 0i64);
              v21 = (WCHAR *)v8;
              Arguments = v8;
              for( LODWORD(NumberOfBytes_4) = 1; ; LODWORD(NumberOfBytes_4) = v23 + 1 )
              {
                v24 = wcschr(v21, 0x2Cu);
                if( !v24 )
                  break;
                *v24 = 0;
                v22 = (INT8 *)(v24 + 1);
                v23 = NumberOfBytes_4;
                if( (unsigned int)NumberOfBytes_4 >= 0x13 )
                {
                  v17 = 1;
                  goto LABEL_17;
                }
                result[(unsigned int)NumberOfBytes_4 - 1] = (INT64)v22;
                v21 = (WCHAR *)v22;
              }
            }
          }
        }
        v17 = 0;
LABEL_17:
        if( *(_DWORD *)a6 < (unsigned int)v15 )
        {
          v10 = -1073741789;
        }
        else if( v8 )
        {
          if( v17 )
          {
            v10 = -1073741619;
          }
          else
          {
            LODWORD(Length) = *(_DWORD *)a6;
            v10 = RtlFormatMessageEx(MessageFormat, 0i64, 0, 0, 1u, &Arguments, Buffer, Length, (UINT64 *)a6);
          }
        }
        else
        {
          memmove((UINT8 *)Buffer, (UINT8 *)v16, v15);
        }
        *(_DWORD *)a6 = v15;
        goto LABEL_21;
      }
      v10 = -1073741584;
    }
LABEL_21:
    ExFreePoolWithTag(v13, 0);
    return v10;
  }
  if( DeviceRegProp >= 0 )
  {
    if( HIDWORD(NumberOfBytes_4) != a3 )
      v10 = -1073741584;
    if( (v10 & 0x80000000) == 0 )
      goto LABEL_8;
  }
  if( v10 == -1073741789 )
LABEL_8:
    *(_DWORD *)a6 = NumberOfBytes;
  return v10;
}

Referenced by:

IoGetDeviceProperty
IopPnPDispatch