37 lines
874 B
C++
37 lines
874 B
C++
#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);
|
|
|
|
//写入我们构造的BYTE 实现 hook
|
|
memcpy(reinterpret_cast<void*>(m_original_address), m_self_byte, Byte_Length);
|
|
|
|
//恢复内存属性
|
|
Motify_memory_attributes(m_original_address, attributes);
|
|
|
|
}
|
|
|
|
void inlinehook::Restore_address()
|
|
{
|
|
DWORD attributes = Motify_memory_attributes(m_original_address);
|
|
|
|
//写入原始的BYTE 实现 hook
|
|
memcpy(reinterpret_cast<void*>(m_original_address), m_original_byte, Byte_Length);
|
|
|
|
//恢复内存属性
|
|
Motify_memory_attributes(m_original_address, attributes);
|
|
}
|