IoWMISuggestInstanceName

NTSTATUS __stdcall IoWMISuggestInstanceName(
        PDEVICE_OBJECT PhysicalDeviceObject,
        _UNICODE_STRING *SymbolicLinkName,
        BOOL CombineNames,
        _UNICODE_STRING *SuggestedInstanceName,
        UINT64 a5,
        INT64 a6,
        INT64 a7,
        UINT64 a8){
  int DeviceProperty; 
  NTSTATUS result; 
  unsigned __int16 v14; 
  VOID **PoolWithTag; 
  int v16; 
  NTSTATUS v17; 
  VOID **v18; 
  WCHAR *v19; 
  unsigned int v20; 
  VOID **v21; 
  VOID **v22; 
  UINT64 *ResultLength; 
  UINT64 *ResultLengtha; 
  UINT64 NumberOfBytes; 
  VOID *DeviceInterfaceKey; 
  _UNICODE_STRING ValueName; 

  DeviceInterfaceKey = 0i64;
  HIDWORD(NumberOfBytes) = 0;
  DeviceProperty = -1073741776;
  ValueName = 0i64;
  if( !*(&ExBootDevicesRemovedEvent + 391) )
    return -1073741823;
  v14 = 0;
  PoolWithTag = 0i64;
  LODWORD(NumberOfBytes) = 0;
  if( PhysicalDeviceObject )
  {
    result = IoGetDeviceProperty(PhysicalDeviceObject, 0, 0i64, 0i64, &NumberOfBytes);
    DeviceProperty = result;
    if( result == -1073741789 )
    {
      PoolWithTag = ExAllocatePoolWithTag(1ui64, (unsigned int)NumberOfBytes, 1885957463i64);
      if( !PoolWithTag )
        return -1073741670;
      DeviceProperty = IoGetDeviceProperty(
                         PhysicalDeviceObject,
                         0,
                         (unsigned int)NumberOfBytes,
                         PoolWithTag,
                         &NumberOfBytes);
      if( DeviceProperty < 0 )
        goto LABEL_35;
    }
    else if( result < 0 )
    {
      return result;
    }
    v14 = NumberOfBytes;
  }
  if( !SymbolicLinkName )
  {
    if( PoolWithTag )
    {
      SuggestedInstanceName->Buffer = (wchar_t *)PoolWithTag;
      SuggestedInstanceName->Length = v14 - 2;
      SuggestedInstanceName->MaximumLength = v14;
    }
    else
    {
      SuggestedInstanceName->Buffer = 0i64;
      *(_DWORD *)&SuggestedInstanceName->Length = 0;
    }
    return DeviceProperty;
  }
  IoOpenDeviceInterfaceRegistryKey(SymbolicLinkName, 0xF003Fui64, &DeviceInterfaceKey, SuggestedInstanceName);
  DeviceProperty = v16;
  if( v16 >= 0 )
  {
    LODWORD(ResultLength) = 0;
    v17 = ZwQueryValueKey(
            DeviceInterfaceKey,
            &ValueName,
            KeyValueFullInformation,
            0i64,
            (UINT64)ResultLength,
            (UINT64 *)((char *)&NumberOfBytes + 4));
    DeviceProperty = v17;
    if( v17 == -2147483643 || v17 == -1073741789 )
    {
      v18 = ExAllocatePoolWithTag(1ui64, HIDWORD(NumberOfBytes), 1885957463i64);
      if( v18 )
      {
        LODWORD(ResultLengtha) = HIDWORD(NumberOfBytes);
        DeviceProperty = ZwQueryValueKey(
                           DeviceInterfaceKey,
                           &ValueName,
                           KeyValueFullInformation,
                           v18,
                           (UINT64)ResultLengtha,
                           (UINT64 *)((char *)&NumberOfBytes + 4));
        if( DeviceProperty >= 0 )
        {
          v19 = (WCHAR *)((char *)v18 + *((unsigned int *)v18 + 2));
          if( CombineNames )
          {
            v20 = *((_DWORD *)v18 + 3) + NumberOfBytes + 2;
            v21 = ExAllocatePoolWithTag(1ui64, v20, 1885957463i64);
            if( v21 )
            {
              SuggestedInstanceName->Buffer = (wchar_t *)v21;
              SuggestedInstanceName->Length = 0;
              SuggestedInstanceName->MaximumLength = v20;
              if( PoolWithTag )
                RtlAppendUnicodeToString(SuggestedInstanceName, (WCHAR *)PoolWithTag);
              RtlAppendUnicodeToString(SuggestedInstanceName, (WCHAR *)&stru_1407CDE30.OutputLength);
              RtlAppendUnicodeToString(SuggestedInstanceName, v19);
            }
            else
            {
              DeviceProperty = -1073741670;
            }
            if( PoolWithTag )
            {
              ExFreePoolWithTag(PoolWithTag, 0);
              PoolWithTag = 0i64;
            }
          }
          else
          {
            if( PoolWithTag )
            {
              ExFreePoolWithTag(PoolWithTag, 0);
              PoolWithTag = 0i64;
            }
            v22 = ExAllocatePoolWithTag(1ui64, *((unsigned int *)v18 + 3), 1885957463i64);
            if( v22 )
            {
              SuggestedInstanceName->Buffer = (wchar_t *)v22;
              SuggestedInstanceName->Length = 0;
              SuggestedInstanceName->MaximumLength = *((_WORD *)v18 + 6);
              RtlAppendUnicodeToString(SuggestedInstanceName, v19);
            }
            else
            {
              DeviceProperty = -1073741670;
            }
          }
        }
        ExFreePoolWithTag(v18, 0);
      }
      else
      {
        DeviceProperty = -1073741670;
      }
    }
    ZwClose((_HANDLE)DeviceInterfaceKey);
  }
  if( !PoolWithTag || DeviceProperty >= 0 )
    return DeviceProperty;
LABEL_35:
  ExFreePoolWithTag(PoolWithTag, 0);
  return DeviceProperty;
}

Referenced by:

No references.