66
77#include " NativeCore.hpp"
88
9- template <typename Proc>
10- static DWORD EnumerateRemoteModulesNative (HANDLE process, Proc proc)
9+ static DWORD GetRemotePeb (HANDLE process, PPEB* ppeb)
1110{
1211 const auto ntdll = GetModuleHandle (TEXT (" ntdll" ));
1312 if (!ntdll)
@@ -27,18 +26,31 @@ static DWORD EnumerateRemoteModulesNative(HANDLE process, Proc proc)
2726 _In_ ULONG ProcessInformationLength,
2827 _Out_opt_ PULONG ReturnLength
2928 );
30-
29+
3130 const auto _NtQueryInformationProcess = tNtQueryInformationProcess (GetProcAddress (ntdll, " NtQueryInformationProcess" ));
3231 if (!_NtQueryInformationProcess)
3332 return ERROR_NOT_FOUND;
34-
33+
3534 PROCESS_BASIC_INFORMATION pbi;
3635 const auto status = _NtQueryInformationProcess (process, ProcessBasicInformation, &pbi, sizeof (pbi), nullptr );
3736 if (!NT_SUCCESS (status))
3837 return _RtlNtStatusToDosError (status);
3938
39+ *ppeb = pbi.PebBaseAddress ;
40+
41+ return ERROR_SUCCESS;
42+ }
43+
44+ template <typename Proc>
45+ static DWORD EnumerateRemoteModulesNative (HANDLE process, Proc proc)
46+ {
47+ PPEB ppeb;
48+ const auto error = GetRemotePeb (process, &ppeb);
49+ if (error != ERROR_SUCCESS)
50+ return error;
51+
4052 PPEB_LDR_DATA ldr;
41- auto success = ReadRemoteMemory (process, &pbi. PebBaseAddress ->Ldr , &ldr, 0 , sizeof (ldr));
53+ auto success = ReadRemoteMemory (process, ppeb ->Ldr , &ldr, 0 , sizeof (ldr));
4254 if (!success)
4355 return ERROR_READ_FAULT; // we seem to swallow the error anyways, might aswell give a distinctive one back
4456
0 commit comments