Skip to content

Commit 389a552

Browse files
committed
Added desired access parameter.
1 parent f8aec05 commit 389a552

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

PipeServer/MemoryHelper.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class FlexibleBuffer
4141
std::vector<uint8_t> data;
4242
};
4343
//---------------------------------------------------------------------------
44-
std::vector<RC_Pointer> GetAvailableHandles()
44+
std::vector<RC_Pointer> GetAvailableHandles(DWORD desiredAccess)
4545
{
4646
using NTSTATUS = LONG;
4747

@@ -88,8 +88,13 @@ std::vector<RC_Pointer> GetAvailableHandles()
8888
ObjectTypeInformation = 2
8989
};
9090

91-
NTSTATUS(__stdcall *NtQuerySystemInformation)(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, ULONG SystemInformationLength, PULONG ReturnLength) = (decltype(NtQuerySystemInformation))GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "NtQuerySystemInformation");
92-
NTSTATUS(__stdcall *NtQueryObject)(HANDLE Handle, OBJECT_INFORMATION_CLASS ObjectInformationClass, PVOID ObjectInformation, ULONG ObjectInformationLength, PULONG ReturnLength) = (decltype(NtQueryObject))GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "NtQueryObject");
91+
using NtQuerySystemInformation_t = NTSTATUS(__stdcall *)(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, ULONG SystemInformationLength, PULONG ReturnLength);
92+
using NtQueryObject_t = NTSTATUS(__stdcall *)(HANDLE Handle, OBJECT_INFORMATION_CLASS ObjectInformationClass, PVOID ObjectInformation, ULONG ObjectInformationLength, PULONG ReturnLength);
93+
94+
const auto moduleHandle = GetModuleHandleW(L"ntdll.dll");
95+
96+
const auto NtQuerySystemInformation = reinterpret_cast<NtQuerySystemInformation_t>(GetProcAddress(moduleHandle, "NtQuerySystemInformation"));
97+
const auto NtQueryObject = reinterpret_cast<NtQueryObject_t>(GetProcAddress(moduleHandle, "NtQueryObject"));
9398

9499
std::vector<RC_Pointer> handles;
95100

@@ -125,10 +130,8 @@ std::vector<RC_Pointer> GetAvailableHandles()
125130
const auto status = NtQueryObject(reinterpret_cast<HANDLE>(handleEntry.Handle), OBJECT_INFORMATION_CLASS::ObjectTypeInformation, &objectTypeInfo, sizeof(objectTypeInfo), &dummy);
126131
if (status == STATUS_SUCCESS)
127132
{
128-
if (wcscmp(objectTypeInfo.TypeName.Buffer, L"Process") == 0)
133+
if (std::wcscmp(objectTypeInfo.TypeName.Buffer, L"Process") == 0)
129134
{
130-
const DWORD desiredAccess = PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE;
131-
132135
if ((handleEntry.GrantedAccess & desiredAccess) == desiredAccess)
133136
{
134137
handles.push_back(reinterpret_cast<RC_Pointer>(handleEntry.Handle));
@@ -204,7 +207,7 @@ void EnumerateRemoteSectionsAndModules(RC_Pointer remoteId, const std::function<
204207
address = reinterpret_cast<size_t>(memInfo.BaseAddress) + memInfo.RegionSize;
205208
}
206209

207-
auto handle = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetProcessId(remoteId));
210+
const auto handle = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetProcessId(remoteId));
208211
if (handle != INVALID_HANDLE_VALUE)
209212
{
210213
MODULEENTRY32W me32 = {};

PipeServer/Messages.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <psapi.h>
55

6-
extern std::vector<RC_Pointer> GetAvailableHandles();
6+
extern std::vector<RC_Pointer> GetAvailableHandles(DWORD desiredAccess);
77
extern void EnumerateRemoteSectionsAndModules(RC_Pointer remoteId, const std::function<void(RC_Pointer, RC_Pointer, std::wstring&&)>&, const std::function<void(RC_Pointer, RC_Pointer, SectionType, SectionCategory, SectionProtection, std::wstring&&, std::wstring&&)>&);
88

99
bool OpenProcessRequest::Handle(MessageClient& client)
@@ -75,7 +75,7 @@ bool EnumerateRemoteSectionsAndModulesRequest::Handle(MessageClient& client)
7575
//---------------------------------------------------------------------------
7676
bool EnumerateProcessHandlesRequest::Handle(MessageClient& client)
7777
{
78-
auto handles = GetAvailableHandles();
78+
auto handles = GetAvailableHandles(PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE);
7979

8080
for (auto handle : handles)
8181
{

0 commit comments

Comments
 (0)