Hook CreateFileW
我想知道进程打开/访问的文件是什么。我可以知道该怎么做吗?我尝试使用免费的挂钩API Deviare来帮助我,但无法从其AIP库或论坛中找到任何有用的信息。
我只知道我必须挂接到kernel32.dll和createFileW,而且我不确定如何继续。
请帮助我。提前致谢。
是的。您必须在kernel32.dll中挂接功能CreateFileA / W来监视acces。您想将这些API挂接到您自己的进程中还是其他进程中?
如果要在自己的进程中挂接函数,可以使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | void *DetourFunc(BYTE *src, const BYTE *dst, const int len) { BYTE *jmp = (BYTE*)malloc(5+len); DWORD dwback; VirtualProtect(src,len,PAGE_READWRITE,&dwback); memcpy(jmp,src,len); jmp += len; jmp[0] = 0xE9; *(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5; src[0] = 0xE9; *(DWORD*)(src+1) = (DWORD)(dst - src) - 5; VirtualProtect(src,len,dwback,&dwback); return (jmp-len); } |
为此。这些函数绕过函数src(例如MessageBoxA())到函数dst。 len可以使用5。它将返回指向原始函数的函数指针。
调用示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | typedef int (WINAPI *__MessageBox)( __in_opt HWND hWnd, __in_opt LPCTSTR lpText, __in_opt LPCTSTR lpCaption, __in UINT uType ); __MessageBox _MessageBox; int cMessageBox(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType) { //here you can change anything you want return _MessageBox(hWnd,lpText,lpCaption,uType); } int main(void) { BYTE *hookfunc = (BYTE*)GetProcAddress(LoadLibrary("user32.dll"),"MessageBoxA"); _MessageBox = (__MessageBox)DetourFunc(hookfunc,(BYTE*)cMessageBox,5); return 0; } |
那是一个用户模式钩子。如果要在系统范围内执行此操作,请使用设备驱动程序。这是有关此的教程。 http://www.codeproject.com/KB/system/driverdev.aspx
如果在多字节模式下使用VC编译,请执行;)。
如果要挂接其他进程,则只需google DLL-Injection;)。