55#include < vector>
66#include < tlhelp32.h>
77
8+ #include " ntdll.h"
9+ #include " winntheap.h"
810#include " injection/custom_ipc.h"
911#include " program_result.h"
1012
@@ -14,9 +16,15 @@ typedef _Return_type_success_(return >= 0) LONG NTSTATUS;
1416
1517typedef NTSTATUS (NTAPI *pNtSuspendProcess)(
1618 HANDLE ProcessHandle
17- ); // Undocumented NTDLL function
19+ );
1820}
1921
22+ typedef NTSTATUS (NTAPI* pNtQueryVirtualMemory)(
23+ HANDLE, PVOID, int , PVOID, SIZE_T, PSIZE_T);
24+
25+ typedef NTSTATUS (NTAPI* pNtQueryInformationProcess)(
26+ HANDLE, int , PVOID, ULONG, PULONG);
27+
2028namespace process_manipulation {
2129
2230// from x64dbg
@@ -150,7 +158,7 @@ class ProcessCapturer {
150158 error_handling::ProgramResult GetMemoryChunk (LPCVOID start, SIZE_T size, BYTE* buffer, SIZE_T* bytes_read);
151159 void WriteBufferToFile (unsigned char * buffer, SIZE_T size, std::string file_name);
152160
153- error_handling::ProgramResult EnumerateHeaps (std::vector<HeapInformation>* heaps);
161+ error_handling::ProgramResult EnumerateHeaps (std::vector<HeapInformation>& heaps, bool extended_search = false );
154162
155163 /* *
156164 * From the information about the heap, copies the whole heap to a buffer.
@@ -226,6 +234,13 @@ class ProcessCapturer {
226234 */
227235 error_handling::ProgramResult GetKeyBlobFromRemote (HCRYPTKEY key_handle, DWORD blob_type, std::vector<BYTE>& key_blob);
228236
237+ /* *
238+ * Returns a copy of the Process Environment Block of the target process
239+ * @param peb A pointer to a PEB structure
240+ */
241+ error_handling::ProgramResult CopyPEB (void * peb);
242+ void * GetPEBLocation ();
243+
229244 private:
230245 /* *
231246 * Function for initializing dynamically imported functions, such as `NtSuspendProcess`.
@@ -240,6 +255,17 @@ class ProcessCapturer {
240255 error_handling::ProgramResult StartControllerServerOnProcess ();
241256 error_handling::ProgramResult StopControllerServerOnProcess (bool terminate = false );
242257
258+ /* *
259+ * Looks for heaps by enumerating the memory regions of the process and matching
260+ * for the HEAP_ENTRY structure
261+ * @param heaps (OUT) vector where the heap region base and size will be placed
262+ */
263+ error_handling::ProgramResult ExtendedHeapSearch (std::vector<HeapInformation>& heaps);
264+ error_handling::ProgramResult SimpleHeapSearch (std::vector<HeapInformation>& heaps);
265+
266+ HANDLE proc_handle_;
267+ pNtQueryInformationProcess fnNtQueryInformationProcess_;
268+ pNtQueryVirtualMemory fnNtQueryVirtualMemory_;
243269 static nt_suspend::pNtSuspendProcess fNtPauseProcess ;
244270 custom_ipc::CustomClient injection_client_;
245271 DWORD pid_;
0 commit comments