From 629d608d4ffed8863e83a586a2248ab0a4f913fa Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Fri, 12 Feb 2021 15:02:31 +0300 Subject: [PATCH] Patch engine: add bd32, bd64 and utf8 patch types bd32 is the same as be32 with a hint it's not executable. utf8 is NOT null-terminated string, null can be added manually. --- Utilities/bin_patch.cpp | 22 ++++++++++++++++++++++ Utilities/bin_patch.h | 3 +++ 2 files changed, 25 insertions(+) diff --git a/Utilities/bin_patch.cpp b/Utilities/bin_patch.cpp index b2b464081c..9770a4edda 100644 --- a/Utilities/bin_patch.cpp +++ b/Utilities/bin_patch.cpp @@ -44,9 +44,12 @@ void fmt_class_string::format(std::string& out, u64 arg) case patch_type::bef64: return "bef64"; case patch_type::be16: return "be16"; case patch_type::be32: return "be32"; + case patch_type::bd32: return "bd32"; case patch_type::be64: return "be64"; + case patch_type::bd64: return "bd64"; case patch_type::lef32: return "lef32"; case patch_type::lef64: return "lef64"; + case patch_type::utf8: return "utf8"; } return unknown; @@ -427,6 +430,10 @@ bool patch_engine::add_patch_data(YAML::Node node, patch_info& info, u32 modifie switch (p_data.type) { + case patch_type::utf8: + { + break; + } case patch_type::bef32: case patch_type::lef32: case patch_type::bef64: @@ -568,6 +575,11 @@ static std::basic_string apply_modification(const patch_engine::patch_info& *reinterpret_cast*>(ptr) = static_cast(p.value.long_value); break; } + case patch_type::bd32: + { + *reinterpret_cast*>(ptr) = static_cast(p.value.long_value); + break; + } case patch_type::be32: { *reinterpret_cast*>(ptr) = static_cast(p.value.long_value); @@ -579,6 +591,11 @@ static std::basic_string apply_modification(const patch_engine::patch_info& *reinterpret_cast*>(ptr) = std::bit_cast(static_cast(p.value.double_value)); break; } + case patch_type::bd64: + { + *reinterpret_cast*>(ptr) = static_cast(p.value.long_value); + break; + } case patch_type::be64: { *reinterpret_cast*>(ptr) = static_cast(p.value.long_value); @@ -597,6 +614,11 @@ static std::basic_string apply_modification(const patch_engine::patch_info& *reinterpret_cast*>(ptr) = std::bit_cast(p.value.double_value); break; } + case patch_type::utf8: + { + std::memcpy(ptr, p.original_value.data(), p.original_value.size()); + break; + } } // Possibly an executable instruction diff --git a/Utilities/bin_patch.h b/Utilities/bin_patch.h index b7a39d8ee3..bd522de0ce 100644 --- a/Utilities/bin_patch.h +++ b/Utilities/bin_patch.h @@ -34,9 +34,12 @@ enum class patch_type lef64, be16, be32, + bd32, // be32 with data hint (non-code) be64, + bd64, // be64 with data hint (non-code) bef32, bef64, + utf8, // Text of string (not null-terminated automatically) }; class patch_engine