diff --git a/lsplant/src/main/jni/art/runtime/art_method.hpp b/lsplant/src/main/jni/art/runtime/art_method.hpp index ec191cf..d82258e 100644 --- a/lsplant/src/main/jni/art/runtime/art_method.hpp +++ b/lsplant/src/main/jni/art/runtime/art_method.hpp @@ -242,12 +242,12 @@ public: if (sdk_int <= __ANDROID_API_N__) { kAccCompileDontBother = 0; } - if (sdk_int == __ANDROID_API_M__) [[unlikely]] { + if (sdk_int == __ANDROID_API_M__) [[unlikely]] { if (!RETRIEVE_FUNC_SYMBOL(art_interpreter_to_compiled_code_bridge, "artInterpreterToCompiledCodeBridge")) { return false; } - interpreter_entry_point_offset = entry_point_offset - 2 * kPointerSize; + interpreter_entry_point_offset = entry_point_offset - 2 * kPointerSize; } return true; diff --git a/lsplant/src/main/jni/art/runtime/dex_file.hpp b/lsplant/src/main/jni/art/runtime/dex_file.hpp index f1f70b3..0659931 100644 --- a/lsplant/src/main/jni/art/runtime/dex_file.hpp +++ b/lsplant/src/main/jni/art/runtime/dex_file.hpp @@ -8,7 +8,7 @@ namespace lsplant::art { class DexFile { struct Header { - uint8_t magic_[8]; + [[maybe_unused]] uint8_t magic_[8]; uint32_t checksum_; // See also location_checksum_ }; CREATE_FUNC_SYMBOL_ENTRY(std::unique_ptr, OpenMemory, const uint8_t* dex_file, diff --git a/lsplant/src/main/jni/art/thread.hpp b/lsplant/src/main/jni/art/thread.hpp index 95f54fb..0d569b3 100644 --- a/lsplant/src/main/jni/art/thread.hpp +++ b/lsplant/src/main/jni/art/thread.hpp @@ -13,7 +13,7 @@ class Thread { if (DecodeJObjectSym) return DecodeJObjectSym(thiz, obj); else - return { .data=nullptr }; + return {.data = nullptr}; } CREATE_FUNC_SYMBOL_ENTRY(Thread *, CurrentFromGdb) { @@ -24,17 +24,13 @@ class Thread { } public: - static Thread *Current() { - return CurrentFromGdb(); - } + static Thread *Current() { return CurrentFromGdb(); } static bool Init(const HookHandler &handler) { - if (!RETRIEVE_MEM_FUNC_SYMBOL(DecodeJObject, - "_ZNK3art6Thread13DecodeJObjectEP8_jobject")) { + if (!RETRIEVE_MEM_FUNC_SYMBOL(DecodeJObject, "_ZNK3art6Thread13DecodeJObjectEP8_jobject")) { return false; } - if (!RETRIEVE_FUNC_SYMBOL(CurrentFromGdb, - "_ZN3art6Thread14CurrentFromGdbEv")) { + if (!RETRIEVE_FUNC_SYMBOL(CurrentFromGdb, "_ZN3art6Thread14CurrentFromGdbEv")) { return false; } return true; @@ -47,4 +43,4 @@ public: return nullptr; } }; -} +} // namespace lsplant::art diff --git a/lsplant/src/main/jni/common.hpp b/lsplant/src/main/jni/common.hpp index 4c49bda..989997c 100644 --- a/lsplant/src/main/jni/common.hpp +++ b/lsplant/src/main/jni/common.hpp @@ -1,14 +1,16 @@ #pragma once -#include -#include -#include -#include -#include #include + +#include +#include +#include +#include +#include + #include "logging.hpp" -#include "utils/hook_helper.hpp" #include "lsplant.hpp" +#include "utils/hook_helper.hpp" namespace lsplant { @@ -19,7 +21,6 @@ enum class Arch { kX8664, }; - consteval inline Arch GetArch() { #if defined(__i386__) return Arch::kX86; @@ -30,13 +31,13 @@ consteval inline Arch GetArch() { #elif defined(__aarch64__) return Arch::kArm64; #else -# error "unsupported architecture" +#error "unsupported architecture" #endif } inline static constexpr auto kArch = GetArch(); -template +template constexpr inline auto RoundUpTo(T v, size_t size) { return v + size - 1 - ((v + size - 1) & (size - 1)); } @@ -54,7 +55,7 @@ inline auto GetAndroidApiLevel() { inline static constexpr auto kPointerSize = sizeof(void *); -template +template inline T GetArtSymbol(const std::function &resolver, std::string_view symbol) requires(std::is_pointer_v) { if (auto *result = resolver(symbol); result) { @@ -66,11 +67,11 @@ inline T GetArtSymbol(const std::function &resolver, } namespace art { -class ArtMethod; -namespace dex { -class ClassDef; -} -} + class ArtMethod; + namespace dex { + class ClassDef; + } +} // namespace art namespace { // target, backup @@ -80,12 +81,15 @@ inline std::shared_mutex hooked_methods_lock_; inline std::list> jit_movements_; inline std::shared_mutex jit_movements_lock_; -inline std::unordered_map>> pending_classes_; +inline std::unordered_map< + const art::dex::ClassDef *, + std::list>> + pending_classes_; inline std::shared_mutex pending_classes_lock_; inline std::unordered_set pending_methods_; inline std::shared_mutex pending_methods_lock_; -} +} // namespace inline bool IsHooked(art::ArtMethod *art_method) { std::shared_lock lk(hooked_methods_lock_); @@ -117,9 +121,8 @@ inline void RecordJitMovement(art::ArtMethod *target, art::ArtMethod *backup) { jit_movements_.emplace_back(target, backup); } -inline void -RecordPending(const art::dex::ClassDef *class_def, art::ArtMethod *target, art::ArtMethod *hook, - art::ArtMethod *backup) { +inline void RecordPending(const art::dex::ClassDef *class_def, art::ArtMethod *target, + art::ArtMethod *hook, art::ArtMethod *backup) { { std::unique_lock lk(pending_methods_lock_); pending_methods_.emplace(target); @@ -143,7 +146,7 @@ inline void OnPending(const art::dex::ClassDef *class_def) { set = std::move(it->second); pending_classes_.erase(it); } - for (auto&[target, hook, backup]: set) { + for (auto &[target, hook, backup] : set) { { std::unique_lock mlk(pending_methods_lock_); pending_methods_.erase(target); @@ -151,4 +154,4 @@ inline void OnPending(const art::dex::ClassDef *class_def) { OnPending(target, hook, backup); } } -} +} // namespace lsplant diff --git a/lsplant/src/main/jni/include/utils/hook_helper.hpp b/lsplant/src/main/jni/include/utils/hook_helper.hpp index 2c4f06b..41a8dae 100644 --- a/lsplant/src/main/jni/include/utils/hook_helper.hpp +++ b/lsplant/src/main/jni/include/utils/hook_helper.hpp @@ -2,13 +2,13 @@ #include -#include "lsplant.hpp" #include "jni_helper.hpp" +#include "lsplant.hpp" #if defined(__LP64__) -# define LP_SELECT(lp32, lp64) lp64 +#define LP_SELECT(lp32, lp64) lp64 #else -# define LP_SELECT(lp32, lp64) lp32 +#define LP_SELECT(lp32, lp64) lp32 #endif #define CONCATENATE(a, b) a##b diff --git a/lsplant/src/main/jni/logging.hpp b/lsplant/src/main/jni/logging.hpp index 0363a15..a4404bf 100644 --- a/lsplant/src/main/jni/logging.hpp +++ b/lsplant/src/main/jni/logging.hpp @@ -3,7 +3,7 @@ #include #ifndef LOG_TAG -#define LOG_TAG "LSPlant" +#define LOG_TAG "LSPlant" #endif #ifdef LOG_DISABLED @@ -14,15 +14,23 @@ #define LOGE(...) #else #ifndef NDEBUG -#define LOGD(fmt, ...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "%s:%d#%s" ": " fmt, __FILE_NAME__, __LINE__, __PRETTY_FUNCTION__ __VA_OPT__(,) __VA_ARGS__) -#define LOGV(fmt, ...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "%s:%d#%s" ": " fmt, __FILE_NAME__, __LINE__, __PRETTY_FUNCTION__ __VA_OPT__(,) __VA_ARGS__) +#define LOGD(fmt, ...) \ + __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, \ + "%s:%d#%s" \ + ": " fmt, \ + __FILE_NAME__, __LINE__, __PRETTY_FUNCTION__ __VA_OPT__(, ) __VA_ARGS__) +#define LOGV(fmt, ...) \ + __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, \ + "%s:%d#%s" \ + ": " fmt, \ + __FILE_NAME__, __LINE__, __PRETTY_FUNCTION__ __VA_OPT__(, ) __VA_ARGS__) #else #define LOGD(...) #define LOGV(...) #endif -#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) -#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__) -#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) -#define LOGF(...) __android_log_print(ANDROID_LOG_FATAL, LOG_TAG, __VA_ARGS__) +#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) +#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__) +#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) +#define LOGF(...) __android_log_print(ANDROID_LOG_FATAL, LOG_TAG, __VA_ARGS__) #define PLOGE(fmt, args...) LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno)) #endif