我的编译器:Microsoft Visual Studio 2012。
我的代码可以在 detours 2.1 上运行,但我无法再用我的编译器编译它(模块对于 SAFESEH 图像不安全。)。我需要使用像 MVS2005 这样的旧编译器,但我不想使用。
所以我需要更新我的代码并使用detours 3.0。
编辑了一些内容并出现了 4 个错误。
error C3861: 'DetourFunction': identifier not found
error C3861: 'DetourFunction': identifier not found
error C3861: 'DetourRemove': identifier not found
error C3861: 'DetourRemove': identifier not found
这是代码块:
此处出现 DetourFunction 错误
o_NtQuerySystemInformation = (t_NtQuerySystemInformation)DetourFunction((PBYTE)GetProcAddress(GetModuleHandle("ntdll.dll"), "NtQuerySystemInformation"), (PBYTE)My_NtQuerySystemInformation);
o_ZwOpenProcess = (t_ZwOpenProcess)DetourFunction((PBYTE)GetProcAddress(GetModuleHandle("ntdll.dll"), "ZwOpenProcess"), (PBYTE)My_ZwOpenProcess);
Detour在此处删除错误
DetourRemove((PBYTE)o_NtQuerySystemInformation, (PBYTE)My_NtQuerySystemInformation);
DetourRemove((PBYTE)o_ZwOpenProcess, (PBYTE)My_ZwOpenProcess);
更新
因此,我尝试将其更改为 DetourAttach 和 DetourDetach,但出现 PBYTE 到 PVOID 错误。
最佳答案
DetourFunction
和 DetourRemove
已替换为 DetourAttach
和 DetourDetach
。使用它们并不难,并且该库附带了一组示例,您可以在其中了解如何使用这些 API。您的代码应如下所示:
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
{
o_NtQuerySystemInformation = (t_NtQuerySystemInformation)DetourAttach(&(PVOID&)GetProcAddress(GetModuleHandle("ntdll.dll"), "NtQuerySystemInformation"), My_NtQuerySystemInformation);
o_ZwOpenProcess = (t_ZwOpenProcess)DetourAttach(&(PVOID&)GetProcAddress(GetModuleHandle("ntdll.dll"), "ZwOpenProcess"), My_ZwOpenProcess);
MyModuleHandle = (HMODULE)hModule;
MyPid = GetCurrentProcessId();
}
if (ul_reason_for_call == DLL_PROCESS_DETACH)
{
DetourDetach(&(PVOID&)o_NtQuerySystemInformation, My_NtQuerySystemInformation);
DetourDetach(&(PVOID&)o_ZwOpenProcess, My_ZwOpenProcess);
}
return TRUE;
}
关于MVS 2012 上的 C++ Detours 3.0 Express 错误 "identifier not found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16013559/