@@ -41,7 +41,7 @@ class FlexibleBuffer
41
41
std::vector<uint8_t > data;
42
42
};
43
43
// ---------------------------------------------------------------------------
44
- std::vector<RC_Pointer> GetAvailableHandles ()
44
+ std::vector<RC_Pointer> GetAvailableHandles (DWORD desiredAccess )
45
45
{
46
46
using NTSTATUS = LONG;
47
47
@@ -88,8 +88,13 @@ std::vector<RC_Pointer> GetAvailableHandles()
88
88
ObjectTypeInformation = 2
89
89
};
90
90
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" ));
93
98
94
99
std::vector<RC_Pointer> handles;
95
100
@@ -125,10 +130,8 @@ std::vector<RC_Pointer> GetAvailableHandles()
125
130
const auto status = NtQueryObject (reinterpret_cast <HANDLE>(handleEntry.Handle ), OBJECT_INFORMATION_CLASS::ObjectTypeInformation, &objectTypeInfo, sizeof (objectTypeInfo), &dummy);
126
131
if (status == STATUS_SUCCESS)
127
132
{
128
- if (wcscmp (objectTypeInfo.TypeName .Buffer , L" Process" ) == 0 )
133
+ if (std:: wcscmp (objectTypeInfo.TypeName .Buffer , L" Process" ) == 0 )
129
134
{
130
- const DWORD desiredAccess = PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE;
131
-
132
135
if ((handleEntry.GrantedAccess & desiredAccess) == desiredAccess)
133
136
{
134
137
handles.push_back (reinterpret_cast <RC_Pointer>(handleEntry.Handle ));
@@ -204,7 +207,7 @@ void EnumerateRemoteSectionsAndModules(RC_Pointer remoteId, const std::function<
204
207
address = reinterpret_cast <size_t >(memInfo.BaseAddress ) + memInfo.RegionSize ;
205
208
}
206
209
207
- auto handle = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE, GetProcessId (remoteId));
210
+ const auto handle = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE, GetProcessId (remoteId));
208
211
if (handle != INVALID_HANDLE_VALUE)
209
212
{
210
213
MODULEENTRY32W me32 = {};
0 commit comments