急!求教Hook文件操作的问题!
这是小弟按照detours帮助文档写的截获系统DeleteFile操作的代码
在另外一个程序里LoadLibrary()和FreeLibrary()
编译,链接都正常,并且Attach和Detach都成功,但就是无法截获系统的DeleteFile操作,删除文件就和正常一样
请问是什么原因呢?
#include <windows.h>#include <detours.h>BOOL (WINAPI * SysDeleteFileA)(LPCTSTR lpFileName)= DeleteFile;BOOL WINAPI MyHookDeleteFileA(LPCTSTR lpFileName);//如果不注释掉编译总显示error C2440: 'initializing' : cannot convert from '' to 'int (__stdcall *)(const char //*)'的错误,不知为什么?谁能解一下?//BOOL (WINAPI * SysDeleteFileW)(LPCTSTR lpFileName)= DeleteFileW;//BOOL WINAPI MyHookDeleteFileW(LPCTSTR lpFileName);__declspec(dllexport) void ExportFunc(void){}BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved){ switch(fdwReason) { case DLL_PROCESS_ATTACH: DetourTransactionBegin(); DetourUpdateThread(GetCurrentThread()); DetourAttach(&(PVOID&)SysDeleteFileA,MyHookDeleteFileA); if(DetourTransactionCommit()==NO_ERROR) { MessageBox(NULL,"Attach Successfully!","Successful",MB_OK); } // DetourTransactionBegin(); // DetourUpdateThread(GetCurrentThread()); // DetourAttach(&(PVOID&)SysDeleteFileW,MyHookDeleteFileW); break; case DLL_PROCESS_DETACH: DetourTransactionBegin(); DetourUpdateThread(GetCurrentThread()); DetourDetach(&(PVOID&)SysDeleteFileA, MyHookDeleteFileA); if(DetourTransactionCommit()==NO_ERROR) { MessageBox(NULL,"Detach Successfully!","Successful",MB_OK); } break; } return true;}BOOL WINAPI MyHookDeleteFileA(LPCTSTR lpFileName){ MessageBox(NULL,"You Can Not Delete This File!","ERROR",MB_OK); return true;}/*BOOL WINAPI MyHookDeleteFileW(LPCTSTR lpFileName){ return true;}*/