PiDevCfgInitMigrationContext

NTSTATUS __stdcall PiDevCfgInitMigrationContext(VOID *ClassGuidString, VOID *DriverInfName, VOID **MigrationContext){
  int CachedContextBaseKey; 
  INT64 v6; 
  NTSTATUS v7; 
  INT64 v8; 
  NTSTATUS v10; 
  INT64 v11; 
  VOID **v12; 
  NTSTATUS v13; 
  INT64 v14; 
  INT64 v15; 
  __int128 v16; 
  _OBJECT_ATTRIBUTES ObjectAttributes; 
  INT64 v18; 

  *(_OWORD *)MigrationContext = 0i64;
  *((_OWORD *)MigrationContext + 1) = 0i64;
  v18 = 0i64;
  *((_OWORD *)MigrationContext + 2) = 0i64;
  MigrationContext[6] = DriverInfName;
  MigrationContext[5] = ClassGuidString;
  v16 = 0i64;
  CachedContextBaseKey = PnpCtxGetCachedContextBaseKey(
                           *(&stru_140CF2E80 + 607),
                           PNPCTX_BASE_KEY_TYPE_CONTROLSET,
                           (VOID **)&v18);
  if( CachedContextBaseKey < 0 )
    goto LABEL_17;
  LODWORD(v16) = 3145774;
  *((_QWORD *)&v16 + 1) = L"Control\\DeviceMigration";
  ObjectAttributes.RootDirectory = (void *)v18;
  *(_QWORD *)&ObjectAttributes.Length = 48i64;
  ObjectAttributes.ObjectName = (_UNICODE_STRING *)&v16;
  *(_QWORD *)&ObjectAttributes.Attributes = 576i64;
  *MigrationContext = 0i64;
  *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
  v7 = ZwOpenKey(
         MigrationContext,
         0x20019ui64,
         &ObjectAttributes,
         v6,
         v16,
         *((INT64 *)&v16 + 1),
         *(INT64 *)&ObjectAttributes.Length,
         (INT64)ObjectAttributes.RootDirectory);
  CachedContextBaseKey = v7;
  if( v7 == -1073741772 )
    return 0;
  if( v7 < 0 )
    goto LABEL_17;
  LODWORD(v16) = 1048590;
  *((_QWORD *)&v16 + 1) = L"Devices";
  ObjectAttributes.RootDirectory = *MigrationContext;
  *(_QWORD *)&ObjectAttributes.Length = 48i64;
  ObjectAttributes.ObjectName = (_UNICODE_STRING *)&v16;
  *(_QWORD *)&ObjectAttributes.Attributes = 576i64;
  MigrationContext[1] = 0i64;
  *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
  v10 = ZwOpenKey(
          MigrationContext + 1,
          0x20019ui64,
          &ObjectAttributes,
          v8,
          v16,
          *((INT64 *)&v16 + 1),
          *(INT64 *)&ObjectAttributes.Length,
          (INT64)ObjectAttributes.RootDirectory);
  CachedContextBaseKey = v10;
  if( v10 == -1073741772 )
  {
    MigrationContext[1] = 0i64;
  }
  else if( v10 < 0 )
  {
    goto LABEL_17;
  }
  LODWORD(v16) = 1048590;
  *((_QWORD *)&v16 + 1) = L"Classes";
  v12 = MigrationContext + 2;
  ObjectAttributes.RootDirectory = *MigrationContext;
  *(_QWORD *)&ObjectAttributes.Length = 48i64;
  ObjectAttributes.ObjectName = (_UNICODE_STRING *)&v16;
  *(_QWORD *)&ObjectAttributes.Attributes = 576i64;
  MigrationContext[2] = 0i64;
  *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
  v13 = ZwOpenKey(
          MigrationContext + 2,
          0x20019ui64,
          &ObjectAttributes,
          v11,
          v16,
          *((INT64 *)&v16 + 1),
          *(INT64 *)&ObjectAttributes.Length,
          (INT64)ObjectAttributes.RootDirectory);
  CachedContextBaseKey = v13;
  if( v13 != -1073741772 )
  {
    if( v13 >= 0 )
      goto LABEL_12;
LABEL_17:
    PiDevCfgFreeMigrationContext((_PI_DEVCFG_MIGRATION_CONTEXT *)MigrationContext);
    return CachedContextBaseKey;
  }
  CachedContextBaseKey = 0;
  *v12 = 0i64;
LABEL_12:
  v15 = (INT64)*v12;
  if( *v12 )
  {
    if( ClassGuidString )
    {
      *(_QWORD *)&ObjectAttributes.Length = 48i64;
      *(_QWORD *)&ObjectAttributes.Attributes = 576i64;
      MigrationContext[3] = 0i64;
      ObjectAttributes.ObjectName = (_UNICODE_STRING *)ClassGuidString;
      *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
      CachedContextBaseKey = ZwOpenKey(
                               MigrationContext + 3,
                               0x20019ui64,
                               &ObjectAttributes,
                               v14,
                               v16,
                               *((INT64 *)&v16 + 1),
                               *(INT64 *)&ObjectAttributes.Length,
                               v15);
      if( CachedContextBaseKey == -1073741772 )
      {
        CachedContextBaseKey = 0;
        MigrationContext[3] = 0i64;
      }
    }
  }
  if( CachedContextBaseKey < 0 )
    goto LABEL_17;
  return CachedContextBaseKey;
}

Referenced by:

PiDevCfgMigrateDevice