diff --git a/include/REL/Relocation.h b/include/REL/Relocation.h index 9babdb4c..af3642dc 100644 --- a/include/REL/Relocation.h +++ b/include/REL/Relocation.h @@ -278,6 +278,39 @@ namespace REL return stl::unrestricted_cast(_address); } + template + void replace_func(const std::size_t a_count, const std::uintptr_t a_dst) + requires(std::same_as) + { +#pragma pack(push, 1) + struct Assembly + { + std::uint8_t jmp; + std::uint8_t modrm; + std::int32_t disp; + std::uint64_t addr; + }; + static_assert(sizeof(Assembly) == 0xE); +#pragma pack(pop) + + Assembly assembly{ + .jmp = static_cast(0xFF), + .modrm = static_cast(0x25), + .disp = static_cast(0), + .addr = static_cast(a_dst), + }; + + safe_fill(address() + O, INT3, a_count); + safe_write(address() + O, &assembly, sizeof(assembly)); + } + + template + void replace_func(const std::size_t a_count, const F a_dst) + requires(std::same_as) + { + replace_func(a_count, stl::unrestricted_cast(a_dst)); + } + void write(const void* a_src, std::size_t a_count) requires(std::same_as) { @@ -338,18 +371,6 @@ namespace REL safe_fill(address(), a_value, a_count); } -#ifdef SFSE_SUPPORT_XBYAK - void write_func(const std::size_t a_count, const std::uintptr_t a_dst) - requires(std::same_as); - - template - void write_func(const std::size_t a_count, const F a_dst) - requires(std::same_as) - { - write_func(a_count, stl::unrestricted_cast(a_dst)); - } -#endif - constexpr std::uintptr_t write_vfunc(const std::size_t a_idx, const std::uintptr_t a_newFunc) requires(std::same_as) { diff --git a/src/REL/Relocation.cpp b/src/REL/Relocation.cpp deleted file mode 100644 index beafb6e5..00000000 --- a/src/REL/Relocation.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "REL/Relocation.h" - -#ifdef SFSE_SUPPORT_XBYAK -# include - -namespace REL -{ - struct write_func_impl : Xbyak::CodeGenerator - { - write_func_impl(std::uintptr_t a_dst) - { - Xbyak::Label dst; - jmp(ptr[rip + dst]); - L(dst); - dq(a_dst); - } - }; - - template - void Relocation::write_func(const std::size_t a_count, const std::uintptr_t a_dst) - requires(std::same_as) - { - safe_fill(address(), INT3, a_count); - auto patch = write_func_impl{ a_dst }; - patch.ready(); - assert(patch.getSize() <= a_count); - safe_write(address(), std::span{ patch.getCode(), patch.getSize() }); - } - - template void Relocation::write_func(const std::size_t, const std::uintptr_t); -} -#endif