PiDevCfgClearDeviceMigrationNode

NTSTATUS __stdcall PiDevCfgClearDeviceMigrationNode(
        PI_DEVCFG_MIGRATION_CONTEXT *MigrationContext,
        WCHAR *DeviceInstanceId){
  VOID *v3; 
  __int64 v5; 
  NTSTATUS v6; 
  NTSTATUS v7; 
  int v8; 
  VOID *v9; 
  __int64 v10; 
  VOID *v11; 
  VOID *v12; 
  _OBJECT_TYPE *v13; 
  VOID *v14; 
  __int64 v15; 
  _OBJECT_TYPE *v16; 
  __int64 v17; 
  VOID *v18; 
  wchar_t *Buffer; 
  VOID **v20; 
  __int64 v21; 
  NTSTATUS v22; 
  __int64 v23; 
  _OBJECT_TYPE *v24; 
  __int64 v25; 
  VOID *v26; 
  __int64 v27; 
  int v29; 
  int v30; 
  int v31; 
  _UNICODE_STRING UnicodeString; 
  int v33; 
  _KEXCEPTION_FRAME *ExceptionFrame; 
  _UNICODE_STRING v35; 
  _UNICODE_STRING DestinationString; 
  VOID *KeyHandle; 
  VOID *Handle[29]; 

  v3 = (VOID *)*((_QWORD *)MigrationContext + 1);
  ExceptionFrame = 0i64;
  KeyHandle = 0i64;
  Handle[0] = 0i64;
  *(_QWORD *)&UnicodeString.Length = 0i64;
  UnicodeString.Buffer = 0i64;
  *(_QWORD *)&v35.Length = 0i64;
  v35.Buffer = 0i64;
  v33 = 0;
  if( *(&stru_140CF2E80 + 607) )
    v5 = *(_QWORD *)(*(&stru_140CF2E80 + 607) + 224i64);
  else
    v5 = 0i64;
  v6 = SysCtxRegOpenKey(v5, v3, DeviceInstanceId, 0, 0x20019u, (VOID **)&ExceptionFrame);
  v7 = v6;
  if( v6 == -1073741772 )
  {
LABEL_5:
    v7 = 0;
    goto LABEL_59;
  }
  if( v6 >= 0 )
  {
    memset(&Handle[1], 0i64, 0xE0u);
    Handle[3] = L"ClassGuid";
    LODWORD(Handle[5]) = 0x1000000;
    LODWORD(Handle[2]) = 288;
    Handle[4] = &UnicodeString;
    LODWORD(Handle[16]) = 288;
    Handle[10] = L"LocationPaths";
    LODWORD(Handle[12]) = 117440512;
    Handle[11] = &v35;
    Handle[17] = L"Persist";
    Handle[18] = &v33;
    LODWORD(Handle[9]) = 304;
    LODWORD(Handle[19]) = 0x4000000;
    LOBYTE(v8) = RtlpQueryRegistryValues((_KTRAP_FRAME *)0xC0000000i64, ExceptionFrame);
    v7 = v8;
    if( v8 >= 0 )
    {
      if( !UnicodeString.Length && UnicodeString.Buffer )
        RtlFreeAnsiString(&UnicodeString);
      if( v35.Buffer && !PnpValidateMultiSzData(v35.Buffer, v35.Length) )
        RtlFreeAnsiString(&v35);
      if( v33 )
        goto LABEL_5;
      ZwClose((_HANDLE)ExceptionFrame);
      v9 = (VOID *)*((_QWORD *)MigrationContext + 1);
      ExceptionFrame = 0i64;
      if( *(&stru_140CF2E80 + 607) && (v10 = *(_QWORD *)(*(&stru_140CF2E80 + 607) + 224i64)) != 0 )
        v11 = *(VOID **)(v10 + 8);
      else
        v11 = 0i64;
      RegRtlDeletePathInternal(v9, DeviceInstanceId, 1, v11, v29);
      v12 = (VOID *)*((_QWORD *)MigrationContext + 3);
      if( v12 )
      {
        DestinationString = 0i64;
        if( RtlInitUnicodeStringEx(&DestinationString, DeviceInstanceId) >= 0 )
          ZwDeleteValueKey(v12, &DestinationString, v13);
      }
      v14 = (VOID *)*((_QWORD *)MigrationContext + 2);
      if( v14 && UnicodeString.Buffer )
      {
        v15 = 0i64;
        if( *(&stru_140CF2E80 + 607) )
          v15 = *(_QWORD *)(*(&stru_140CF2E80 + 607) + 224i64);
        if( SysCtxRegOpenKey(v15, v14, UnicodeString.Buffer, 0, 0xF003Fu, &KeyHandle) >= 0 )
        {
          DestinationString = 0i64;
          if( RtlInitUnicodeStringEx(&DestinationString, DeviceInstanceId) >= 0 )
            ZwDeleteValueKey(KeyHandle, &DestinationString, v16);
          ZwClose((_HANDLE)KeyHandle);
        }
        if( *(&stru_140CF2E80 + 607) && (v17 = *(_QWORD *)(*(&stru_140CF2E80 + 607) + 224i64)) != 0 )
          v18 = *(VOID **)(v17 + 8);
        else
          v18 = 0i64;
        RegRtlDeletePathInternal(*((VOID **)MigrationContext + 2), UnicodeString.Buffer, 0, v18, v30);
      }
      Buffer = v35.Buffer;
      if( v35.Buffer )
      {
        v20 = (VOID **)(MigrationContext + 8);
        if( !*((_QWORD *)MigrationContext + 4) )
        {
          v21 = 0i64;
          if( *(&stru_140CF2E80 + 607) )
            v21 = *(_QWORD *)(*(&stru_140CF2E80 + 607) + 224i64);
          v22 = SysCtxRegOpenKey(
                  v21,
                  *(VOID **)MigrationContext,
                  L"Locations",
                  0,
                  0xF003Fu,
                  (VOID **)MigrationContext + 4);
          if( v22 == -1073741772 )
          {
            *v20 = 0i64;
          }
          else if( v22 < 0 )
          {
            v7 = v22;
            goto LABEL_59;
          }
          Buffer = v35.Buffer;
          if( !*v20 )
            goto LABEL_59;
        }
        while( *Buffer )
        {
          v23 = 0i64;
          if( *(&stru_140CF2E80 + 607) )
            v23 = *(_QWORD *)(*(&stru_140CF2E80 + 607) + 224i64);
          if( SysCtxRegOpenKey(v23, *v20, Buffer, 0, 0xF003Fu, Handle) >= 0 )
          {
            DestinationString = 0i64;
            if( RtlInitUnicodeStringEx(&DestinationString, DeviceInstanceId) >= 0 )
              ZwDeleteValueKey(Handle[0], &DestinationString, v24);
            ZwClose((_HANDLE)Handle[0]);
          }
          if( *(&stru_140CF2E80 + 607) && (v25 = *(_QWORD *)(*(&stru_140CF2E80 + 607) + 224i64)) != 0 )
            v26 = *(VOID **)(v25 + 8);
          else
            v26 = 0i64;
          RegRtlDeletePathInternal(*v20, Buffer, 0, v26, v31);
          v27 = -1i64;
          do
            ++v27;
          while( Buffer[v27] );
          Buffer += v27 + 1;
        }
      }
    }
  }
LABEL_59:
  RtlFreeAnsiString(&UnicodeString);
  RtlFreeAnsiString(&v35);
  if( ExceptionFrame )
    ZwClose((_HANDLE)ExceptionFrame);
  return v7;
}

Referenced by:

PiDevCfgFindDeviceMigrationNode
PiDevCfgMigrateDevice