Reformat code

This commit is contained in:
LoveSy 2022-03-11 19:37:11 +08:00
parent fd8e2e4c17
commit a3f95f050b
6 changed files with 51 additions and 44 deletions

View File

@ -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;

View File

@ -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<DexFile>, OpenMemory, const uint8_t* dex_file,

View File

@ -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

View File

@ -1,14 +1,16 @@
#pragma once
#include <string_view>
#include <shared_mutex>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <sys/system_properties.h>
#include <list>
#include <shared_mutex>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
#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<typename T>
template <typename T>
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<typename T>
template <typename T>
inline T GetArtSymbol(const std::function<void *(std::string_view)> &resolver,
std::string_view symbol) requires(std::is_pointer_v<T>) {
if (auto *result = resolver(symbol); result) {
@ -66,11 +67,11 @@ inline T GetArtSymbol(const std::function<void *(std::string_view)> &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<std::pair<art::ArtMethod *, art::ArtMethod *>> jit_movements_;
inline std::shared_mutex jit_movements_lock_;
inline std::unordered_map<const art::dex::ClassDef *, std::list<std::tuple<art::ArtMethod *, art::ArtMethod *, art::ArtMethod *>>> pending_classes_;
inline std::unordered_map<
const art::dex::ClassDef *,
std::list<std::tuple<art::ArtMethod *, art::ArtMethod *, art::ArtMethod *>>>
pending_classes_;
inline std::shared_mutex pending_classes_lock_;
inline std::unordered_set<const art::ArtMethod *> 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

View File

@ -2,13 +2,13 @@
#include <concepts>
#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

View File

@ -3,7 +3,7 @@
#include <android/log.h>
#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