- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将 MessageBoxA 函数与 MS Detours 3.0 Hook ,但是当我尝试它时,我的程序崩溃了。我不确定是什么导致程序崩溃。当我运行测试程序并按下 shift 时,会出现消息框,但是当我注入(inject) dll 并按下 shift 时,我的程序崩溃了。
测试程序
#include <Windows.h>
int main()
{
for(;;)
{
if(GetAsyncKeyState(VK_SHIFT))
{
MessageBoxA(0,"NOT HOOKED","HOOK STATUS",0);
}
}
}
Hook 动态链接库
#include <Windows.h>
#include <detours.h>
#pragma comment(lib,"detours.lib")
BOOL (WINAPI* oMessageBoxA)(HWND,LPCTSTR,LPCTSTR,UINT);
BOOL WINAPI hMessageBoxA( HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption,UINT uType)
{
return oMessageBoxA(hWnd,"HOOKED",lpCaption,uType);
}
void patch()
{
HMODULE user32 = GetModuleHandle("user32.dll");
if(user32 != NULL)
{
DWORD MessageBoxAddress = (DWORD)GetProcAddress(user32,"MessageBoxA");
oMessageBoxA = (BOOL (WINAPI*)(HWND, LPCTSTR, LPCTSTR, UINT))MessageBoxAddress;
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)oMessageBoxA, hMessageBoxA);
DetourTransactionCommit();
}
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
{
if(fdwReason==DLL_PROCESS_ATTACH)
{
patch();
}
}
最佳答案
您错误地声明了 MessageBoxA()
的签名,并且您对 DWORD MessageBoxAddress
的使用在 64 位 DLL 中不起作用。
试试这个 DLL 代码:
#include <Windows.h>
#include <detours.h>
#pragma comment(lib,"detours.lib")
typedef int (WINAPI* LPFN_MBA)(HWND, LPCSTR, LPCSTR, UINT);
LPFN_MBA oMessageBoxA = NULL;
int WINAPI hMessageBoxA( HWND hWnd, LPCSTR lpText, LPCSTR lpCaption,UINT uType)
{
return oMessageBoxA(hWnd,"HOOKED",lpCaption,uType);
}
void patch()
{
HMODULE user32 = GetModuleHandle(TEXT("user32.dll"));
if (user32 != NULL)
{
oMessageBoxA = (LPFN_MBA) GetProcAddress(user32, "MessageBoxA");
if (oMessageBoxA != NULL)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((PVOID*)&oMessageBoxA, hMessageBoxA);
DetourTransactionCommit();
}
}
}
void unpatch()
{
if (oMessageBoxA != NULL)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach((PVOID*)&oMessageBoxA, hMessageBoxA);
DetourTransactionCommit();
}
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
if (fdwReason == DLL_PROCESS_ATTACH)
{
DisableThreadLibraryCalls(hinstDLL);
patch();
}
else if (fdwReason == DLL_PROCESS_DETACH)
{
unpatch();
}
}
阅读以下内容了解更多详情:
关于c++ - Detours 3.0 Hook 崩溃 MessageBoxA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21128363/
我有几个关于 Microsoft Detours Library 的快速问题。我以前用过(成功),但是我只是想到了这个功能: LONG DetourUpdateThread(HANDLE hThrea
我是 Microsoft Detours 的新手。我已经安装它来跟踪进程进行的系统调用。我运行以下从网上获得的命令 syelogd.exe /q C:\Users\xxx\Desktop\log.tx
我正在寻找 Delphi 示例,但我只能找到 C++ 示例代码。 例如,如何在Delphi中定义下面的钩子(Hook)? DETOUR_TRAMPOLINE(int WINAPI SetScrol
我正在尝试拦截系统上每个对象的构造/销毁。为此,我使用 Detours Lib创建运行时补丁。它似乎以某种方式工作 FastCode方法确实如此。我认为它应该有相同的限制(无法修补操作码小于 5 个字
请问tileLayers在detour中是如何工作的。 我能否将任意 2 block 瓷砖分层,导致“切口”合并到更大的洞中?以何种方式,是否有任何限制?我可以拥有多少层以及它们在导航时如何交互。例如
在这里感觉很愚蠢,但为什么这段代码在 Visual 中给我一个语法错误Studio 何时尝试编译它? DetourAttach(&(PVOID&)true_create_file, creat
我尝试在谷歌上搜索编译器错误,但它甚至没有返回搜索结果。所以,我在这里有点迷路了。我刚刚下载了 Microsoft Detours,构建它并从中获取了 detours.h、detours.lib、de
我在使用 Microsoft Detours 时遇到访问冲突问题。我制作了一个加载到第三方应用程序中的 dll。我正在使用 Detours 制作一个蹦床功能到一个未记录的功能,Ida Pro 显示为:
我正在寻找一个 C 库/框架,它允许我替换内存中的函数并将它们重定向到我自己的实现,同时仍然允许我的实现调用原始实现。 这在 Linux-y 系统上似乎是一个相当罕见的需求,大概是因为 LD_PREL
我有一个应用程序,它使用 Winsock 2.0 recv 函数,我可以通过 Redox Packet Editor 捕获输出,例如,它确认版本是 2.0。 我有这段代码来 Hook 函数: #def
我不会在 Minesweeper 中绕过 PlaySoundW 功能。游戏一调用 PlaySoundW 函数就崩溃了。如果我在我的代码中取消对 Beep 的注释,游戏会发出哔哔声然后崩溃。 现在代码正
我正在尝试学习使用弯路修改和扩展程序中的功能。在本例中,我尝试修改 Windows 记事本 32 位中的 InsertDateTime 函数。 我正在使用 Winject 注入(inject)我创建的
很长一段时间我都没有遇到使用 Detours 劫持函数的问题...当我试图劫持类方法时(在我的例子中是 IHTMLDocument2::write from mshtml.dll)我遇到了无穷无尽的问
我通过函数偏移量在外部进程中 Hook 函数。到目前为止,这对于我 Hook 的函数来说效果很好——但是我发现一个“debugLog(char...)”函数仍然存在于二进制文件中但不进行任何打印——它
detours包声称支持 64 位 但我没有看到编译 64 位 二进制文件的方法: Detouring 32-bit and 64-bit Processes 使用nmake all 只编译32 位
很长一段时间我都没有遇到使用 Detours 劫持函数的问题...当我试图劫持类方法时(在我的例子中是 IHTMLDocument2::write from mshtml.dll)我遇到了无穷无尽的问
我是新来的,这是我提出的第一个问题。我希望在这里相处得很好:)对于我的问题!: 我为 x64 处理器(普通英特尔 x64)写了一个 Detouring 基础设施 主要有趣的函数如下所示: typede
我将在Visual Studio 2013或Visual Studio 2019中编译旧项目(Visual Studio 2012 Platform-v110xp)。 它使用了boost和Micros
我无法使用绕行来获得我的第一个钩子(Hook)。我正在使用 Detour 3.0。 我的代码编译得很好,我可以使用 Winject 注入(inject) DLL,但是,我应该 Hook 的函数似乎没有
我正在使用: 微软 VS 10 Detours v3.0 Express 完整的源代码DLL: #include #include ofstream prclist ; #pragma comme
我是一名优秀的程序员,十分优秀!