Dem*_*urg 5 windows hook winapi setwindowshookex
有没有一种简单的方法来挂钩我的代码执行的进程的注册表访问?我知道SetWindowsHookEx和朋友,但它太复杂了......我仍然希望有一种像LD_PRELOAD上一样简单的方法Unix......
在这里阅读 DLL 注入的理论: http: //en.wikipedia.org/wiki/DLL_injection
不过,我将在这里为您提供 DLL 注入片段:http://www.dreamincode.net/code/snippet407.htm
一旦您进入外部应用程序的内存中,在注入时,执行这些类型的操作就非常容易,您也可以成为该过程的一部分。
有一种叫做绕行的东西,我相信这就是您正在寻找的东西,它只是挂钩一个函数,当该进程调用它时,它会执行您自己的函数。(为确保它不会崩溃,请在函数末尾调用该函数)
因此,如果您想通过 CreateRegKeyEx 编写自己的函数
(http://msdn.microsoft.com/en-us/library/ms724844%28v=vs.85%29.aspx)
它可能看起来像这样:
LONG WINAPI myRegCreateKeyEx(HKEY hKey, LPCTSTR lpSubKey, DWORD Reserved, LPTSTR lpClass, DWORD dwOptions, REGSAM samDesired, LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition)
{
//check for suspicious keys being made via the parameters
RegCreateKeyEx(hKey, lpSubKey, Reserved, lpClass, dwOptions, samDesired, lpSecurityAttributes, phkResult, lpdwDisposition);
}
Run Code Online (Sandbox Code Playgroud)
您可以在这里获得一个编写良好的绕道库,名为 DetourXS: http: //www.gamedeception.net/threads/10649-DetourXS
以下是他如何使用它建立绕行路线的示例代码:
#include <detourxs.h>
typedef DWORD (WINAPI* tGetTickCount)(void);
tGetTickCount oGetTickCount;
DWORD WINAPI hGetTickCount(void)
{
printf("GetTickCount hooked!");
return oGetTickCount();
}
// To create the detour
oGetTickCount = (tGetTickCount) DetourCreate("kernel32.dll", "GetTickCount", hGetTickCount, DETOUR_TYPE_JMP);
// ...Or an address
oGetTickCount = (tGetTickCount) DetourCreate(0x00000000, hGetTickCount, DETOUR_TYPE_JMP);
// ...You can also specify the detour len
oGetTickCount = (tGetTickCount) DetourCreate(0x00000000, hGetTickCount, DETOUR_TYPE_JMP, 5);
// To remove the detour
DetourRemove(oGetTickCount);
Run Code Online (Sandbox Code Playgroud)
如果您看不出来,该片段正在挂钩 GetTickCount(),并且每当调用该函数时,他都会写“GetTickCount hooked!” -- 然后他按照预期执行 GetTickCount 函数。
抱歉,信息如此分散,但我希望这会有所帮助。:) -- 我意识到这是一个老问题。--
SetWindowsHookEx 根本没有帮助 - 它提供了不同的功能。
检查https://web.archive.org/web/20080212040635/http://www.codeproject.com/KB/system/RegMon.aspx是否有帮助。SysInternals 的 RegMon 使用内核模式驱动程序,这是非常复杂的方式。
更新:我们公司提供 CallbackRegistry 产品,可让您轻松跟踪注册表操作。顺便说一句,我们根据要求提供免费的非商业许可证(需根据具体情况批准)。