VhdiInitializeBootDisk

NTSTATUS __stdcall VhdiInitializeBootDisk(
        _LOADER_PARAMETER_BLOCK *LoaderBlock,
        _BOOT_DISK_CONTEXT *BootDiskContext,
        _UNICODE_STRING *BootDeviceName){
  PARTITION_INFORMATION_EX *v3; 
  const VOID *v4; 
  _DRIVE_LAYOUT_INFORMATION_EX *v6; 
  char v7; 
  unsigned int v8; 
  int inited; 
  WCHAR *VolumeVhdFilePath; 
  ULONG OutputBufferLength; 
  VOID **OutputBuffer; 
  _PARTITION_STYLE PartitionStyle; 
  bool v14; 
  UINT64 ShareAccess; 
  UINT64 OpenOptions; 
  INT64 v17; 
  INT64 v18; 
  VOID *Handle; 
  UINT64 PartitionNumber; 
  INT64 v21; 
  _UNICODE_STRING DestinationString; 
  _IO_STATUS_BLOCK IoStatusBlock; 
  _OBJECT_ATTRIBUTES ObjectAttributes; 
  WCHAR pszDest[64]; 

  LODWORD(PartitionNumber) = 0;
  DestinationString = 0i64;
  IoStatusBlock = 0i64;
  memset(&ObjectAttributes, 0, sizeof(ObjectAttributes));
  if( !LoaderBlock )
    return -1073741811;
  if( !BootDiskContext )
    return -1073741811;
  if( !BootDeviceName )
    return -1073741811;
  v3 = *(PARTITION_INFORMATION_EX **)BootDiskContext;
  v4 = (const VOID *)*((_QWORD *)BootDiskContext + 1);
  if( !*(_QWORD *)BootDiskContext )
    return -1073741811;
  if( !v4 )
    return -1073741811;
  if( !*((_QWORD *)BootDiskContext + 2) )
    return -1073741811;
  v21 = *((_QWORD *)BootDiskContext + 3);
  if( !v21 )
    return -1073741811;
  if( !RtlCreateUnicodeStringFromAsciiz((INT64)BootDeviceName, (INT64)LoaderBlock->ArcBootDeviceName) )
    return -1073741823;
  v6 = 0i64;
  v7 = 0;
  v8 = 0;
  HIDWORD(PartitionNumber) = IoGetConfigurationInformation()->DiskCount;
  Handle = 0i64;
  if( !HIDWORD(PartitionNumber) )
    goto LABEL_39;
  while( 1 )
  {
    inited = RtlStringCbPrintfW(pszDest, 0x80ui64, (WCHAR *)L"\\Device\\Harddisk%d\\Partition0");
    if( inited < 0 )
      goto LABEL_35;
    inited = RtlInitUnicodeStringEx(&DestinationString, pszDest);
    if( inited < 0 )
      goto LABEL_35;
    ObjectAttributes.Length = 48;
    ObjectAttributes.RootDirectory = 0i64;
    ObjectAttributes.Attributes = 576;
    ObjectAttributes.ObjectName = &DestinationString;
    *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
    if( Handle )
    {
      ZwClose((_HANDLE)Handle);
      Handle = 0i64;
    }
    LODWORD(OpenOptions) = 32;
    LODWORD(ShareAccess) = 3;
    inited = ZwOpenFile(&Handle, 0xC0100000ui64, &ObjectAttributes, &IoStatusBlock, ShareAccess, OpenOptions);
    if( inited < 0 )
      goto LABEL_35;
    VolumeVhdFilePath = VhdiQueryVolumeVhdFilePath(Handle);
    if( !VolumeVhdFilePath )
      break;
    ExFreeHeapPool(VolumeVhdFilePath);
LABEL_35:
    if( ++v8 >= HIDWORD(PartitionNumber) )
      goto LABEL_38;
  }
  if( v6 )
    ExFreeHeapPool(v6);
  for( OutputBufferLength = 4096; ; OutputBufferLength *= 2 )
  {
    OutputBuffer = ExAllocatePoolWithTag(0x200ui64, OutputBufferLength, 1113876566i64);
    v6 = (_DRIVE_LAYOUT_INFORMATION_EX *)OutputBuffer;
    if( !OutputBuffer )
      break;
    inited = ZwDeviceIoControlFile(
               (_HANDLE)Handle,
               0,
               0i64,
               0i64,
               &IoStatusBlock,
               0x70050u,
               0i64,
               0,
               OutputBuffer,
               OutputBufferLength);
    if( inited != -1073741789 )
      goto LABEL_25;
    ExFreeHeapPool(v6);
  }
  inited = -1073741801;
LABEL_25:
  if( inited < 0 )
    goto LABEL_35;
  PartitionStyle = v3->PartitionStyle;
  if( v6->PartitionStyle == v3->PartitionStyle )
  {
    if( PartitionStyle )
    {
      if( PartitionStyle != PARTITION_STYLE_GPT )
        goto LABEL_34;
      v14 = RtlCompareMemory(&v6->Mbr, v4, 16) == (_SIZE_T *)16;
    }
    else
    {
      v14 = RtlCompareMemory(&v6->Mbr, v4, 4) == (_SIZE_T *)4;
    }
    if( v14 )
    {
      inited = VhdiGetPartitionNumber(v6, v3, &PartitionNumber);
      if( inited >= 0 )
        v7 = 1;
    }
  }
LABEL_34:
  if( !v7 )
    goto LABEL_35;
  inited = VhdiGetVolumeNumber(
             Handle,
             v8,
             (unsigned int)PartitionNumber,
             (UINT64 *)v21,
             ShareAccess,
             OpenOptions,
             v17,
             v18);
LABEL_38:
  if( !v7 )
LABEL_39:
    inited = -1073741810;
  if( v6 )
    ExFreeHeapPool(v6);
  if( Handle )
    ZwClose((_HANDLE)Handle);
  return inited;
}

Referenced by:

No references.