Skip to content

Commit

Permalink
Remove opcode_length and make_raw_hook from public API
Browse files Browse the repository at this point in the history
  • Loading branch information
Smertig committed Dec 1, 2022
1 parent 354e98c commit eb3d5df
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 35 deletions.
2 changes: 0 additions & 2 deletions include/rcmp/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::byte[]> allocate_code(std::size_t count);

} // namespace rcmp
15 changes: 1 addition & 14 deletions source/detail/arch/arm64/impl.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
#include <rcmp/memory.hpp>
#include <rcmp/codegen.hpp>

// returns relocated original address
rcmp::address_t rcmp::make_raw_hook(rcmp::address_t original_function, rcmp::address_t wrapper_function) {
static_cast<void>(original_function);
static_cast<void>(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<void>(address);
throw rcmp::error("rcmp::opcode_length is not implemented yet");
}
/* Nothing here */
4 changes: 2 additions & 2 deletions source/detail/arch/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 9 additions & 3 deletions source/detail/arch/x86-64-common/impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 uint8_t>();
const auto bytes_to = to.as_ptr<uint8_t>();

Expand Down Expand Up @@ -236,7 +238,7 @@ std::unique_ptr<std::byte[]> 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;
}();
Expand All @@ -250,7 +252,7 @@ std::unique_ptr<std::byte[]> 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);
Expand Down Expand Up @@ -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<std::size_t>::max)(), RCMP_GET_ARCH() == RCMP_ARCH_X86 ? NMD_X86_MODE_32 : NMD_X86_MODE_64);
}
7 changes: 0 additions & 7 deletions source/detail/arch/x86-64/impl.cpp

This file was deleted.

7 changes: 0 additions & 7 deletions source/detail/arch/x86/impl.cpp

This file was deleted.

0 comments on commit eb3d5df

Please sign in to comment.