diff --git a/lsplant/src/main/jni/include/utils/hook_helper.hpp b/lsplant/src/main/jni/include/utils/hook_helper.hpp index 542e4f449..05e94d8ae 100644 --- a/lsplant/src/main/jni/include/utils/hook_helper.hpp +++ b/lsplant/src/main/jni/include/utils/hook_helper.hpp @@ -1,8 +1,9 @@ #pragma once -#include #include +#include + #include "lsplant.hpp" #include "type_traits.hpp" @@ -12,15 +13,12 @@ #define LP_SELECT(lp32, lp64) lp32 #endif -#define CONCATENATE(a, b) a##b - #define CREATE_HOOK_STUB_ENTRY(SYM, RET, FUNC, PARAMS, DEF) \ - inline static struct : public lsplant::Hooker{ \ + inline static struct : public lsplant::Hooker{ \ inline static RET replace PARAMS DEF} FUNC #define CREATE_MEM_HOOK_STUB_ENTRY(SYM, RET, FUNC, PARAMS, DEF) \ - inline static struct : public lsplant::MemHooker{ \ + inline static struct : public lsplant::MemHooker{ \ inline static RET replace PARAMS DEF} FUNC #define RETRIEVE_FUNC_SYMBOL(name, ...) \ @@ -46,38 +44,12 @@ namespace lsplant { using HookHandler = InitInfo; -template -struct tstring : public std::integer_sequence { - inline constexpr static const char *c_str() { return str_; } - - inline constexpr operator std::string_view() const { return {c_str(), sizeof...(chars)}; } - -private: - inline static constexpr char str_[]{chars..., '\0'}; +template +struct FixedString { + consteval inline FixedString(const char (&str)[N]) { std::copy_n(str, N, data); } + char data[N] = {}; }; -template -inline constexpr tstring operator""_tstr() { - return {}; -} - -template -inline constexpr tstring operator+(const tstring &, const tstring &) { - return {}; -} - -template -inline constexpr auto operator+(const std::string &a, const tstring &) { - char b[]{as..., '\0'}; - return a + b; -} - -template -inline constexpr auto operator+(const tstring &, const std::string &b) { - char a[]{as..., '\0'}; - return a + b; -} - inline void *Dlsym(const HookHandler &handle, const char *name, bool match_prefix = false) { if (auto match = handle.art_symbol_resolver(name); match) { return match; @@ -88,8 +60,8 @@ inline void *Dlsym(const HookHandler &handle, const char *name, bool match_prefi } template -requires(std::is_same_v || - std::is_same_v) inline static auto memfun_cast(Return (*func)(T *, Args...)) { + requires(std::is_same_v || std::is_same_v) +inline static auto memfun_cast(Return (*func)(T *, Args...)) { union { Return (Class::*f)(Args...); @@ -143,22 +115,22 @@ MemberFunction(Return (*f)(This *, Args...)) -> MemberFunction MemberFunction(Return (This::*f)(Args...)) -> MemberFunction; -template +template struct Hooker; -template -struct Hooker> { +template +struct Hooker { inline static Ret (*backup)(Args...) = nullptr; - inline static constexpr std::string_view sym = tstring{}; + inline static constexpr std::string_view sym = Sym.data; }; -template +template struct MemHooker; -template -struct MemHooker> { +template +struct MemHooker { inline static MemberFunction backup; - inline static constexpr std::string_view sym = tstring{}; + inline static constexpr std::string_view sym = Sym.data; }; template