PnpHardwareConfigCreateBootDriverFlags

__int64 __fastcall PnpHardwareConfigCreateBootDriverFlags(_GUID *a1, __int64 a2){
  _HANDLE v2; 
  VOID **OutputBuffer; 
  int Status; 
  __int64 v6; 
  unsigned int v7; 
  int v8; 
  int v9; 
  UINT64 InitialState; 
  unsigned int v11; 
  _HANDLE Event[3]; 
  int v13; 
  unsigned int v14; 
  VOID *HardwareConfigKey; 
  int v16; 
  UINT64 NumberOfBytes; 
  VOID *Handle; 
  _IO_STATUS_BLOCK IoStatusBlock; 
  _OBJECT_ATTRIBUTES ObjectAttributes; 
  __int64 InputBuffer; 
  int v22; 

  NumberOfBytes = 0i64;
  v11 = 0;
  InputBuffer = 0i64;
  v2 = a2;
  v22 = 0;
  OutputBuffer = 0i64;
  v13 = 0;
  v16 = 0;
  *(_QWORD *)&Event[1] = 0i64;
  v14 = 0;
  Handle = 0i64;
  HardwareConfigKey = 0i64;
  IoStatusBlock = 0i64;
  memset(&ObjectAttributes, 0, sizeof(ObjectAttributes));
  if( !a2 )
    return(unsigned int)-1073741811;
  Status = PipHardwareConfigOpenKey((VOID **)a1);
  if( Status >= 0 )
  {
    Event[0] = 4;
    Status = RegRtlQueryValue(HardwareConfigKey, L"BootDriverFlags", &v13, &v16, (__int64)Event);
    if( Status == -1073741772 )
    {
      v22 = 0;
      ObjectAttributes.Length = 48;
      ObjectAttributes.RootDirectory = 0i64;
      ObjectAttributes.Attributes = 512;
      ObjectAttributes.ObjectName = 0i64;
      *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
      Status = ZwCreateEvent((UINT64)&Event[1], 0x1F0003ui64, (INT64)&ObjectAttributes, 0i64, 0);
      if( Status >= 0 )
      {
        Status = ZwDeviceIoControlFile(
                   v2,
                   Event[1],
                   0i64,
                   0i64,
                   &IoStatusBlock,
                   0x2D1400u,
                   &InputBuffer,
                   0xCu,
                   &NumberOfBytes,
                   8u);
        if( Status == 259 )
        {
          Status = ZwWaitForSingleObject(*(UINT64 *)&Event[1], 0, 0i64);
          if( Status < 0 )
            goto LABEL_4;
          Status = IoStatusBlock.Status;
        }
        if( Status >= 0 )
        {
          OutputBuffer = ExAllocatePoolWithTag(1ui64, HIDWORD(NumberOfBytes), 1852403792i64);
          if( !OutputBuffer )
          {
            Status = -1073741670;
            goto LABEL_4;
          }
          ZwResetEvent(*(VOID **)&Event[1], 0i64);
          Status = ZwDeviceIoControlFile(
                     v2,
                     Event[1],
                     0i64,
                     0i64,
                     &IoStatusBlock,
                     0x2D1400u,
                     &InputBuffer,
                     0xCu,
                     OutputBuffer,
                     HIDWORD(NumberOfBytes));
          if( Status == 259 )
          {
            Status = ZwWaitForSingleObject(*(UINT64 *)&Event[1], 0, 0i64);
            if( Status < 0 )
              goto LABEL_4;
            Status = IoStatusBlock.Status;
          }
          if( Status < 0 )
            goto LABEL_4;
          v6 = 0i64;
          if( *(&stru_140CF2E80 + 607) )
            v6 = *(_QWORD *)(*(&stru_140CF2E80 + 607) + 224i64);
          Status = SysCtxRegOpenKey(v6, (VOID *)0x80000002i64, L"System\\CurrentControlSet\\Control", 0, 1u, &Handle);
          if( Status < 0 )
            goto LABEL_4;
          Event[0] = 4;
          Status = RegRtlQueryValue(Handle, L"BootDriverFlags", &v13, &v14, (__int64)Event);
          if( Status < 0 )
            goto LABEL_4;
          v7 = v14 & 0xFFFFFFE3;
          v11 = v14 & 0xFFFFFFE3;
          v8 = *((_DWORD *)OutputBuffer + 7);
          if( v8 > 0 )
          {
            if( v8 <= 3 )
              goto LABEL_39;
            switch( v8 )
            {
              case 7:
                v9 = v7 | 0x14;
                goto LABEL_43;
              case 11:
LABEL_39:
                LODWORD(InitialState) = 4;
                Status = RegRtlSetValue(HardwareConfigKey, L"BootDriverFlags", 4u, &v11, InitialState);
                goto LABEL_4;
              case 12:
                v9 = v7 | 8;
                goto LABEL_43;
            }
            if( v8 > 14 )
            {
              if( v8 > 16 )
              {
                if( v8 == 17 || v8 == 19 )
                  goto LABEL_39;
                goto LABEL_38;
              }
              v9 = v14;
LABEL_43:
              v11 = v9;
              goto LABEL_39;
            }
          }
LABEL_38:
          v11 = v14;
          goto LABEL_39;
        }
      }
    }
  }
LABEL_4:
  if( Handle )
    ZwClose((_HANDLE)Handle);
  if( HardwareConfigKey )
    ZwClose((_HANDLE)HardwareConfigKey);
  if( OutputBuffer )
    ExFreePoolWithTag(OutputBuffer, 0);
  if( *(_QWORD *)&Event[1] )
    ZwClose(Event[1]);
  return(unsigned int)Status;
}

Referenced by:

IopMarkBootPartition