Skip to content

Commit 4b893a0

Browse files
committed
Add PhGetProcessHeapFrontEndType
1 parent 53e3df4 commit 4b893a0

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

phlib/include/phnative.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,7 @@ typedef struct _PH_PROCESS_DEBUG_HEAP_ENTRY
17931793
{
17941794
ULONG Flags;
17951795
ULONG Signature;
1796+
UCHAR HeapFrontEndType;
17961797
ULONG NumberOfEntries;
17971798
PVOID BaseAddress;
17981799
SIZE_T BytesAllocated;
@@ -1803,6 +1804,7 @@ typedef struct _PH_PROCESS_DEBUG_HEAP_ENTRY32
18031804
{
18041805
ULONG Flags;
18051806
ULONG Signature;
1807+
UCHAR HeapFrontEndType;
18061808
ULONG NumberOfEntries;
18071809
ULONG BaseAddress;
18081810
ULONG BytesAllocated;

phlib/native.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10237,6 +10237,7 @@ NTSTATUS PhGetProcessHeapSignature(
1023710237

1023810238
if (WindowsVersion >= WINDOWS_7)
1023910239
{
10240+
// dt _HEAP SegmentSignature
1024010241
status = NtReadVirtualMemory(
1024110242
ProcessHandle,
1024210243
PTR_ADD_OFFSET(HeapAddress, IsWow64 ? 0x8 : 0x10),
@@ -10255,6 +10256,57 @@ NTSTATUS PhGetProcessHeapSignature(
1025510256
return status;
1025610257
}
1025710258

10259+
NTSTATUS PhGetProcessHeapFrontEndType(
10260+
_In_ HANDLE ProcessHandle,
10261+
_In_ PVOID HeapAddress,
10262+
_In_ ULONG IsWow64,
10263+
_Out_ UCHAR *HeapFrontEndType
10264+
)
10265+
{
10266+
NTSTATUS status = STATUS_UNSUCCESSFUL;
10267+
UCHAR heapFrontEndType = UCHAR_MAX;
10268+
10269+
if (WindowsVersion >= WINDOWS_10)
10270+
{
10271+
// dt _HEAP FrontEndHeapType
10272+
status = NtReadVirtualMemory(
10273+
ProcessHandle,
10274+
PTR_ADD_OFFSET(HeapAddress, IsWow64 ? 0x0ea : 0x1a2),
10275+
&heapFrontEndType,
10276+
sizeof(UCHAR),
10277+
NULL
10278+
);
10279+
}
10280+
else if (WindowsVersion >= WINDOWS_8_1)
10281+
{
10282+
status = NtReadVirtualMemory(
10283+
ProcessHandle,
10284+
PTR_ADD_OFFSET(HeapAddress, IsWow64 ? 0x0d6 : 0x17a),
10285+
&heapFrontEndType,
10286+
sizeof(UCHAR),
10287+
NULL
10288+
);
10289+
}
10290+
else if (WindowsVersion >= WINDOWS_7)
10291+
{
10292+
status = NtReadVirtualMemory(
10293+
ProcessHandle,
10294+
PTR_ADD_OFFSET(HeapAddress, IsWow64 ? 0x0da : 0x182),
10295+
&heapFrontEndType,
10296+
sizeof(UCHAR),
10297+
NULL
10298+
);
10299+
}
10300+
10301+
if (NT_SUCCESS(status))
10302+
{
10303+
if (HeapFrontEndType)
10304+
*HeapFrontEndType = heapFrontEndType;
10305+
}
10306+
10307+
return status;
10308+
}
10309+
1025810310
NTSTATUS PhQueryProcessHeapInformation(
1025910311
_In_ HANDLE ProcessId,
1026010312
_Out_ PPH_PROCESS_DEBUG_HEAP_INFORMATION* HeapInformation
@@ -10342,6 +10394,7 @@ NTSTATUS PhQueryProcessHeapInformation(
1034210394

1034310395
heapDebugInfo->Heaps[i].Flags = heapInfo->Flags;
1034410396
heapDebugInfo->Heaps[i].Signature = ULONG_MAX;
10397+
heapDebugInfo->Heaps[i].HeapFrontEndType = UCHAR_MAX;
1034510398
heapDebugInfo->Heaps[i].NumberOfEntries = heapInfo->NumberOfEntries;
1034610399
heapDebugInfo->Heaps[i].BaseAddress = heapInfo->BaseAddress;
1034710400
heapDebugInfo->Heaps[i].BytesAllocated = allocated;
@@ -10354,6 +10407,7 @@ NTSTATUS PhQueryProcessHeapInformation(
1035410407
)))
1035510408
{
1035610409
ULONG signature = ULONG_MAX;
10410+
UCHAR frontEndType = UCHAR_MAX;
1035710411
#ifndef _WIN64
1035810412
BOOLEAN isWow64 = TRUE;
1035910413
#else
@@ -10371,6 +10425,16 @@ NTSTATUS PhQueryProcessHeapInformation(
1037110425
heapDebugInfo->Heaps[i].Signature = signature;
1037210426
}
1037310427

10428+
if (NT_SUCCESS(PhGetProcessHeapFrontEndType(
10429+
processHandle,
10430+
heapInfo->BaseAddress,
10431+
isWow64,
10432+
&frontEndType
10433+
)))
10434+
{
10435+
heapDebugInfo->Heaps[i].HeapFrontEndType = frontEndType;
10436+
}
10437+
1037410438
NtClose(processHandle);
1037510439
}
1037610440
}

0 commit comments

Comments
 (0)