SiFindSystemPartition

NTSTATUS __stdcall SiFindSystemPartition(INT64 a1){
  __int64 v1; 
  NTSTATUS DriveLayoutInformation; 
  _DRIVE_LAYOUT_INFORMATION_EX *v4; 
  NTSTATUS v5; 
  ULONG PartitionCount; 
  __int64 v7; 
  __int64 v8; 
  ULONG v10; 
  unsigned __int8 *p_BootIndicator; 
  _DRIVE_LAYOUT_INFORMATION_EX *DriveLayout; 
  WCHAR Dst[32]; 

  v1 = *(unsigned int *)(a1 + 4);
  DriveLayout = 0i64;
  swprintf_s(Dst, 0x20ui64, (WCHAR *)L"\\??\\PhysicalDrive%d", v1);
  DriveLayoutInformation = SiGetDriveLayoutInformation(Dst, &DriveLayout);
  v4 = DriveLayout;
  v5 = DriveLayoutInformation;
  if( DriveLayoutInformation >= 0 )
  {
    if( DriveLayout->PartitionStyle )
    {
      if( DriveLayout->PartitionStyle == 1 )
      {
        PartitionCount = DriveLayout->PartitionCount;
        v7 = 0i64;
        if( PartitionCount )
        {
          while( 1 )
          {
            v8 = *((_QWORD *)&DriveLayout->PartitionEntry[0].Gpt.PartitionType + 18 * v7)
               - *(_QWORD *)&PARTITION_SYSTEM_GUID.Data1;
            if( !v8 )
              v8 = *(_QWORD *)&DriveLayout->PartitionEntry[0].Gpt.PartitionId[9 * v7].Data1
                 - *(_QWORD *)PARTITION_SYSTEM_GUID.Data4;
            if( !v8 )
              break;
            v7 = (unsigned int)(v7 + 1);
            if( (unsigned int)v7 >= PartitionCount )
              goto LABEL_9;
          }
LABEL_18:
          *(_DWORD *)(a1 + 8) = *(&DriveLayout->PartitionEntry[0].PartitionNumber + 36 * v7);
          goto LABEL_10;
        }
      }
    }
    else
    {
      v10 = DriveLayout->PartitionCount;
      v7 = 0i64;
      if( v10 )
      {
        p_BootIndicator = &DriveLayout->PartitionEntry[0].Gpt.BootIndicator;
        while( !*p_BootIndicator )
        {
          v7 = (unsigned int)(v7 + 1);
          p_BootIndicator += 144;
          if( (unsigned int)v7 >= v10 )
            goto LABEL_9;
        }
        goto LABEL_18;
      }
    }
LABEL_9:
    v5 = -1073741275;
  }
LABEL_10:
  if( v4 )
    ExFreePoolWithTag(v4, 0);
  return v5;
}

Referenced by:

SyspartGetPhysicalPartitions