2

我已经在这段代码上工作了几个小时,这让我发疯了!

整个来源在这里http://pastebin.com/Urxh68W4但我很确定我知道这个问题。

extern "C" NTSYSAPI LONG NTAPI ZwUnmapViewOfSection(HANDLE, PVOID);

当我运行它时,我收到以下错误:

Error 1 error LNK2019: unresolved external symbol __imp__ZwUnmapViewOfSection@8 referenced in function _wWinMain@16

我猜应该包含一些 dll 或库,所以我将 Ntoskrnl.lib 添加到我的项目中,因为它包含 ZwUnmapViewOfSection 函数。

我完全不知道该怎么做。我应该使用 Ntdll.dll 吗?如果是这样,我什至如何链接 dll?我以为你只能使用 Visual Studio 2010 中的库。

另外,NTSYSAPI 和 NTAPI 到底是什么?网络上几乎没有任何信息。

4

1 回答 1

5

这看起来像用户模式代码,因此您可能不想链接到 ntoskrnl.lib。你宁愿链接到ntdll。

我可能会这样做的方式是使用动态链接并调用GetProcAddress传入HANDLEntdll.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!

于 2013-03-30T03:10:52.127 回答