DNF_DLL/test/inlinehook.cpp

37 lines
884 B
C++
Raw Normal View History

2022-03-07 13:50:29 +08:00
#include "pch.h"
#include "inlinehook.h"
#include <Windows.h>
DWORD inlinehook::Motify_memory_attributes(int address, DWORD attributes)
{
DWORD Old_attributes;
VirtualProtect(reinterpret_cast<void*>(address), Byte_Length, attributes, &Old_attributes);
return Old_attributes;
}
void inlinehook::Motify_address()
{
DWORD attributes = Motify_memory_attributes(m_original_address);
//д<><D0B4><EFBFBD><EFBFBD><EFBFBD>ǹ<EFBFBD><C7B9><EFBFBD><EFBFBD><EFBFBD>BYTE ʵ<><CAB5> hook
memcpy(reinterpret_cast<void*>(m_original_address), m_self_byte, Byte_Length);
//<2F>ָ<EFBFBD><D6B8>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>
Motify_memory_attributes(m_original_address, attributes);
}
void inlinehook::Restore_address()
{
DWORD attributes = Motify_memory_attributes(m_original_address);
//д<><D0B4>ԭʼ<D4AD><CABC>BYTE ʵ<><CAB5> hook
memcpy(reinterpret_cast<void*>(m_original_address), m_original_byte, Byte_Length);
//<2F>ָ<EFBFBD><D6B8>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>
Motify_memory_attributes(m_original_address, attributes);
}