Improve PR #224
This commit is contained in:
@@ -412,8 +412,4 @@ PhReferenceProcessItemForRecord(
|
||||
);
|
||||
// end_phapppub
|
||||
|
||||
BOOLEAN PhProcessIsCFGuardEnabled(
|
||||
_In_ HANDLE ProcessHandle
|
||||
);
|
||||
|
||||
#endif
|
||||
|
||||
+15
-5
@@ -84,6 +84,7 @@ PPH_MODULE_PROVIDER PhCreateModuleProvider(
|
||||
PhEmGetObjectSize(EmModuleProviderType, sizeof(PH_MODULE_PROVIDER)),
|
||||
PhModuleProviderType
|
||||
);
|
||||
memset(moduleProvider, 0, sizeof(PH_MODULE_PROVIDER));
|
||||
|
||||
moduleProvider->ModuleHashtable = PhCreateHashtable(
|
||||
sizeof(PPH_MODULE_ITEM),
|
||||
@@ -122,9 +123,21 @@ PPH_MODULE_PROVIDER PhCreateModuleProvider(
|
||||
moduleProvider->RunStatus = status;
|
||||
}
|
||||
|
||||
if (moduleProvider->ProcessHandle)
|
||||
if (WindowsVersion >= WINDOWS_8 && moduleProvider->ProcessHandle)
|
||||
{
|
||||
moduleProvider->PackageFullName = PhGetProcessPackageFullName(moduleProvider->ProcessHandle);
|
||||
|
||||
if (WindowsVersion >= WINDOWS_8_1)
|
||||
{
|
||||
BOOLEAN cfguardEnabled;
|
||||
|
||||
if (NT_SUCCESS(PhGetProcessIsCFGuardEnabled(moduleProvider->ProcessHandle, &cfguardEnabled)))
|
||||
{
|
||||
moduleProvider->ControlFlowGuardEnabled = cfguardEnabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RtlInitializeSListHead(&moduleProvider->QueryListHead);
|
||||
|
||||
PhEmCallObjectOperation(EmModuleProviderType, moduleProvider, EmObjectCreate);
|
||||
@@ -354,7 +367,6 @@ VOID PhModuleProviderUpdate(
|
||||
PPH_MODULE_PROVIDER moduleProvider = (PPH_MODULE_PROVIDER)Object;
|
||||
PPH_LIST modules;
|
||||
ULONG i;
|
||||
BOOLEAN cfGuardEnabled = FALSE;
|
||||
|
||||
// If we didn't get a handle when we created the provider,
|
||||
// abort (unless this is the System process - in that case
|
||||
@@ -445,8 +457,6 @@ VOID PhModuleProviderUpdate(
|
||||
}
|
||||
}
|
||||
|
||||
cfGuardEnabled = PhProcessIsCFGuardEnabled(moduleProvider->ProcessHandle);
|
||||
|
||||
// Look for new modules.
|
||||
for (i = 0; i < modules->Count; i++)
|
||||
{
|
||||
@@ -531,7 +541,7 @@ VOID PhModuleProviderUpdate(
|
||||
}
|
||||
|
||||
// remove CF Guard flag if CFG mitigation is not enabled for the process
|
||||
if (!cfGuardEnabled)
|
||||
if (!moduleProvider->ControlFlowGuardEnabled)
|
||||
moduleItem->ImageDllCharacteristics &= ~IMAGE_DLLCHARACTERISTICS_GUARD_CF;
|
||||
|
||||
if (NT_SUCCESS(PhQueryFullAttributesFileWin32(moduleItem->FileName->Buffer, &networkOpenInfo)))
|
||||
|
||||
+13
-38
@@ -1449,34 +1449,35 @@ VOID PhpFillProcessItem(
|
||||
{
|
||||
PS_PROTECTION protection;
|
||||
|
||||
if (NT_SUCCESS(NtQueryInformationProcess(
|
||||
ProcessItem->QueryHandle,
|
||||
ProcessProtectionInformation,
|
||||
&protection,
|
||||
sizeof(PS_PROTECTION),
|
||||
NULL
|
||||
)))
|
||||
if (NT_SUCCESS(PhGetProcessProtection(ProcessItem->QueryHandle, &protection)))
|
||||
{
|
||||
ProcessItem->Protection.Level = protection.Level;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// "emulate" PS_PROTECTION info for older OSes
|
||||
// HACK: 'emulate' the PS_PROTECTION info for older OSes.
|
||||
if (ProcessItem->IsProtectedProcess)
|
||||
ProcessItem->Protection.Type = PsProtectedTypeProtected;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// we weren't able to get protection info
|
||||
// lets signalize that with special value
|
||||
// Signalize that we weren't able to get protection info with a special value.
|
||||
// Note: We use this value to determine if we should show protection information.
|
||||
ProcessItem->Protection.Level = UCHAR_MAX;
|
||||
}
|
||||
|
||||
// Control Flow Guard
|
||||
if (ProcessItem->QueryHandle)
|
||||
ProcessItem->IsControlFlowGuardEnabled = PhProcessIsCFGuardEnabled(ProcessItem->QueryHandle);
|
||||
if (WindowsVersion >= WINDOWS_8_1 && ProcessItem->QueryHandle)
|
||||
{
|
||||
BOOLEAN cfguardEnabled;
|
||||
|
||||
if (NT_SUCCESS(PhGetProcessIsCFGuardEnabled(ProcessItem->QueryHandle, &cfguardEnabled)))
|
||||
{
|
||||
ProcessItem->IsControlFlowGuardEnabled = cfguardEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
// On Windows 8.1 and above, processes without threads are reflected processes
|
||||
// which will not terminate if we have a handle open.
|
||||
@@ -2989,29 +2990,3 @@ PPH_PROCESS_ITEM PhReferenceProcessItemForRecord(
|
||||
return processItem;
|
||||
}
|
||||
|
||||
BOOLEAN PhProcessIsCFGuardEnabled(
|
||||
_In_ HANDLE ProcessHandle
|
||||
)
|
||||
{
|
||||
BOOLEAN cfgEnabled = FALSE;
|
||||
|
||||
if (WindowsVersion >= WINDOWS_8_1)
|
||||
{
|
||||
PROCESS_MITIGATION_POLICY_INFORMATION policyInfo;
|
||||
|
||||
policyInfo.Policy = ProcessControlFlowGuardPolicy;
|
||||
|
||||
if (NT_SUCCESS(NtQueryInformationProcess(
|
||||
ProcessHandle,
|
||||
ProcessMitigationPolicy,
|
||||
&policyInfo,
|
||||
sizeof(PROCESS_MITIGATION_POLICY_INFORMATION),
|
||||
NULL
|
||||
)))
|
||||
{
|
||||
cfgEnabled = (policyInfo.ControlFlowGuardPolicy.EnableControlFlowGuard != 0);
|
||||
}
|
||||
}
|
||||
|
||||
return cfgEnabled;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user