From bba720f0595313c8131bf9bdd99f3dbc5e25ede4 Mon Sep 17 00:00:00 2001 From: Quentin <837334+xiaoxiao921@users.noreply.github.com> Date: Tue, 23 Jul 2024 18:19:39 +0200 Subject: [PATCH] fix crash on reinject (#3409) Co-authored-by: gir489 <100792176+gir489returns@users.noreply.github.com> --- src/memory/byte_patch.cpp | 16 ++++++++++------ src/memory/byte_patch.hpp | 1 - 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/memory/byte_patch.cpp b/src/memory/byte_patch.cpp index 158281c4..7e3ac5a8 100644 --- a/src/memory/byte_patch.cpp +++ b/src/memory/byte_patch.cpp @@ -9,20 +9,24 @@ namespace memory void byte_patch::apply() const { - DWORD temp; + DWORD old_protect; + VirtualProtect(m_address, m_size, PAGE_EXECUTE_READWRITE, (PDWORD)&old_protect); - 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); + + DWORD unused; + VirtualProtect(m_address, m_size, old_protect, &unused); } void byte_patch::restore() const { - DWORD temp; + DWORD old_protect; + VirtualProtect(m_address, m_size, PAGE_EXECUTE_READWRITE, (PDWORD)&old_protect); - 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); + + DWORD unused; + VirtualProtect(m_address, m_size, old_protect, &unused); } void byte_patch::remove() const diff --git a/src/memory/byte_patch.hpp b/src/memory/byte_patch.hpp index 8565d0f3..861abc4f 100644 --- a/src/memory/byte_patch.hpp +++ b/src/memory/byte_patch.hpp @@ -67,7 +67,6 @@ namespace memory std::unique_ptr m_value; std::unique_ptr m_original_bytes; std::size_t m_size; - DWORD m_old_protect; friend bool operator==(const std::unique_ptr& a, const byte_patch* b); };