这看起来像用户模式代码,因此您可能不想链接到 ntoskrnl.lib。你宁愿链接到ntdll。
我可能会这样做的方式是使用动态链接并调用GetProcAddress
传入HANDLE
ntdll.dll 和ZwUnmapViewOfSection
.
示例代码:
typedef LONG (NTAPI *pfnZwUnmapViewOfSection)(HANDLE, PVOID);
HMODULE hMod = GetModuleHandle("ntdll.dll");
pfnZwUnmapViewOfSection pZwUnmapViewOfSection= (pfnZwUnmapViewOfSection)GetProcAddress(hMod, "ZwUnmapViewOfSection");
我还没有编译这个,但它应该看起来像那样(可能添加一些错误检查等)。
关于您的其他问题:NTAPI
在这种情况下,是一个定义调用约定的宏__stdcall
。调用约定与函数的参数如何传递以及谁将清理这些参数有关。
例如,__stdcall
要求参数以相反的顺序压入堆栈,被调用者将清理堆栈。
Similarly, NTSYSAPI
is a macro that just resolves to __declspec(dllimport)
if I recall correctly.
Also, I should point out that calling functions exported by NtDll in user-mode is generally frowned upon. And, the code that you're writing will also have additional problems along the way (even after it appears to be working).
In case you're looking for another example of code that performs a very similar task to the one you're writing, you might check here. It was a technique used by the Duqu malware. Good luck!