ExpGetPartitionTableInfo

NTSTATUS __stdcall ExpGetPartitionTableInfo(PWCHAR pDeviceName, _DRIVE_LAYOUT_INFORMATION_EX **ppDriveLayout){
  NTSTATUS result; 
  UINT64 OutputBufferLength; 
  UINT64 i; 
  int v6; 
  _DRIVE_LAYOUT_INFORMATION_EX *OutputBuffer; 
  UINT64 ShareAccess; 
  UINT64 OpenOptions; 
  _UNICODE_STRING DestinationString; 
  _IO_STATUS_BLOCK IoStatusBlock; 
  _OBJECT_ATTRIBUTES ObjectAttributes; 
  VOID *FileHandle; 

  *(&ObjectAttributes.Length + 1) = 0;
  *(&ObjectAttributes.Attributes + 1) = 0;
  FileHandle = 0i64;
  DestinationString = 0i64;
  IoStatusBlock = 0i64;
  RtlInitUnicodeString(&DestinationString, pDeviceName);
  ObjectAttributes.RootDirectory = 0i64;
  LODWORD(OpenOptions) = 96;
  ObjectAttributes.ObjectName = &DestinationString;
  ObjectAttributes.Length = 48;
  ObjectAttributes.Attributes = 576;
  LODWORD(ShareAccess) = 3;
  *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
  result = ZwOpenFile(&FileHandle, 0x100080ui64, &ObjectAttributes, &IoStatusBlock, ShareAccess, OpenOptions);
  if( result >= 0 )
  {
    LODWORD(OutputBufferLength) = 2352;
    for( i = 2352i64; ; i = OutputBufferLength )
    {
      OutputBuffer = (_DRIVE_LAYOUT_INFORMATION_EX *)ExAllocatePoolWithTag(0x200ui64, i, 1920364101i64);
      if( !OutputBuffer )
      {
        ZwClose((_HANDLE)FileHandle);
        return -1073741670;
      }
      v6 = ZwDeviceIoControlFile(
             (_HANDLE)FileHandle,
             0,
             0i64,
             0i64,
             &IoStatusBlock,
             0x70050u,
             0i64,
             0,
             OutputBuffer,
             OutputBufferLength);
      if( v6 >= 0 )
        break;
      ExFreePoolWithTag(OutputBuffer, 0);
      if( v6 != -1073741789 )
        goto LABEL_10;
      OutputBufferLength = (unsigned int)(2 * OutputBufferLength);
    }
    *ppDriveLayout = OutputBuffer;
LABEL_10:
    ZwClose((_HANDLE)FileHandle);
    return v6;
  }
  return result;
}

Referenced by:

ExpFindDiskSignature