PiDevCfgMigrateDevice
NTSTATUS __stdcall PiDevCfgMigrateDevice(
_DEVICE_NODE *DeviceNode,
PI_DEVCFG_DEVICE_CONTEXT *DeviceContext,
_UNICODE_STRING *ClassGuidString,
_UNICODE_STRING *DriverInfName,
UINT64 *ConfigFlags,
UINT64 *ConfigStatus){
_DEVICE_NODE *v8;
int v9;
int inited;
VOID *v12;
__int64 v13;
NTSTATUS v14;
const WCHAR *v15;
__int64 v16;
NTSTATUS v17;
__int64 v18;
NTSTATUS DeviceMigrationNode;
_PI_DEVCFG_MIGRATION_NODE v20;
unsigned int *v21;
INT64 v22;
INT64 v23;
PI_DEVCFG_DEVICE_CONTEXT *v24;
_PI_DEVCFG_MIGRATION_NODE *v25;
VOID *v26;
_OBJECT_TYPE *v27;
_PI_DEVCFG_MIGRATION_NODE *v28;
VOID *v29;
VOID *v30;
WCHAR *v31;
WCHAR *v32;
_DEVPROPKEY *PropertyKey;
_PI_DEVCFG_MIGRATION_NODE *MigrationNode;
int v35;
_HANDLE Handle[3];
_KEY_VALUE_FULL_INFORMATION *Information[2];
_PI_DEVCFG_MIGRATION_CONTEXT MigrationContext[4];
VOID *MigrationNodesKeyHandle[2];
__int128 v40;
__int64 v41;
v41 = 0i64;
MigrationNode = 0i64;
Information[0] = 0i64;
v8 = DeviceNode;
memset(Handle, 0, sizeof(Handle));
v9 = 0;
v35 = 0;
*(_OWORD *)MigrationContext = 0i64;
*(_OWORD *)MigrationNodesKeyHandle = 0i64;
v40 = 0i64;
if( ConfigFlags )
*(_DWORD *)ConfigFlags = 0;
if( ConfigStatus )
*(_DWORD *)ConfigStatus = 0;
inited = PiDevCfgInitMigrationContext(ClassGuidString, DriverInfName, (VOID **)MigrationContext);
if( inited < 0 )
goto LABEL_8;
if( !*(_QWORD *)MigrationContext )
{
inited = 0;
goto LABEL_8;
}
if( PnpGetObjectProperty(
*(&stru_140CF2E80 + 1214),
*((_QWORD *)DeviceContext + 1),
1i64,
*((_QWORD *)DeviceContext + 2),
0i64,
(INT64)&DEVPKEY_Device_MigrationRank,
(INT64)Handle,
0i64) == -1073741789
&& Handle[0] == 9
&& v35 == 8 )
{
goto LABEL_50;
}
if( *(_QWORD *)&MigrationContext[2] )
{
inited = PiDevCfgQueryDeviceMigrationNode(MigrationContext, *((WCHAR **)DeviceContext + 1), &MigrationNode);
if( inited < 0 )
{
MigrationNode = 0i64;
if( inited == -1073741772 )
inited = 0;
}
else
{
*((_QWORD *)MigrationNode + 23) = 0i64;
}
}
if( MigrationNode )
{
LABEL_51:
v20 = MigrationNode[4];
if( (v20 & 1) != 0 )
{
inited = -1073740007;
}
else if( (v20 & 2) != 0 )
{
inited = -1073740719;
}
else
{
if( IopGetRegistryValue(*((PVOID *)MigrationNode + 5), (PWCHAR)L"ConfigFlags", 0i64, Information) >= 0 )
{
if( PnpValidateRegistryDword((__int64)Information[0]) )
v9 = *(unsigned int *)((char *)v21 + v21[2]);
ExFreePoolWithTag(v21, 0);
}
v22 = *((_QWORD *)DeviceContext + 2);
v23 = *((_QWORD *)DeviceContext + 1);
PropertyKey = (_DEVPROPKEY *)&v35;
v35 = 0;
if( PnpGetObjectProperty(
*(&stru_140CF2E80 + 1214),
v23,
1i64,
v22,
0i64,
(INT64)&DEVPKEY_Device_ClassGuid,
(INT64)Handle,
0i64) != -1073741789
|| Handle[0] != 13
|| v35 != 16 )
{
if( ClassGuidString )
{
PiDevCfgSetDeviceRegProp(v24, (_CM_REG_PROP)DeviceContext, 9ui64, (UINT8 *)1, (UINT64)ClassGuidString->Buffer);
}
else
{
LODWORD(PropertyKey) = 16;
LODWORD(v31) = 13;
PiDevCfgSetObjectProperty(
*(&stru_140CF2E80 + 607),
DeviceContext,
*((_QWORD *)DeviceContext + 1),
(WCHAR *)1,
*((WCHAR **)DeviceContext + 2),
v29,
(UINT64)&DEVPKEY_Device_ClassGuid,
v31,
(UINT64)(MigrationNode + 20),
PropertyKey);
}
}
HIDWORD(v32) = HIDWORD(ConfigStatus);
inited = PiDevCfgConfigureDeviceDriverConfiguration(
v8,
DeviceContext,
*((VOID **)MigrationNode + 5),
0xFFFFFFFFui64,
0i64,
0i64);
if( inited >= 0 )
{
if( ConfigFlags )
*(_DWORD *)ConfigFlags |= v9;
v25 = MigrationNode;
if( *((_QWORD *)MigrationNode + 23) )
{
v26 = (VOID *)*((_QWORD *)DeviceContext + 2);
*(_OWORD *)Information = 0i64;
if( RtlInitUnicodeStringEx((_UNICODE_STRING *)Information, (WCHAR *)L"ParentIdPrefix") >= 0 )
{
ZwDeleteValueKey(v26, (_UNICODE_STRING *)Information, v27);
v25 = MigrationNode;
}
}
LODWORD(PropertyKey) = 8;
LODWORD(v32) = 9;
PiDevCfgSetObjectProperty(
*(&stru_140CF2E80 + 607),
DeviceContext,
*((_QWORD *)DeviceContext + 1),
(WCHAR *)1,
*((WCHAR **)DeviceContext + 2),
v30,
(UINT64)&DEVPKEY_Device_MigrationRank,
v32,
(UINT64)(v25 + 46),
PropertyKey);
}
}
PiDevCfgLogDeviceMigrated(DeviceContext, MigrationNode, (unsigned int)inited);
v28 = MigrationNode;
if( (MigrationNode[4] & 1) == 0 )
{
PiDevCfgClearDeviceMigrationNode(MigrationContext, *((WCHAR **)MigrationNode + 4));
v28 = MigrationNode;
}
if( !v28 || wcsicmp(*((const wchar_t **)DeviceContext + 1), *((const wchar_t **)v28 + 4)) )
goto LABEL_76;
goto LABEL_8;
}
if( CmIsRootEnumeratedDevice(*((WCHAR **)DeviceContext + 1)) )
goto LABEL_50;
if( !*((_QWORD *)DeviceContext + 8) )
goto LABEL_45;
v12 = (VOID *)v40;
if( !(_QWORD)v40 )
{
v13 = 0i64;
if( *(&stru_140CF2E80 + 607) )
v13 = *(_QWORD *)(*(&stru_140CF2E80 + 607) + 224i64);
v14 = SysCtxRegOpenKey(v13, *(VOID **)MigrationContext, L"Locations", 0, 0x20019u, (VOID **)&v40);
if( v14 == -1073741772 )
{
*(_QWORD *)&v40 = 0i64;
goto LABEL_45;
}
if( v14 < 0 )
{
inited = v14;
goto LABEL_8;
}
v12 = (VOID *)v40;
if( !(_QWORD)v40 )
goto LABEL_45;
}
v15 = (const WCHAR *)*((_QWORD *)DeviceContext + 8);
if( !*v15 )
goto LABEL_43;
while( 1 )
{
v16 = 0i64;
if( *(&stru_140CF2E80 + 607) )
v16 = *(_QWORD *)(*(&stru_140CF2E80 + 607) + 224i64);
v17 = SysCtxRegOpenKey(v16, v12, v15, 0, 0x20019u, (VOID **)&Handle[1]);
if( v17 == -1073741772 )
goto LABEL_38;
if( v17 < 0 )
break;
inited = PiDevCfgFindDeviceMigrationNode(
MigrationContext,
DeviceContext,
*(VOID **)&Handle[1],
0x11201ui64,
&MigrationNode);
ZwClose(Handle[1]);
if( inited >= 0 )
goto LABEL_44;
MigrationNode = 0i64;
if( inited == -1073741275 )
inited = 0;
LABEL_38:
v18 = -1i64;
do
++v18;
while( v15[v18] );
v15 += v18 + 1;
if( !*v15 )
goto LABEL_43;
v12 = (VOID *)v40;
}
inited = v17;
LABEL_43:
if( inited >= 0 )
{
LABEL_44:
v8 = DeviceNode;
LABEL_45:
if( MigrationNode )
goto LABEL_51;
if( MigrationNodesKeyHandle[1] )
{
DeviceMigrationNode = PiDevCfgFindDeviceMigrationNode(
MigrationContext,
DeviceContext,
MigrationNodesKeyHandle[1],
0x11021ui64,
&MigrationNode);
inited = DeviceMigrationNode;
if( DeviceMigrationNode < 0 )
{
MigrationNode = 0i64;
if( DeviceMigrationNode == -1073741275 )
inited = 0;
}
LABEL_50:
if( MigrationNode )
goto LABEL_51;
}
LABEL_76:
PiDevCfgClearDeviceMigrationNode(MigrationContext, *((WCHAR **)DeviceContext + 1));
}
LABEL_8:
if( MigrationNode )
PiDevCfgFreeDeviceMigrationNode(MigrationNode);
PiDevCfgFreeMigrationContext(MigrationContext);
return inited;
}Referenced by:
PiDevCfgConfigureDevice
PiDevCfgMigrateRootDevice
PpDevCfgProcessDeviceReset