IoVolumeDeviceNameToGuidPath

NTSTATUS __stdcall IoVolumeDeviceNameToGuidPath(UNICODE_STRING *VolumeDeviceName, UNICODE_STRING *GuidPath){
  int *v3; 
  int Length; 
  char v5; 
  ULONG v7; 
  VOID *PoolWithTag; 
  void *v9; 
  WCHAR v10; 
  int DeviceObjectPointer; 
  _DEVICE_OBJECT *v12; 
  IRP *v13; 
  ULONG OutputBufferLength; 
  IRP *v15; 
  __int64 v16; 
  wchar_t *v17; 
  unsigned __int16 v18; 
  __int64 v19; 
  wchar_t *v20; 
  char v22; 
  PDEVICE_OBJECT DeviceObject; 
  PFILE_OBJECT FileObject; 
  struct _KEVENT Event; 
  struct _IO_STATUS_BLOCK IoStatusBlock; 
  struct _UNICODE_STRING DestinationString; 
  int OutputBuffer[8]; 
  v22 = 0;
  v3 = 0i64;
  FileObject = 0i64;
  Length = VolumeDeviceName->Length;
  v5 = 0;
  DeviceObject = 0i64;
  memset(&Event, 0, sizeof(Event));
  IoStatusBlock = 0i64;
  DestinationString = 0i64;
  if( (unsigned __int16)Length > 0xF000u )
    return -1073741811;
  v7 = Length + 26;
  PoolWithTag = ExAllocatePoolWithTag(PagedPool, (unsigned int)(Length + 26), 0x20473244ui64);
  v9 = PoolWithTag;
  if( !PoolWithTag )
    return -1073741670;
  memset((INT64)PoolWithTag, 0i64);
  *((_DWORD *)v9 + 4) = 24;
  *(_DWORD *)v9 = 0;
  *((_WORD *)v9 + 2) = 0;
  *((_DWORD *)v9 + 2) = 0;
  *((_WORD *)v9 + 6) = 0;
  *((_WORD *)v9 + 10) = VolumeDeviceName->Length;
  memmove((UINT8 *)v9 + 24, (UINT8 *)VolumeDeviceName->Buffer, VolumeDeviceName->Length);
  RtlInitUnicodeString(&DestinationString, L"\\Device\\MountPointManager", v10);
  DeviceObjectPointer = IoGetDeviceObjectPointer(&DestinationString, 0x80ui64, &FileObject, &DeviceObject);
  if( DeviceObjectPointer >= 0 )
  {
    v5 = 1;
    v3 = OutputBuffer;
    KeInitializeEvent(&Event, NotificationEvent, 0);
    v12 = DeviceObject;
    v13 = IoBuildDeviceIoControlRequest(0x6D0008u, DeviceObject, v9, v7, OutputBuffer, 0x20u, 0, &Event, &IoStatusBlock);
    if( v13 )
    {
      DeviceObjectPointer = IofCallDriver(v12, v13);
      if( DeviceObjectPointer == 259 )
      {
        KeWaitForSingleObject(&Event, Executive, 0, 0, 0i64);
        DeviceObjectPointer = IoStatusBlock.Status;
      }
      if( (int)(DeviceObjectPointer + 0x80000000) >= 0 && DeviceObjectPointer != -2147483643 )
        goto LABEL_19;
      OutputBufferLength = OutputBuffer[0] + 32;
      if( (unsigned int)(OutputBuffer[0] + 32) > 0xFFFF )
      {
        DeviceObjectPointer = -1073741306;
        goto LABEL_19;
      }
      v3 = (int *)ExAllocatePoolWithTag(PagedPool, OutputBufferLength, 0x20473244ui64);
      if( v3 )
      {
        v22 = 1;
        KeInitializeEvent(&Event, NotificationEvent, 0);
        v15 = IoBuildDeviceIoControlRequest(0x6D0008u, v12, v9, v7, v3, OutputBufferLength, 0, &Event, &IoStatusBlock);
        v16 = 0i64;
        if( v15 )
        {
          DeviceObjectPointer = IofCallDriver(v12, v15);
          if( DeviceObjectPointer == 259 )
          {
            KeWaitForSingleObject(&Event, Executive, 0, 0, 0i64);
            DeviceObjectPointer = IoStatusBlock.Status;
          }
          if( DeviceObjectPointer >= 0 )
          {
            DeviceObjectPointer = -1073741275;
            if( v3[1] )
            {
              while( 1 )
              {
                v17 = (wchar_t *)((char *)v3 + (unsigned int)v3[6 * v16 + 2]);
                if( !wcsnicmp(L"\\??\\Volume", v17, 0xAui64) )
                  break;
                v16 = (unsigned int)(v16 + 1);
                if( (unsigned int)v16 >= v3[1] )
                  goto LABEL_18;
              }
              v18 = v3[6 * v16 + 3];
              GuidPath->Length = v18;
              v19 = (unsigned __int16)(v18 + 2);
              GuidPath->MaximumLength = v19;
              v20 = (wchar_t *)ExAllocatePoolWithTag(PagedPool, (unsigned __int16)v19, 0x20473244ui64);
              DeviceObjectPointer = 0;
              GuidPath->Buffer = v20;
              if( v20 )
              {
                memmove((UINT8 *)v20, (UINT8 *)v17, GuidPath->Length);
                GuidPath->Buffer[(unsigned __int64)GuidPath->Length >> 1] = 0;
              }
              else
              {
                *(_DWORD *)&GuidPath->Length = 0;
                DeviceObjectPointer = -1073741670;
              }
LABEL_18:
              v5 = 1;
            }
          }
          goto LABEL_19;
        }
      }
    }
    DeviceObjectPointer = -1073741670;
  }
LABEL_19:
  ExFreePoolWithTag(v9, 0);
  if( v22 )
    ExFreePoolWithTag(v3, 0);
  if( v5 )
    HalPutDmaAdapter((PADAPTER_OBJECT)FileObject);
  return DeviceObjectPointer;
}

Referenced by:

IoVolumeDeviceNameToGuid
IoVolumeDeviceToGuidPath