1 Star 1 Fork 1

yangand/winspool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
CAnyHook.cpp 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
yangan 提交于 2020-04-19 23:24 . 添加项目文件。
#include "stdafx.h"
#include <Windows.h>
#include "CAnyHook.h"
CAnyHook::CAnyHook()
{
memset(oldData, 0, 7);
memset(newData, 0, 7);
isHooked = false;
}
CAnyHook::CAnyHook(void* hookAddr, void* hookTarget)
{
CAnyHook();
hook(hookAddr, hookTarget);
}
void CAnyHook::hook(void* hookAddr, void* hookTarget)
{
if (!isHooked)
{
mHookAddr = hookAddr;
mTargetaddr = hookTarget;
writeData(oldData, hookAddr, 7);
newData[0] = 0x8b;
newData[1] = 0xff;
newData[2] = 0xe9;
*(DWORD*)& newData[3] = (DWORD)hookTarget - (DWORD)hookAddr - 5 - 2;
writeData(hookAddr, newData, 7);
isHooked = true;
}
}
void CAnyHook::writeData(void* patchAddr, void* patchData, DWORD patchSize)
{
DWORD oldProtect = 0;
VirtualProtect(patchAddr, patchSize, PAGE_EXECUTE_READWRITE, &oldProtect);
memcpy(patchAddr, patchData, patchSize);
}
void CAnyHook::unHook()
{
if(isHooked)
{
writeData(mHookAddr, oldData, 7);
isHooked = false;
}
}
void CAnyHook::reHook()
{
if(!isHooked)
{
writeData(mHookAddr, newData, 7);
isHooked = true;
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yangand/winspool.git
[email protected]:yangand/winspool.git
yangand
winspool
winspool
master

搜索帮助