Skip to content

Commit

Permalink
Remove generic_hook_function overload that accepts compile-time add…
Browse files Browse the repository at this point in the history
…ress (it should be injected directly in `Policy` as a `Tag` to provide state uniqueness)
  • Loading branch information
Smertig committed Mar 20, 2023
1 parent b5236c2 commit 8ee2d8b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
11 changes: 0 additions & 11 deletions include/rcmp/codegen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@ void generic_hook_function(rcmp::address_t original_address, Hook&& hook) {
>::template install_hook<Policy>(original_address, std::forward<Hook>(hook));
}

// TODO: remove this overload
template <template <class> class Policy, auto Address, class Signature, class Hook>
void generic_hook_function(Hook&& hook) {
static_assert(std::is_constructible_v<rcmp::address_t, decltype(Address)>);

return rcmp::generic_hook_function<
Policy,
Signature
>(Address, std::forward<Hook>(hook));
}

} // namespace rcmp

#include "detail/hook_policy/prolog_policy.hpp"
Expand Down
2 changes: 1 addition & 1 deletion include/rcmp/detail/hook_policy/indirect_policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void hook_indirect_function(F&& hook) {
detail::HookIndirectPolicy,
std::integral_constant<decltype(IndirectFunctionAddress), IndirectFunctionAddress>
>;
rcmp::generic_hook_function<wrapped_policy_t::Policy, IndirectFunctionAddress, Signature>(std::forward<F>(hook));
rcmp::generic_hook_function<wrapped_policy_t::template Policy, Signature>(IndirectFunctionAddress, std::forward<F>(hook));
}

template <class Tag, class Signature, class F>
Expand Down
2 changes: 1 addition & 1 deletion include/rcmp/detail/hook_policy/prolog_policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void hook_function(F&& hook) {
detail::HookPrologPolicy,
std::integral_constant<decltype(FunctionAddress), FunctionAddress>
>;
rcmp::generic_hook_function<wrapped_policy_t::template Policy, FunctionAddress, Signature>(std::forward<F>(hook));
rcmp::generic_hook_function<wrapped_policy_t::template Policy, Signature>(FunctionAddress, std::forward<F>(hook));
}

template <auto Function, class F>
Expand Down
10 changes: 10 additions & 0 deletions test/test_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,13 @@ TEST_CASE("hook with different tags") {
rcmp::hook_function<class Tag2, decltype(f4)>(rcmp::bit_cast<const void*>(&f4), l);
CHECK(f4(42) == 44);
}

TEST_CASE("compile-time addresses") {
if ([[maybe_unused]] auto always_true = []{ return true; }()) {
return;
}

// Just to check compilation, should not be called
rcmp::hook_indirect_function<0x0, void()>([](auto) {});
rcmp::hook_function<0x0, void()>([](auto) {});
}

0 comments on commit 8ee2d8b

Please sign in to comment.