PiDevCfgProcessDevice
NTSTATUS __stdcall PiDevCfgProcessDevice(_DEVICE_NODE *DeviceNode, VOID *DeviceInstanceKeyHandle, UINT64 Flags){
_UNICODE_STRING *p_InstancePath;
int v6;
bool v7;
NTSTATUS v8;
int inited;
char v10;
NTSTATUS v11;
bool v12;
int v13;
unsigned int StateFlags;
unsigned int v15;
wchar_t *v16;
__int64 v17;
unsigned int v18;
unsigned int v19;
wchar_t *v20;
wchar_t *v21;
wchar_t *Buffer;
wchar_t *v24;
char v25;
NTSTATUS v26;
char v27;
unsigned __int64 v28;
__int64 v29;
__int64 v30;
__int64 v31;
UINT64 Problem;
UINT64 *ConfigStatus;
UINT8 *PropertyBuffer;
UINT8 *PropertyBuffera;
UINT8 *PropertyBufferb;
WCHAR *Flagsa;
WCHAR *Flagsb;
WCHAR *Flagsc;
_DEVPROPKEY *PropertyKey;
_DEVPROPKEY *PropertyKeya;
UINT64 PropertySize;
UINT64 CmRegPropType;
UINT64 v44;
_PI_DEVCFG_DRIVER_NODE *DriverNodeResult;
INT64 v46;
_UNICODE_STRING UnicodeString;
UINT64 v48;
_UNICODE_STRING DestinationString;
_PI_DEVCFG_DEVICE_CONTEXT DeviceContext[20];
UINT64 PropertyCount[16];
char v52;
char v53;
UINT64 ConfigFlags;
v53 = Flags;
p_InstancePath = 0i64;
memset(DeviceContext, 0i64, 0x48u);
*(_QWORD *)&UnicodeString.Length = 0i64;
v6 = 0;
LODWORD(CmRegPropType) = 1;
v7 = 0;
UnicodeString.Buffer = 0i64;
v8 = 0;
*(_QWORD *)&DestinationString.Length = 0i64;
DestinationString.Buffer = 0i64;
DriverNodeResult = 0i64;
LODWORD(ConfigFlags) = 0;
LODWORD(v44) = 0;
v52 = 0;
v46 = 0i64;
PropertySize = 0i64;
v48 = 0i64;
BYTE4(CmRegPropType) = 0;
if( !DeviceNode->InstancePath.Buffer )
{
inited = -1073741808;
goto LABEL_51;
}
p_InstancePath = &DeviceNode->InstancePath;
PnpDiagnosticTraceObject(&KMPnPEvt_DeviceConfig_Start, &DeviceNode->InstancePath.Length);
inited = PiDevCfgInitDeviceContext(DeviceNode->InstancePath.Buffer, DeviceInstanceKeyHandle, DeviceContext);
if( inited >= 0 )
{
v10 = DeviceContext[0];
if( (v53 & 1) != 0 )
{
v10 = LOBYTE(DeviceContext[0]) | 1;
DeviceContext[0] |= 1u;
}
if( !DeviceInstanceKeyHandle )
DeviceInstanceKeyHandle = *(VOID **)&DeviceContext[4];
if( (v10 & 1) != 0 || PnpBootMode )
goto LABEL_8;
memset(PropertyCount, 0i64, 0x50u);
LODWORD(PropertyBuffer) = 2;
LODWORD(PropertyCount[1]) = 8210;
LODWORD(PropertyCount[6]) = 8210;
Buffer = DeviceNode->InstancePath.Buffer;
PropertyCount[0] = (UINT64)&DEVPKEY_Device_PendingConfigurationIds;
HIDWORD(PropertyCount[3]) = 6;
PropertyCount[2] = (UINT64)&UnicodeString;
PropertyCount[5] = (UINT64)&DEVPKEY_Device_RequestConfigurationIds;
PropertyCount[7] = (UINT64)&DestinationString;
HIDWORD(PropertyCount[8]) = 6;
inited = PiDevCfgQueryObjectProperties(
(WCHAR *)6,
(PNP_OBJECT_TYPE)Buffer,
(VOID *)1,
(PI_DEVCFG_QUERY_PROPERTY_PARAM *)DeviceInstanceKeyHandle,
(UINT64)PropertyCount,
(UINT64)PropertyBuffer);
if( inited >= 0 )
{
if( SLODWORD(PropertyCount[4]) < 0 )
RtlInitUnicodeString(&UnicodeString, 0i64);
if( SLODWORD(PropertyCount[9]) < 0 )
RtlInitUnicodeString(&DestinationString, 0i64);
if( UnicodeString.Buffer && !*UnicodeString.Buffer )
{
v8 = -1073740656;
v7 = 1;
goto LABEL_15;
}
LABEL_8:
inited = PiDevCfgFindDeviceDriver(DeviceContext, UnicodeString.Buffer, &DriverNodeResult);
if( inited >= 0 )
{
if( DestinationString.Buffer )
{
inited = PiDevCfgRequestDriverConfigurations((POOL_TYPE)DeviceContext, DriverNodeResult);
}
else
{
v11 = PiDevCfgConfigureDevice(DeviceNode, DeviceContext, DriverNodeResult, &ConfigFlags, &v44);
inited = v11;
if( v11 >= 0 )
{
v6 = ConfigFlags;
v52 = 1;
}
v12 = ((v11 + 1073740653) & 0xFFFFFFFD) == 0;
v13 = BYTE4(CmRegPropType);
if( !v12 )
v13 = 1;
HIDWORD(CmRegPropType) = v13;
}
}
LABEL_15:
if( UnicodeString.Buffer && (DriverNodeResult || v7) )
{
LODWORD(PropertyKey) = 0;
LODWORD(Flagsa) = 0;
PiDevCfgSetObjectProperty(
*(&stru_140CF2E80 + 607),
DeviceContext,
(const PNP_OBJECT_TYPE)DeviceNode->InstancePath.Buffer,
(WCHAR *)1,
(WCHAR *)DeviceInstanceKeyHandle,
PropertyBuffer,
(UINT64)&DEVPKEY_Device_PendingConfigurationIds,
Flagsa,
0i64,
PropertyKey);
}
if( DestinationString.Buffer )
goto LABEL_45;
if( !UnicodeString.Buffer )
{
if( v7 )
goto LABEL_91;
if( DriverNodeResult )
{
if( DriverNodeResult[103] >= 0 )
{
LABEL_21:
if( v52 )
{
if( PnpBootMode || (v53 & 2) != 0 )
v6 |= 0x40000u;
StateFlags = DeviceNode->StateFlags;
if( (v6 & 0x40) != 0 )
v15 = StateFlags & 0xFFFFFFFE;
else
v15 = StateFlags | 1;
DeviceNode->StateFlags = v15;
}
v16 = DeviceNode->InstancePath.Buffer;
LODWORD(Flagsa) = 0;
LODWORD(PropertySize) = 4;
if( CmGetDeviceRegProp(
*(&stru_140CF2E80 + 607),
v16,
DeviceInstanceKeyHandle,
11i64,
&CmRegPropType,
(UINT8 *)&ConfigFlags,
&PropertySize,
(UINT64)Flagsa) < 0
|| (_DWORD)CmRegPropType != 4
|| (_DWORD)PropertySize != 4 )
{
LODWORD(ConfigFlags) = 0;
}
v18 = DeviceNode->Flags & 0x2000;
if( inited < 0 )
{
if( v18 )
{
Problem = DeviceNode->Problem;
if( (_DWORD)Problem == 1 || (_DWORD)Problem == 18 )
PipSetDevNodeProblem(DeviceNode, Problem, inited);
}
}
else
{
LODWORD(ConfigFlags) = ConfigFlags & 0xFFF7FB9F;
v6 &= ~0x20u;
if( v18 )
{
v17 = 1i64;
if( DeviceNode->Problem == 1
|| (v28 = DeviceNode->Problem, (unsigned int)v28 <= 0x38)
&& (v29 = 0x100000010040000i64, _bittest64(&v29, v28)) )
{
PipClearDevNodeProblem(DeviceNode);
}
}
if( ((DeviceNode->State - 770) & 0xFFFFFFEF) == 0 )
{
v19 = DeviceNode->Flags;
if( (v19 & 0x6000) != 0 )
{
if( (v19 & 0x2000) != 0 && DeviceNode->Problem == 14 && (v44 & 0x70) == 0 )
{
PipClearDevNodeProblem(DeviceNode);
PipClearDevNodeUserFlags(DeviceNode, 4ui64);
}
}
else if( (v44 & 0x70) == 0 || PnpBootMode )
{
if( (v6 & 0x40) != 0 )
PipSetDevNodeProblem(DeviceNode, 0x1Cui64, v8);
}
else
{
v30 = 0i64;
if( (v44 & 0x10) != 0 )
{
v30 = 128i64;
v31 = 128i64;
v46 = 128i64;
}
else
{
v31 = v46;
}
if( (v44 & 0x20) != 0 )
{
v31 = v30 | 0x10;
v46 = v30 | 0x10;
v30 |= 0x10ui64;
}
if( (v44 & 0x40) != 0 )
{
v31 = v30 | 0x200;
v46 = v30 | 0x200;
}
PnpUpdateRebootRequiredReason((INT64)DeviceNode->InstancePath.Buffer, v17, v31);
PipSetDevNodeProblem(DeviceNode, 0xEui64, -1073741102);
PipSetDevNodeUserFlags(DeviceNode, 4ui64);
}
}
if( HIDWORD(PropertySize) && (v6 & 0x40) != 0 )
{
LODWORD(PropertyKey) = 4;
LODWORD(Flagsb) = 23;
PiDevCfgSetObjectProperty(
*(&stru_140CF2E80 + 607),
DeviceContext,
(const PNP_OBJECT_TYPE)DeviceNode->InstancePath.Buffer,
(WCHAR *)1,
(WCHAR *)DeviceInstanceKeyHandle,
PropertyBuffera,
(UINT64)&DEVPKEY_Device_InstallError,
Flagsb,
(UINT64)&PropertySize + 4,
PropertyKey);
}
else if( (DeviceContext[0] & 1) == 0 )
{
LODWORD(PropertyKey) = 0;
LODWORD(Flagsb) = 0;
PiDevCfgSetObjectProperty(
*(&stru_140CF2E80 + 607),
DeviceContext,
(const PNP_OBJECT_TYPE)DeviceNode->InstancePath.Buffer,
(WCHAR *)1,
(WCHAR *)DeviceInstanceKeyHandle,
PropertyBuffera,
(UINT64)&DEVPKEY_Device_InstallError,
Flagsb,
0i64,
PropertyKey);
}
}
if( v52 || v6 )
{
LODWORD(ConfigFlags) = v6 | ConfigFlags;
LODWORD(PropertyBuffera) = 4;
PiDevCfgSetDeviceRegProp(
(PI_DEVCFG_DEVICE_CONTEXT *)4,
(_CM_REG_PROP)DeviceContext,
0xBui64,
(UINT8 *)4,
(UINT64)&ConfigFlags);
if( v52 )
{
LODWORD(PropertyKey) = 8;
v20 = DeviceNode->InstancePath.Buffer;
v48 = *(_QWORD *)&KUSER_SHARED_DATA.SystemTime.LowPart;
LODWORD(Flagsb) = 16;
PiDevCfgSetObjectProperty(
*(&stru_140CF2E80 + 607),
DeviceContext,
(const PNP_OBJECT_TYPE)v20,
(WCHAR *)1,
(WCHAR *)DeviceInstanceKeyHandle,
PropertyBuffera,
(UINT64)&DEVPKEY_Device_InstallDate,
Flagsb,
(UINT64)&v48,
PropertyKey);
PropertyKeya = (_DEVPROPKEY *)&PropertySize;
if( PnpGetObjectProperty(
*(&stru_140CF2E80 + 1214),
(INT64)DeviceNode->InstancePath.Buffer,
1i64,
(INT64)DeviceInstanceKeyHandle,
0i64,
(INT64)&DEVPKEY_Device_FirstInstallDate,
(INT64)&CmRegPropType,
0i64) != -1073741789
|| (_DWORD)PropertySize != 8 )
{
LODWORD(PropertyKeya) = 8;
LODWORD(Flagsc) = 16;
PiDevCfgSetObjectProperty(
*(&stru_140CF2E80 + 607),
DeviceContext,
(const PNP_OBJECT_TYPE)DeviceNode->InstancePath.Buffer,
(WCHAR *)1,
(WCHAR *)DeviceInstanceKeyHandle,
PropertyBufferb,
(UINT64)&DEVPKEY_Device_FirstInstallDate,
Flagsc,
(UINT64)&v48,
PropertyKeya);
}
}
}
LABEL_45:
if( BYTE4(CmRegPropType) )
{
v21 = DeviceNode->InstancePath.Buffer;
LODWORD(PropertySize) = 8;
if( PnpGetObjectProperty(
*(&stru_140CF2E80 + 1214),
(INT64)v21,
1i64,
(INT64)DeviceInstanceKeyHandle,
0i64,
(INT64)&DEVPKEY_Device_RebootRequiredReason,
(INT64)&CmRegPropType,
(INT64)&v46) < 0
|| (_DWORD)CmRegPropType != 9
|| (_DWORD)PropertySize != 8 )
{
v46 = 0i64;
}
LODWORD(ConfigStatus) = inited;
PiDevCfgLogDeviceConfigured(
DeviceNode,
DeviceContext,
DriverNodeResult,
(unsigned int)v44,
(INT64)ConfigStatus);
}
goto LABEL_49;
}
v7 = 1;
v8 = DriverNodeResult[103];
}
else
{
if( inited != -1073740656 || (PiDevCfgMode & 2) == 0 )
goto LABEL_21;
if( !PnpBootMode || (DeviceNode->CapabilityFlags & 0x100) != 0 )
{
if( CmIsRootEnumeratedDevice(DeviceNode->InstancePath.Buffer) )
{
LODWORD(Flagsa) = 0;
v24 = DeviceNode->InstancePath.Buffer;
LODWORD(PropertySize) = 4;
if( CmGetDeviceRegProp(
*(&stru_140CF2E80 + 607),
v24,
DeviceInstanceKeyHandle,
11i64,
&CmRegPropType,
(UINT8 *)&ConfigFlags,
&PropertySize,
(UINT64)Flagsa) >= 0
&& (_DWORD)CmRegPropType == 4
&& (_DWORD)PropertySize == 4 )
{
v25 = ConfigFlags;
}
else
{
v25 = 0;
LODWORD(ConfigFlags) = 0;
}
v7 = (v25 & 0x20) != 0;
}
else
{
v7 = 1;
}
}
else
{
v6 = 32;
}
if( CmIsRootEnumeratedDevice(DeviceNode->InstancePath.Buffer) )
{
if( PiDevCfgMigrateRootDevice(DeviceNode, DeviceContext, &ConfigFlags) >= 0 )
{
v6 |= ConfigFlags;
if( (ConfigFlags & 1) != 0 )
{
v7 = 0;
v6 &= ~0x20u;
}
}
}
v8 = -1073740656;
}
}
if( !v7 )
goto LABEL_21;
LABEL_91:
v26 = PiDevCfgConfigureDevice(DeviceNode, DeviceContext, 0i64, &ConfigFlags, &v44);
inited = v26;
if( v26 >= 0 )
{
v6 = ConfigFlags;
v52 = 1;
switch( v8 )
{
case -1073740656:
HIDWORD(PropertySize) = -536870360;
break;
case -1073740655:
HIDWORD(PropertySize) = -536870320;
break;
case -1073740654:
HIDWORD(PropertySize) = -536870319;
break;
case -1073740653:
HIDWORD(PropertySize) = -536870318;
break;
case -1073740652:
HIDWORD(PropertySize) = -536870375;
break;
}
}
v12 = ((v26 + 1073740653) & 0xFFFFFFFD) == 0;
v27 = BYTE4(CmRegPropType);
if( !v12 )
v27 = 1;
BYTE4(CmRegPropType) = v27;
goto LABEL_21;
}
}
LABEL_49:
if( DriverNodeResult )
PiDevCfgFreeDriverNode(DriverNodeResult);
LABEL_51:
RtlFreeAnsiString(&UnicodeString);
RtlFreeAnsiString(&DestinationString);
PiDevCfgFreeDeviceContext(DeviceContext);
if( p_InstancePath )
PnpDiagnosticTraceObjectWithStatus(&KMPnPEvt_DeviceConfig_Stop, &p_InstancePath->Length, inited);
return inited;
}Referenced by:
PpDevCfgProcessDevice