PipCallDriverAddDeviceQueryRoutine
NTSTATUS __stdcall PipCallDriverAddDeviceQueryRoutine(
UINT64 ValueType,
WCHAR *ValueData,
UINT64 ValueLength,
_QUERY_CONTEXT *Context,
UINT64 ServiceType){
NTSTATUS result;
const wchar_t *v6;
_ADAPTER_OBJECT *v8;
NTSTATUS v9;
char v10;
VOID *v11;
__int16 v12;
char v13;
int v14;
int v15;
int v16;
int DriverNameFromKeyNode;
int ServiceStartType;
unsigned int v19;
__int64 v20;
NTSTATUS v21;
UINT64 v22;
VOID ***v23;
VOID **PoolWithTag;
UINT16 GroupOrderIndex;
int v26;
VOID *v27;
unsigned __int64 v28;
__int64 v29;
int v30;
_DEVICE_NODE *v31;
int v32;
NTSTATUS v33;
UINT64 v34;
INT64 DriverEntryStatus;
VOID *ServiceHandle;
_UNICODE_STRING DestinationString;
_UNICODE_STRING DriverName;
char v39;
UINT8 CheckForSafeBoot;
result = 0;
v6 = L"\\Driver\\";
DriverEntryStatus = 0i64;
v39 = 0;
ServiceHandle = 0i64;
v8 = 0i64;
v9 = 0;
v10 = 0;
v11 = 0i64;
DestinationString = 0i64;
DriverName = 0i64;
if( (_DWORD)ValueType == 1 && (unsigned int)ValueLength > 2 )
{
RtlInitUnicodeString(&DestinationString, ValueData);
v12 = 92;
v13 = 1;
v14 = 0;
do
{
if( DestinationString.Buffer[v14] != v12 )
{
v15 = 0;
v13 = 0;
goto LABEL_6;
}
++v6;
++v14;
v12 = *v6;
}
while( *v6 );
v15 = 0;
LABEL_6:
if( v13 )
{
RtlInitUnicodeString(&DriverName, DestinationString.Buffer);
}
else
{
if( !*(_WORD *)(*(_QWORD *)Context + 56i64) )
{
*(_UNICODE_STRING *)(*(_QWORD *)Context + 56i64) = DestinationString;
*(_QWORD *)(*(_QWORD *)Context + 64i64) = ExAllocatePoolWithTag(
1ui64,
DestinationString.MaximumLength,
1215327824i64);
v27 = *(VOID **)(*(_QWORD *)Context + 64i64);
if( !v27 )
{
*(_WORD *)(*(_QWORD *)Context + 58i64) = 0;
*(_WORD *)(*(_QWORD *)Context + 56i64) = 0;
*(_QWORD *)(*(_QWORD *)Context + 64i64) = 0i64;
return -1073741823;
}
memmove(v27, DestinationString.Buffer, DestinationString.MaximumLength);
}
v16 = PipOpenServiceEnumKeys(&DestinationString, 0x20019ui64, &ServiceHandle, 0i64, 0);
v15 = v16;
if( v16 < 0 )
{
if( v16 != -1073741772 || (_DWORD)ServiceType )
PipSetDevNodeProblem(*(_DEVICE_NODE **)Context, 0x13ui64, v16);
else
v15 = 0;
v11 = ServiceHandle;
goto LABEL_23;
}
v11 = ServiceHandle;
DriverNameFromKeyNode = IopGetDriverNameFromKeyNode(ServiceHandle, &DriverName);
v15 = DriverNameFromKeyNode;
if( DriverNameFromKeyNode < 0 )
{
PipSetDevNodeProblem(*(_DEVICE_NODE **)Context, 0x13ui64, DriverNameFromKeyNode);
goto LABEL_23;
}
v39 = 1;
v15 = 0;
}
v8 = (_ADAPTER_OBJECT *)IopReferenceDriverObjectByName(&DriverName);
ServiceHandle = v8;
if( v8 )
{
LABEL_36:
if( ((__int64)v8->AdapterObject.ContiguousMapRegisters & 0x10) != 0 )
{
if( PnpIsLegacyDriver((__int64)v8) )
{
if( (_DWORD)ServiceType != 3 )
goto LABEL_22;
PipSetDevNodeFlags(*(_DEVICE_NODE **)Context, 0x1000ui64);
PipSetDevNodeState(*(_DEVICE_NODE **)Context, DeviceNodeStarted);
}
else if( (unsigned int)(*(_DWORD *)(*(_QWORD *)Context + 300i64) - 770) <= 1 )
{
v23 = (VOID ***)((char *)&Context[2 * (unsigned int)ServiceType] + v22);
PoolWithTag = ExAllocatePoolWithTag((unsigned int)(v22 - 15), v22, 1852141648i64);
if( PoolWithTag )
{
*PoolWithTag = v8;
v8 = 0i64;
PoolWithTag[1] = 0i64;
while( *v23 )
v23 = (VOID ***)(*v23 + 1);
*v23 = PoolWithTag;
}
else
{
v15 = -1073741670;
}
goto LABEL_22;
}
}
goto LABEL_21;
}
if( !v13 )
{
ServiceStartType = PnpGetServiceStartType(DestinationString.Buffer, v11, (_DWORD *)&DriverEntryStatus + 1);
v19 = HIDWORD(DriverEntryStatus);
if( ServiceStartType < 0 )
v19 = 4;
if( (_DWORD)ServiceType != 3 && !*(&PnpReplaceEvent + 6682) )
{
GroupOrderIndex = PpInitGetGroupOrderIndex(v11);
v26 = PnpLoadBootFilterDriver(v11, &DriverName, GroupOrderIndex, (_LIST_ENTRY **)&ServiceHandle);
v15 = v26;
if( v26 < 0 )
{
if( (unsigned int)(v26 + 1073740949) > 1 )
{
if( v19 && !*(_BYTE *)(*((_QWORD *)Context + 1) + 4i64) && !PnpCheckPossibleBootStartDriver(v11) )
*(_BYTE *)(*(_QWORD *)Context + 688i64) = 1;
v8 = (_ADAPTER_OBJECT *)ServiceHandle;
goto LABEL_22;
}
v8 = (_ADAPTER_OBJECT *)ServiceHandle;
}
else
{
v8 = (_ADAPTER_OBJECT *)ServiceHandle;
if( !ServiceHandle )
goto LABEL_87;
ObfReferenceObject(ServiceHandle);
}
goto LABEL_50;
}
v20 = *((_QWORD *)Context + 1);
if( v19 > *(_DWORD *)v20 )
{
if( v19 == 4 && (*(_DWORD *)(*(_QWORD *)Context + 396i64) & 0x6000) == 0 )
PipSetDevNodeProblem(*(_DEVICE_NODE **)Context, 0x20ui64, 0);
}
else
{
if( *(_BYTE *)(v20 + 4) )
{
v21 = IopLoadDriver(v11, CheckForSafeBoot, (_DWORD)ServiceType != 3, &DriverEntryStatus);
v15 = v21;
v11 = 0i64;
v9 = v21;
if( v21 < 0 )
{
if( v21 == -1073740955 )
{
if( (_DWORD)DriverEntryStatus == -1073741670 )
v15 = -1073741670;
}
else
{
v28 = (unsigned int)(v21 + 1073740961);
if( (unsigned int)v28 > 0x2F || (v29 = 0x800000003001i64, !_bittest64(&v29, v28)) )
{
if( v15 != -1073741218 && v15 != -1073741670 && v15 != -1073740760 )
v15 = -1073741204;
}
}
}
if( *(&PnpReplaceEvent + 6004) )
IopCallDriverReinitializationRoutines(0);
v8 = (_ADAPTER_OBJECT *)IopReferenceDriverObjectByName(&DriverName);
if( v8 )
{
LABEL_35:
v15 = 0;
goto LABEL_36;
}
if( !PnpBootMode
|| (unsigned int)(v15 + 1073740961) <= 0xD && (v30 = 12353, _bittest(&v30, v15 + 1073740961))
|| v15 == -1073740760 )
{
LABEL_87:
PnpDiagnosticTraceDeviceOperation(
&KMPnPEvt_DriverLoad_Fail,
(unsigned __int16 *)(*(_QWORD *)Context + 40i64),
v15,
(__int64)&DriverName,
0);
v31 = *(_DEVICE_NODE **)Context;
if( (*(_DWORD *)(*(_QWORD *)Context + 396i64) & 0x6000) == 0 )
{
if( v15 > -1073740955 )
{
if( v15 == -1073740949 )
{
PipSetDevNodeProblem(v31, 0x30ui64, -1073740949);
PipSetDevNodeFlags(*(_DEVICE_NODE **)Context, 0x100000ui64);
goto LABEL_22;
}
if( v15 == -1073740948 )
{
PipSetDevNodeFlags(v31, 0x100000ui64);
v15 = 0;
goto LABEL_22;
}
v33 = -1073740914;
if( v15 == -1073740914 )
{
v34 = 38i64;
goto LABEL_100;
}
v32 = -1073740760;
if( v15 != -1073740760 )
goto LABEL_108;
v34 = 52i64;
}
else
{
if( v15 == -1073740955 )
{
v33 = DriverEntryStatus;
v34 = 37i64;
goto LABEL_100;
}
v32 = -1073741670;
if( v15 == -1073741670 )
{
v34 = 3i64;
}
else
{
v33 = -1073741472;
if( v15 == -1073741472 )
{
v34 = 40i64;
goto LABEL_100;
}
if( v15 == -1073741411 )
goto LABEL_95;
v32 = -1073741218;
if( v15 != -1073741218 )
{
if( v15 == -1073741204 )
{
LABEL_95:
v33 = v9;
v34 = 39i64;
LABEL_100:
PipSetDevNodeProblem(v31, v34, v33);
goto LABEL_22;
}
LABEL_108:
v33 = v15;
v34 = 31i64;
goto LABEL_100;
}
v34 = 41i64;
}
}
v33 = v32;
goto LABEL_100;
}
LABEL_22:
v10 = v39;
LABEL_23:
if( v11 )
ZwClose((_HANDLE)v11);
if( v10 )
RtlFreeAnsiString(&DriverName);
if( v8 )
HalPutDmaAdapter(v8);
return v15;
}
v15 = -1073741204;
LABEL_50:
if( !v8 )
goto LABEL_87;
goto LABEL_35;
}
if( v19 && !PnpCheckPossibleBootStartDriver(v11) )
*(_BYTE *)(*(_QWORD *)Context + 688i64) = 1;
}
}
LABEL_21:
v15 = -1073741823;
goto LABEL_22;
}
return result;
}Referenced by:
PnpCallDriverQueryServiceHelper