fix(byte_patch): sometimes the page protections get modified between apply
and restore
: make sure the protections are fine for us to memcpy. (#1831)
* feat(BytePatch): add is_active member function * fix(byte_patch): sometimes the page protections get modified between the apply and restore of the byte_patch, make sure the protections are fine for us to memcpy Co-authored-by: Quentin E. / iDeath <xiaoxiao921@hotmail.fr>
This commit is contained in:
parent
16e8e571f0
commit
0289576677
@ -8,23 +8,19 @@ namespace big
|
||||
{
|
||||
using bool_command::bool_command;
|
||||
|
||||
memory::byte_patch* m_window_hook_patch;
|
||||
|
||||
virtual void refresh() override
|
||||
{
|
||||
static auto patch = (m_window_hook_patch = memory::byte_patch::make(g_pointers->m_gta.m_window_hook.as<void*>(), std::to_array({0xC3, 0x90, 0x90, 0x90}))
|
||||
.get(),
|
||||
true);
|
||||
static auto& window_hook_patch = memory::byte_patch::make(g_pointers->m_gta.m_window_hook.as<void*>(), std::to_array({0xC3, 0x90, 0x90, 0x90}));
|
||||
|
||||
if (m_toggle)
|
||||
{
|
||||
m_window_hook_patch->apply();
|
||||
window_hook_patch->apply();
|
||||
UnhookWindowsHookEx(*g_pointers->m_gta.m_window_hook.add(45).rip().as<HHOOK*>());
|
||||
}
|
||||
else
|
||||
{
|
||||
SetWindowsHookExA(13, g_pointers->m_gta.m_window_hook.add(18).rip().as<HOOKPROC>(), GetModuleHandleA("GTA5.exe"), 0);
|
||||
m_window_hook_patch->restore();
|
||||
window_hook_patch->restore();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -9,15 +9,20 @@ namespace memory
|
||||
|
||||
void byte_patch::apply() const
|
||||
{
|
||||
DWORD temp;
|
||||
|
||||
VirtualProtect(m_address, m_size, PAGE_EXECUTE_READWRITE, (PDWORD)&m_old_protect);
|
||||
memcpy(m_address, m_value.get(), m_size);
|
||||
VirtualProtect(m_address, m_size, m_old_protect, &temp);
|
||||
}
|
||||
|
||||
void byte_patch::restore() const
|
||||
{
|
||||
DWORD temp;
|
||||
VirtualProtect(m_address, m_size, m_old_protect, &temp);
|
||||
|
||||
VirtualProtect(m_address, m_size, PAGE_EXECUTE_READWRITE, (PDWORD)&temp);
|
||||
memcpy(m_address, m_original_bytes.get(), m_size);
|
||||
VirtualProtect(m_address, m_size, m_old_protect, &temp);
|
||||
}
|
||||
|
||||
void byte_patch::remove() const
|
||||
|
@ -12,7 +12,6 @@ namespace memory
|
||||
virtual ~byte_patch();
|
||||
|
||||
void apply() const;
|
||||
|
||||
void restore() const;
|
||||
|
||||
void remove() const;
|
||||
|
Reference in New Issue
Block a user