2022-03-07 13:50:29 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
2022-03-08 12:57:35 +08:00
|
|
|
|
constexpr int Byte_Length = 6;
|
2022-03-07 13:50:29 +08:00
|
|
|
|
|
|
|
|
|
|
class inlinehook
|
|
|
|
|
|
{
|
|
|
|
|
|
private:
|
|
|
|
|
|
using uchar = unsigned char;
|
|
|
|
|
|
|
|
|
|
|
|
//ԭʼ<D4AD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD>ָ<EFBFBD><D6B8>
|
|
|
|
|
|
uchar m_original_byte[Byte_Length];
|
|
|
|
|
|
//<2F><><EFBFBD>ǹ<EFBFBD><C7B9><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD>ָ<EFBFBD><D6B8>
|
|
|
|
|
|
uchar m_self_byte[Byte_Length];
|
|
|
|
|
|
|
|
|
|
|
|
//ԭʼ<D4AD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
|
int m_original_address;
|
|
|
|
|
|
//<2F><><EFBFBD>Ǻ<EFBFBD><C7BA><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
|
int m_self_address;
|
|
|
|
|
|
|
|
|
|
|
|
DWORD Motify_memory_attributes(int address, DWORD attributes = PAGE_EXECUTE_READWRITE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
inlinehook(int original_address, int self_address):m_original_address(original_address), m_self_address(self_address)
|
|
|
|
|
|
{
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>jmp
|
|
|
|
|
|
m_self_byte[0] = '\xe9';
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB>
|
|
|
|
|
|
int offset = self_address - (original_address + Byte_Length);
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD>ǵĺ<C7B5><C4BA><EFBFBD>BYTE
|
2022-03-08 12:57:35 +08:00
|
|
|
|
memcpy(&m_self_byte[1], &offset, Byte_Length - 2);
|
2022-03-07 13:50:29 +08:00
|
|
|
|
|
2022-03-08 12:57:35 +08:00
|
|
|
|
m_self_byte[5] = '\x90';
|
2022-03-07 13:50:29 +08:00
|
|
|
|
//<2F><EFBFBD><DEB8>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
DWORD attributes = Motify_memory_attributes(original_address);
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ԭʼ<D4AD>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>BYTE
|
|
|
|
|
|
memcpy(&m_original_byte, reinterpret_cast<void*>(original_address), Byte_Length);
|
|
|
|
|
|
|
|
|
|
|
|
//<2F>ָ<EFBFBD><D6B8>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
Motify_memory_attributes(original_address, attributes);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F>ĵ<DEB8>ַ
|
|
|
|
|
|
void Motify_address();
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><>ԭ<EFBFBD><D4AD>ַ
|
|
|
|
|
|
void Restore_address();
|
|
|
|
|
|
};
|
|
|
|
|
|
|