30#if !defined PROCESSINFOCLASS
31 typedef LONG PROCESSINFOCLASS;
34 NTSTATUS(WINAPI *_ZwQueryInformationProcess)(
35 IN HANDLE ProcessHandle,
36 IN PROCESSINFOCLASS ProcessInformationClass,
37 OUT PVOID ProcessInformation,
38 IN ULONG ProcessInformationLength,
39 OUT PULONG ReturnLength
47 FARPROC procPtr = GetProcAddress(hNtDll,
"ZwQueryInformationProcess");
52 _ZwQueryInformationProcess = (NTSTATUS(WINAPI *)(
60 typedef struct _PROCESS_BASIC_INFORMATION {
64 ULONG_PTR UniqueProcessId;
66 } PROCESS_BASIC_INFORMATION;
68 PROCESS_BASIC_INFORMATION pbi = { 0 };
69 if (_ZwQueryInformationProcess(hProcess, 0, &pbi,
sizeof(PROCESS_BASIC_INFORMATION), NULL) == S_OK) {
70 const DWORD pid =
static_cast<DWORD
>(pbi.UniqueProcessId);
112 if (!areaSize)
return false;
114 const DWORD dwForbiddenArea = PAGE_GUARD | PAGE_NOACCESS;
116 MEMORY_BASIC_INFORMATION mbi = { 0 };
117 const size_t mbiSize =
sizeof(MEMORY_BASIC_INFORMATION);
119 SIZE_T sizeToCheck = areaSize;
120 LPCVOID areaPtr = areaStart;
122 while (sizeToCheck > 0) {
124 memset(&mbi, 0, mbiSize);
127 if (VirtualQuery(areaPtr, &mbi, mbiSize) != mbiSize) {
131 bool isOk = (mbi.State & MEM_COMMIT)
132 && !(mbi.Protect & dwForbiddenArea)
133 && (mbi.Protect & dwAccessRights);
137 SIZE_T offset = (ULONG_PTR)areaPtr - (ULONG_PTR)mbi.BaseAddress;
138 SIZE_T queriedSize = mbi.RegionSize - offset;
139 if (queriedSize >= sizeToCheck) {
143 sizeToCheck -= queriedSize;
144 areaPtr = LPCVOID((ULONG_PTR)areaPtr + queriedSize);
153 return (IsBadReadPtr(areaStart, areaSize)) ? true :
false;
155 const DWORD dwReadRights = PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY;