10static const std::vector<HookTestCase> g_Cases = {
14 "RWX view unmapped from current process",
18 {
"NtUnmapViewOfSection: executable view at * unmapped from the current process" },
21 "RX view unmapped from current process",
25 {
"NtUnmapViewOfSection: executable view at * unmapped from the current process" },
28 "Image unmapped from current process by its base",
32 {
"NtUnmapViewOfSection: executable image at * unmapped from the current process" },
36 "Image unmapped from current process by an address inside it",
39 UnmapView(GetCurrentProcess(), base + 0x1000);
41 {
"NtUnmapViewOfSection: executable image at * unmapped from the current process" },
44 "RWX view unmapped through a real handle to self",
46 HANDLE self = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
50 {
"NtUnmapViewOfSection: executable view at * unmapped from the current process" },
54 "RWX view unmapped through a handle with only limited query access",
57 HANDLE self = OpenProcess(PROCESS_VM_OPERATION | PROCESS_QUERY_LIMITED_INFORMATION, FALSE, GetCurrentProcessId());
61 {
"NtUnmapViewOfSection: executable view at * unmapped from the current process" },
65 "Image unmapped from remote process",
67 HANDLE remote = context.RemoteProcess();
71 "NtMapViewOfSection: *-byte image mapped into a remote process at * (protection 0x2, executable)",
72 "NtUnmapViewOfSection: executable image at * unmapped from the remote process",
76 "RW view unmapped from current process is not reported",
83 "RW view of an RWX section unmapped from current process is not reported",
92 "Failed unmap of executable private memory is not reported",
94 UnmapView(GetCurrentProcess(), VirtualAlloc(NULL, 0x1000, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE));
96 {
"NtAllocateVirtualMemory: 4096 executable bytes allocated at * in the current process (protection 0x40)" },
99 "Failed unmap through a handle without PROCESS_VM_OPERATION is not reported",
102 HANDLE self = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
112 "Ex: RWX view unmapped from current process",
116 {
"NtUnmapViewOfSectionEx: executable view at * unmapped from the current process" },
119 "Ex: image unmapped from remote process",
121 HANDLE remote = context.RemoteProcess();
125 "NtMapViewOfSection: *-byte image mapped into a remote process at * (protection 0x2, executable)",
126 "NtUnmapViewOfSectionEx: executable image at * unmapped from the remote process",
130 "Ex: RW view unmapped from current process is not reported",
137 "Ex: failed unmap of executable private memory is not reported",
139 UnmapViewEx(GetCurrentProcess(), VirtualAlloc(NULL, 0x1000, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE));
141 {
"NtAllocateVirtualMemory: 4096 executable bytes allocated at * in the current process (protection 0x40)" },
149 "Remote process's main image unmapped (process hollowing)",
151 HANDLE remote = context.RemoteProcess();
152 PROCESS_BASIC_INFORMATION info{};
154 remote, ProcessBasicInformation, &info,
sizeof(info), NULL);
155 PVOID imageBase = NULL;
157 ReadProcessMemory(remote, (BYTE*)info.PebBaseAddress + 2 *
sizeof(
void*), &imageBase,
sizeof(imageBase), &bytesRead);
161 std::string(
"NtReadVirtualMemory: ") + (
sizeof(
void*) == 8 ?
"8" :
"4") +
162 " bytes read from the PEB of the remote process at offset " + (
sizeof(
void*) == 8 ?
"0x10" :
"0x8"),
163 "NtUnmapViewOfSection: executable image at * unmapped from the remote process",
168int main(
int argc,
char** argv) {
169 return RunHookTests(argc, argv,
"NtUnmapViewOfSection", g_Cases);
int main()
Loads the hook DLL for this architecture from bin/<config>, one directory above the tests folder this...
Resources shared by the cases of one test run, created in the child process. The remote processes are...
T NtdllFunction(const char *name)
Looks up an ntdll export. Calls through the result go through the hooks, because the hooks patch the ...
int RunHookTests(int argc, char **argv, const char *apiName, const std::vector< HookTestCase > &cases)
Runs the cases and prints a PASS/FAIL line for each. Call from main.
PVOID MapView(HANDLE section, HANDLE process, ULONG protection)
Maps a view of a section through NtMapViewOfSection. Returns NULL if the call fails.
NTSTATUS UnmapView(HANDLE process, PVOID address)
HANDLE CreateImageSection()
Creates an image section from System32.
NTSTATUS UnmapViewEx(HANDLE process, PVOID address)
HANDLE CreatePageSection(DWORD protection)
Creates a one-page, pagefile-backed section with the given maximum protection.