diff --git a/include/rcmp/memory.hpp b/include/rcmp/memory.hpp index aeeaa56..5a8b8dc 100644 --- a/include/rcmp/memory.hpp +++ b/include/rcmp/memory.hpp @@ -23,8 +23,6 @@ void set_opcode(rcmp::address_t where, Range&& bytes) { std::memcpy(where.as_ptr(), std::data(bytes), std::size(bytes)); } -std::size_t opcode_length(rcmp::address_t address); - std::unique_ptr allocate_code(std::size_t count); } // namespace rcmp diff --git a/source/detail/arch/arm64/impl.cpp b/source/detail/arch/arm64/impl.cpp index 0e490d7..3b44754 100644 --- a/source/detail/arch/arm64/impl.cpp +++ b/source/detail/arch/arm64/impl.cpp @@ -1,14 +1 @@ -#include -#include - -// returns relocated original address -rcmp::address_t rcmp::make_raw_hook(rcmp::address_t original_function, rcmp::address_t wrapper_function) { - static_cast(original_function); - static_cast(wrapper_function); - throw rcmp::error("rcmp::make_raw_hook is not implemented yet"); -} - -std::size_t rcmp::opcode_length(rcmp::address_t address) { - static_cast(address); - throw rcmp::error("rcmp::opcode_length is not implemented yet"); -} +/* Nothing here */ diff --git a/source/detail/arch/impl.cpp b/source/detail/arch/impl.cpp index fd2a87e..81139e9 100644 --- a/source/detail/arch/impl.cpp +++ b/source/detail/arch/impl.cpp @@ -2,10 +2,10 @@ #if RCMP_GET_ARCH() == RCMP_ARCH_X86 static_assert(sizeof(void*) == 4); - #include "x86/impl.cpp" + #include "x86-64-common/impl.cxx" #elif RCMP_GET_ARCH() == RCMP_ARCH_X86_64 static_assert(sizeof(void*) == 8); - #include "x86-64/impl.cpp" + #include "x86-64-common/impl.cxx" #elif RCMP_GET_ARCH() == RCMP_ARCH_ARM64 static_assert(sizeof(void*) == 8); #include "arm64/impl.cpp" diff --git a/source/detail/arch/x86-64-common/impl.cxx b/source/detail/arch/x86-64-common/impl.cxx index 124ddd7..ffcf512 100644 --- a/source/detail/arch/x86-64-common/impl.cxx +++ b/source/detail/arch/x86-64-common/impl.cxx @@ -9,6 +9,8 @@ static_assert(RCMP_GET_ARCH() == RCMP_ARCH_X86 || RCMP_GET_ARCH() == RCMP_ARCH_X86_64); +static std::size_t opcode_length(rcmp::address_t address); + namespace { std::string hex_dump(rcmp::address_t address, std::size_t count) { @@ -155,7 +157,7 @@ std::size_t relocate_opcode(rcmp::address_t from, rcmp::address_t to) { to = &dummy; } - const auto cmd_len = rcmp::opcode_length(from); + const auto cmd_len = opcode_length(from); const auto bytes_from = from.as_ptr(); const auto bytes_to = to.as_ptr(); @@ -236,7 +238,7 @@ std::unique_ptr relocate_function(rcmp::address_t address, std::siz while (from_it < address + bytes) { out_size += relocate_opcode(from_it, nullptr); - from_it += rcmp::opcode_length(from_it); + from_it += opcode_length(from_it); } return out_size; }(); @@ -250,7 +252,7 @@ std::unique_ptr relocate_function(rcmp::address_t address, std::siz while (from_it < address + bytes) { out_it += relocate_opcode(from_it, out_it); - from_it += rcmp::opcode_length(from_it); + from_it += opcode_length(from_it); } rcmp::unprotect_memory(address, from_it - address); @@ -298,3 +300,7 @@ rcmp::address_t rcmp::detail::make_x86_x86_64_raw_hook(rcmp::address_t original_ #elif RCMP_GET_COMPILER() == RCMP_COMPILER_MSVC #pragma warning(pop) #endif + +std::size_t opcode_length(rcmp::address_t address) { + return nmd_x86_ldisasm(address.as_ptr(), (std::numeric_limits::max)(), RCMP_GET_ARCH() == RCMP_ARCH_X86 ? NMD_X86_MODE_32 : NMD_X86_MODE_64); +} diff --git a/source/detail/arch/x86-64/impl.cpp b/source/detail/arch/x86-64/impl.cpp deleted file mode 100644 index 3fb39bb..0000000 --- a/source/detail/arch/x86-64/impl.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "../x86-64-common/impl.cxx" - -#include - -std::size_t rcmp::opcode_length(rcmp::address_t address) { - return nmd_x86_ldisasm(address.as_ptr(), (std::numeric_limits::max)(), NMD_X86_MODE_64); -} diff --git a/source/detail/arch/x86/impl.cpp b/source/detail/arch/x86/impl.cpp deleted file mode 100644 index 5732be2..0000000 --- a/source/detail/arch/x86/impl.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "../x86-64-common/impl.cxx" - -#include - -std::size_t rcmp::opcode_length(rcmp::address_t address) { - return nmd_x86_ldisasm(address.as_ptr(), (std::numeric_limits::max)(), NMD_X86_MODE_32); -}