7#define TEST_NT_SUCCESS(status) ((NTSTATUS)(status) >= 0)
10#define TEST_VIEW_UNMAP 2
13 PVOID* BaseAddress, ULONG_PTR ZeroBits, SIZE_T CommitSize, PLARGE_INTEGER SectionOffset,
14 PSIZE_T ViewSize, DWORD InheritDisposition, ULONG AllocationType, ULONG Win32Protect);
16 PVOID* BaseAddress, PLARGE_INTEGER SectionOffset, PSIZE_T ViewSize, ULONG AllocationType,
17 ULONG PageProtection, PMEM_EXTENDED_PARAMETER ExtendedParameters, ULONG ExtendedParameterCount);
23 return CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, protection | SEC_COMMIT, 0, 0x1000, NULL);
32 strcat_s(path,
"\\version.dll");
33 HANDLE file = CreateFileA(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
34 if (file == INVALID_HANDLE_VALUE) {
35 fprintf(stderr,
" failed to open %s (error %lu)\n", path, GetLastError());
38 HANDLE section = CreateFileMappingA(file, NULL, PAGE_READONLY | SEC_IMAGE, 0, 0, NULL);
44inline PVOID
MapView(HANDLE section, HANDLE process, ULONG protection) {
48 NTSTATUS status = map(section, process, &base, 0, 0, NULL, &size,
TEST_VIEW_UNMAP, 0, protection);
53inline PVOID
MapViewEx(HANDLE section, HANDLE process, ULONG protection) {
56 fprintf(stderr,
" NtMapViewOfSectionEx is not exported by this ntdll\n");
61 NTSTATUS status = map(section, process, &base, NULL, &size, 0, protection, NULL, 0);
65inline NTSTATUS
UnmapView(HANDLE process, PVOID address) {
72 fprintf(stderr,
" NtUnmapViewOfSectionEx is not exported by this ntdll\n");
73 return (NTSTATUS)0xC0000002;
75 return unmap(process, address, 0);
T NtdllFunction(const char *name)
Looks up an ntdll export. Calls through the result go through the hooks, because the hooks patch the ...
#define TEST_NT_SUCCESS(status)
NTSTATUS(NTAPI * NtMapViewOfSectionEx_t)(HANDLE SectionHandle, HANDLE ProcessHandle, PVOID *BaseAddress, PLARGE_INTEGER SectionOffset, PSIZE_T ViewSize, ULONG AllocationType, ULONG PageProtection, PMEM_EXTENDED_PARAMETER ExtendedParameters, ULONG ExtendedParameterCount)
NTSTATUS(NTAPI * NtUnmapViewOfSectionEx_t)(HANDLE ProcessHandle, PVOID BaseAddress, ULONG Flags)
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)
NTSTATUS(NTAPI * NtMapViewOfSection_t)(HANDLE SectionHandle, HANDLE ProcessHandle, PVOID *BaseAddress, ULONG_PTR ZeroBits, SIZE_T CommitSize, PLARGE_INTEGER SectionOffset, PSIZE_T ViewSize, DWORD InheritDisposition, ULONG AllocationType, ULONG Win32Protect)
PVOID MapViewEx(HANDLE section, HANDLE process, ULONG protection)
Maps a view of a section through NtMapViewOfSectionEx. Returns NULL if the call fails.
#define TEST_VIEW_UNMAP
SECTION_INHERIT::ViewUnmap: the view is not mapped into child processes.
HANDLE CreatePageSection(DWORD protection)
Creates a one-page, pagefile-backed section with the given maximum protection.
NTSTATUS(NTAPI * NtUnmapViewOfSection_t)(HANDLE ProcessHandle, PVOID BaseAddress)