代码拉取完成,页面将自动刷新
#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;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。