MVS 2012 上的 C++ Detours 3.0 Express 错误 "identifier not found"

标签 c++ detours

我的编译器: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 错误。

最佳答案

DetourFunctionDetourRemove 已替换为 DetourAttachDetourDetach。使用它们并不难,并且该库附带了一组示例,您可以在其中了解如何使用这些 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/

相关文章:

c++ - 为什么C++中的API hook ExtTextOut和DrawText只会输出垃圾?

c++ - 在鼠标 Hook 中,滚轮增量始终为 0

c++ - 将 sleep() 注入(inject)到外部进程的函数中

c++ - 防止 DLL 文件通过 MS Detours 加载到我的进程中

c++ - 如何在 Windows 上使用命令行运行 UnitTest++

windows - Microsoft Detours 如何工作以及如何使用它来获取堆栈跟踪?

32-bit - 构建 32 位 Detours 库

c++ - 无法使用结构作为键在 C++ 映射中找到插入的值

c++ - 如何处理SIGABRT信号?

c++ - 如何提高我的 C++ 程序读取分隔文本文件的速度?