DrvDbGetDeviceIdMappedProperty

NTSTATUS __stdcall DrvDbGetDeviceIdMappedProperty(
        _DRVDB_CONTEXT *pDrvDbCtx,
        WCHAR *DeviceId,
        VOID *ObjectBaseKey,
        _DEVPROPKEY *PropertyKey,
        UINT64 *PropertyType,
        VOID *PropertyBuffer,
        UINT64 BufferSize,
        UINT64 *PropertySize){
  INT64 *v10; 
  unsigned int pid; 
  __int64 v12; 
  WCHAR *v13; 
  _UNICODE_STRING *v14; 
  NTSTATUS v15; 
  VOID *v16; 
  int RegValueMappedProperty; 
  __int64 v19; 
  __int64 v20; 
  int v21; 
  unsigned int v22; 
  unsigned int v23; 
  WORD *v24; 
  WCHAR *v25; 
  int v26; 
  NTSTATUS ObjectDatabaseNodeName; 
  unsigned int v28; 
  __int64 **i; 
  __int64 *v30; 
  __int64 v31; 
  __int64 v32; 
  const _DRVDB_PROPERTY_REG_VALUE_MAP *v33; 
  UINT64 Create; 
  UINT64 BaseKeyHandle; 
  UINT8 IncludeMatchData[4]; 
  unsigned int v37; 
  WCHAR *DriverInfMatches; 
  _DRVDB_CONTEXT *pDrvDbCtxa; 
  char v40; 

  pDrvDbCtxa = pDrvDbCtx;
  DriverInfMatches = 0i64;
  v10 = (INT64 *)pDrvDbCtx;
  *(_DWORD *)IncludeMatchData = 0;
  *(_DWORD *)PropertyType = 0;
  *(_DWORD *)PropertySize = 0;
  pid = PropertyKey->pid;
  v37 = 0;
  v40 = 0;
  if( pid == 2 )
  {
    v19 = *(_QWORD *)&PropertyKey->fmtid.Data1 - DEVPKEY_NODE;
    if( *(_QWORD *)&PropertyKey->fmtid.Data1 == DEVPKEY_NODE )
      v19 = *(_QWORD *)PropertyKey->fmtid.Data4 + 0x5008C7D4C8250077i64;
    if( !v19 )
    {
      LODWORD(Create) = (unsigned int)BufferSize >> 1;
      *(_DWORD *)PropertyType = 18;
      ObjectDatabaseNodeName = DrvDbGetObjectDatabaseNodeName(
                                 (INT64 *)pDrvDbCtx,
                                 5i64,
                                 (INT64)DeviceId,
                                 PropertyBuffer,
                                 Create,
                                 PropertySize);
      RegValueMappedProperty = ObjectDatabaseNodeName;
      if( (int)(ObjectDatabaseNodeName + 0x80000000) < 0 || ObjectDatabaseNodeName == -1073741789 )
        *(_DWORD *)PropertySize *= 2;
      goto LABEL_18;
    }
    v20 = *(_QWORD *)&PropertyKey->fmtid.Data1 - DEVPKEY_DeviceId_DriverInfNames;
    if( *(_QWORD *)&PropertyKey->fmtid.Data1 == DEVPKEY_DeviceId_DriverInfNames )
      v20 = *(_QWORD *)PropertyKey->fmtid.Data4 + 0x4524B8338B5D1E6Ci64;
    if( !v20 )
      goto LABEL_6;
LABEL_62:
    v28 = 0;
    for( i = &off_140001728; ; i += 5 )
    {
      v30 = *i;
      if( *((_DWORD *)*i + 4) == pid )
      {
        v31 = *v30 - *(_QWORD *)&PropertyKey->fmtid.Data1;
        if( *v30 == *(_QWORD *)&PropertyKey->fmtid.Data1 )
          v31 = v30[1] - *(_QWORD *)PropertyKey->fmtid.Data4;
        if( !v31 )
          break;
      }
      if( ++v28 )
        return -1073741802;
    }
    v32 = 5i64 * v28;
    v33 = (const _DRVDB_PROPERTY_REG_VALUE_MAP *)&(&off_140001728)[5 * v28];
    if( v33 )
    {
      if( !ObjectBaseKey )
      {
        RegValueMappedProperty = DrvDbOpenDeviceIdRegKey(v10, (INT64)DeviceId, 1i64, 0, (INT64)&DriverInfMatches, 0i64);
        if( RegValueMappedProperty < 0 )
          goto LABEL_18;
        ObjectBaseKey = DriverInfMatches;
      }
      LODWORD(BaseKeyHandle) = BufferSize;
      RegValueMappedProperty = DrvDbGetRegValueMappedProperty(
                                 (VOID *)v32,
                                 ObjectBaseKey,
                                 v33,
                                 (UINT8 *)PropertyType,
                                 PropertyBuffer,
                                 BaseKeyHandle,
                                 PropertySize);
      goto LABEL_18;
    }
    return -1073741802;
  }
  if( pid != 3 )
    goto LABEL_62;
  pDrvDbCtx = (_DRVDB_CONTEXT *)0xBADB47CC74A2E194i64;
  v12 = *(_QWORD *)&PropertyKey->fmtid.Data1 - DEVPKEY_DeviceId_DriverInfMatches;
  if( *(_QWORD *)&PropertyKey->fmtid.Data1 == DEVPKEY_DeviceId_DriverInfMatches )
    v12 = *(_QWORD *)PropertyKey->fmtid.Data4 + 0x4524B8338B5D1E6Ci64;
  if( v12 )
    goto LABEL_62;
LABEL_6:
  if( *DeviceId != 64 || (v24 = wcschr(DeviceId + 1, 58)) == 0i64 || (v13 = v24 + 1) == 0i64 )
    v13 = DeviceId;
  if( v13 == DeviceId && !v10[5] )
  {
    v14 = (_UNICODE_STRING *)v10[2];
    if( v14 == (_UNICODE_STRING *)(v10 + 2) )
      goto LABEL_17;
    while( 1 )
    {
      v15 = DrvDbOpenObjectRegKey(
              pDrvDbCtxa,
              v14,
              DRVDB_BASE_KEY_TYPE_DEVICE_IDS,
              DeviceId,
              1,
              0,
              (VOID **)&DriverInfMatches,
              0i64);
      RegValueMappedProperty = v15;
      if( v15 >= 0 )
      {
        v40 = 1;
        RegValueMappedProperty = DrvDbGetDeviceIdDriverInfMatches(
                                   v16,
                                   DriverInfMatches,
                                   (UINT64)PropertyBuffer + v37,
                                   (UINT64 *)(((unsigned int)BufferSize - v37) >> 1),
                                   (UINT8)IncludeMatchData);
        ZwClose((_HANDLE)DriverInfMatches);
        DriverInfMatches = 0i64;
        if( RegValueMappedProperty >= 0 )
          goto LABEL_29;
        if( RegValueMappedProperty != -1073741275 )
        {
          if( RegValueMappedProperty != -1073741789 )
          {
LABEL_15:
            if( (int)(RegValueMappedProperty + 0x80000000) >= 0 && RegValueMappedProperty != -1073741789 )
              goto LABEL_18;
            if( v40 )
            {
              if( *(_DWORD *)PropertySize )
              {
                *(_DWORD *)PropertyType = 8210;
                v23 = *(_DWORD *)PropertySize + 2;
                *(_DWORD *)PropertySize = v23;
                if( PropertyBuffer && v23 <= (unsigned int)BufferSize )
                  *((_WORD *)PropertyBuffer + ((unsigned __int64)v23 >> 1) - 1) = 0;
                else
                  RegValueMappedProperty = -1073741789;
              }
              else
              {
                RegValueMappedProperty = -1073741275;
              }
            }
            else
            {
LABEL_17:
              RegValueMappedProperty = -1073741772;
            }
            goto LABEL_18;
          }
LABEL_29:
          v21 = 2 * *(_DWORD *)IncludeMatchData - 2;
          if( (unsigned int)(2 * *(_DWORD *)IncludeMatchData) <= 2 )
            v21 = 2 * *(_DWORD *)IncludeMatchData;
          if( PropertyBuffer )
          {
            v22 = v37;
            if( v21 + v37 < (unsigned int)BufferSize )
              v22 = v21 + v37;
            v37 = v22;
          }
          *(_DWORD *)PropertySize += v21;
          goto LABEL_14;
        }
      }
      else if( v15 != -1073741772 )
      {
        goto LABEL_15;
      }
      RegValueMappedProperty = 0;
LABEL_14:
      v14 = *(_UNICODE_STRING **)&v14->Length;
      if( v14 == (_UNICODE_STRING *)(pDrvDbCtxa + 4) )
        goto LABEL_15;
    }
  }
  v25 = 0i64;
  if( ObjectBaseKey != (VOID *)-1i64 )
    v25 = (WCHAR *)ObjectBaseKey;
  if( !v25 )
  {
    RegValueMappedProperty = DrvDbOpenDeviceIdRegKey(v10, (INT64)DeviceId, 1i64, 0, (INT64)&DriverInfMatches, 0i64);
    if( RegValueMappedProperty < 0 )
      goto LABEL_18;
    v25 = DriverInfMatches;
  }
  RegValueMappedProperty = DrvDbGetDeviceIdDriverInfMatches(
                             pDrvDbCtx,
                             v25,
                             (UINT64)PropertyBuffer,
                             (UINT64 *)((unsigned int)BufferSize >> 1),
                             (UINT8)IncludeMatchData);
  if( (int)(RegValueMappedProperty + 0x80000000) < 0 || RegValueMappedProperty == -1073741789 )
  {
    v26 = 2 * *(_DWORD *)IncludeMatchData;
    *(_DWORD *)PropertyType = 8210;
    *(_DWORD *)PropertySize = v26;
  }
LABEL_18:
  if( DriverInfMatches )
    ZwClose((_HANDLE)DriverInfMatches);
  return RegValueMappedProperty;
}

Referenced by:

DrvDbDispatchDeviceId