我正在学习为 Windows API 编写钩子,为了练习,我正在为 pDeleteFileA 函数编写一个钩子。当函数被调用时,在删除文件之前,我想检查文件名是否为“testfile.txt”,如果是,那么将弹出一条消息而不是删除它,如果它调用了其他内容,则继续删除文件。
我已经写了一些代码并且代码编译没有任何错误但是当我尝试删除'testfile.txt'时它只是被删除了。也许有人可以给我一个提示,我做错了什么或我没有做什么?
到目前为止,这是我的代码:
#include <Windows.h>
struct hook_t{// a datatype to store information about our hook
bool isHooked = false;
void* FunctionAddress = operator new(100);
void* HookAddress = operator new(100);
char Jmp[6] = { 0 };
char OriginalBytes[6] = {0};
void* OriginalFunction = operator new(100);
};
namespace hook {
bool InitializeHook(hook_t* Hook, char* Module, char* Function, void* HookFunction) {
HMODULE hModule;
DWORD OrigFunc, FuncAddr;
byte opcodes[] = {0x90, 0x90, 0x90, 0x90, 0x90, 0xe9, 0x00, 0x00, 0x00, …Run Code Online (Sandbox Code Playgroud)