PnpCallDriverQueryServiceHelper

__int64 __fastcall PnpCallDriverQueryServiceHelper(
        PVOID *a1,
        _DWORD *a2,
        unsigned int a3,
        INT64 a4,
        WCHAR *DeviceInstanceId,
        VOID *BaseKeyHandle,
        char a7,
        __int64 a8,
        __int64 a9,
        _QUERY_CONTEXT *Context){
  char v10; 
  VOID *v11; 
  WCHAR *v12; 
  unsigned int v16; 
  UINT8 *v17; 
  NTSTATUS ObjectProperty; 
  NTSTATUS v19; 
  unsigned int v20; 
  unsigned int v22; 
  WCHAR *v23; 
  int v24; 
  __int64 v25; 
  unsigned int v26; 
  unsigned int v27; 
  UINT64 v28; 
  VOID **PoolWithTag; 
  NTSTATUS InstallerClassRegProp; 
  UINT64 *CmRegPropType; 
  UINT64 Flags; 
  UINT64 Flagsa; 
  UINT64 ValueType[2]; 
  UINT64 ValueLength; 

  v10 = a7;
  v11 = BaseKeyHandle;
  v12 = DeviceInstanceId;
  ValueType[0] = 0i64;
  LODWORD(ValueLength) = *a2;
  v16 = 0;
  v17 = (UINT8 *)*a1;
  if( a4 )
  {
    v16 = (a7 != 0) + 1;
    ObjectProperty = PnpGetObjectProperty(
                       *(&stru_140CF2E80 + 1214),
                       (INT64)DeviceInstanceId,
                       v16,
                       (INT64)BaseKeyHandle,
                       0i64,
                       a4,
                       (INT64)ValueType + 4,
                       (INT64)v17);
  }
  else if( a7 )
  {
    ObjectProperty = CmGetInstallerClassRegProp(
                       *(&stru_140CF2E80 + 607),
                       DeviceInstanceId,
                       BaseKeyHandle,
                       a3,
                       ValueType,
                       v17,
                       &ValueLength,
                       Flags);
  }
  else
  {
    LODWORD(Flags) = 0;
    ObjectProperty = CmGetDeviceRegProp(
                       *(&stru_140CF2E80 + 607),
                       DeviceInstanceId,
                       BaseKeyHandle,
                       a3,
                       ValueType,
                       v17,
                       &ValueLength,
                       Flags);
  }
  v19 = ObjectProperty;
  if( ObjectProperty == -1073741789 )
  {
    ExFreePoolWithTag(*a1, 0);
    v28 = (unsigned int)ValueLength;
    *a2 = ValueLength;
    PoolWithTag = ExAllocatePoolWithTag(1ui64, v28, 1852141648i64);
    *a1 = PoolWithTag;
    if( !PoolWithTag )
      return(unsigned int)-1073741670;
    if( a4 )
    {
      v19 = PnpGetObjectProperty(
              *(&stru_140CF2E80 + 1214),
              (INT64)v12,
              v16,
              (INT64)v11,
              0i64,
              a4,
              (INT64)ValueType + 4,
              (INT64)PoolWithTag);
    }
    else
    {
      if( v10 )
      {
        InstallerClassRegProp = CmGetInstallerClassRegProp(
                                  *(&stru_140CF2E80 + 607),
                                  v12,
                                  v11,
                                  a3,
                                  ValueType,
                                  (UINT8 *)PoolWithTag,
                                  &ValueLength,
                                  Flagsa);
      }
      else
      {
        LODWORD(Flagsa) = 0;
        InstallerClassRegProp = CmGetDeviceRegProp(
                                  *(&stru_140CF2E80 + 607),
                                  v12,
                                  v11,
                                  a3,
                                  ValueType,
                                  (UINT8 *)PoolWithTag,
                                  &ValueLength,
                                  Flagsa);
      }
      v19 = InstallerClassRegProp;
    }
  }
  if( v19 >= 0 )
  {
    if( a4 )
    {
      if( HIDWORD(ValueType[0]) == 8210 )
      {
        ValueType[0] = 0x201200000007i64;
LABEL_14:
        if( *a2 < 2u )
          return(unsigned int)-1073741823;
        v22 = ValueLength;
        if( (unsigned int)ValueLength < 2 )
        {
          return(unsigned int)-1073741823;
        }
        else
        {
          v23 = (WCHAR *)*a1;
          if( *(_WORD *)*a1 )
          {
            v24 = a8;
            while( 1 )
            {
              v25 = -1i64;
              do
                ++v25;
              while( v23[v25] );
              v26 = v25 + 1;
              if( RtlULongSub(v22, 2 * v26, &ValueLength) < 0 )
                break;
              LODWORD(CmRegPropType) = v24;
              v19 = PipCallDriverAddDeviceQueryRoutine(1ui64, v23, v27, Context, (UINT64)CmRegPropType);
              if( v19 >= 0 )
              {
                v22 = ValueLength;
                if( (unsigned int)ValueLength >= 2 )
                {
                  v23 += v26;
                  if( *v23 )
                    continue;
                }
              }
              return(unsigned int)v19;
            }
            return 0;
          }
        }
        return(unsigned int)v19;
      }
      if( HIDWORD(ValueType[0]) != 18 )
      {
        v20 = 0;
        LODWORD(ValueType[0]) = 0;
        goto LABEL_9;
      }
      ValueType[0] = 0x1200000001i64;
      v20 = 1;
    }
    else
    {
      v20 = ValueType[0];
    }
    if( v20 != 7 )
    {
LABEL_9:
      LODWORD(CmRegPropType) = a8;
      return(unsigned int)PipCallDriverAddDeviceQueryRoutine(
                             v20,
                             (WCHAR *)*a1,
                             (unsigned int)ValueLength,
                             Context,
                             (UINT64)CmRegPropType);
    }
    goto LABEL_14;
  }
  return(unsigned int)v19;
}

Referenced by:

PipCallDriverAddDevice