mirror of
https://github.com/LSPosed/LSPlant.git
synced 2025-05-04 20:42:02 +08:00
Reformat code
This commit is contained in:
parent
fd8e2e4c17
commit
a3f95f050b
@ -242,12 +242,12 @@ public:
|
|||||||
if (sdk_int <= __ANDROID_API_N__) {
|
if (sdk_int <= __ANDROID_API_N__) {
|
||||||
kAccCompileDontBother = 0;
|
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,
|
if (!RETRIEVE_FUNC_SYMBOL(art_interpreter_to_compiled_code_bridge,
|
||||||
"artInterpreterToCompiledCodeBridge")) {
|
"artInterpreterToCompiledCodeBridge")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
interpreter_entry_point_offset = entry_point_offset - 2 * kPointerSize;
|
interpreter_entry_point_offset = entry_point_offset - 2 * kPointerSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
namespace lsplant::art {
|
namespace lsplant::art {
|
||||||
class DexFile {
|
class DexFile {
|
||||||
struct Header {
|
struct Header {
|
||||||
uint8_t magic_[8];
|
[[maybe_unused]] uint8_t magic_[8];
|
||||||
uint32_t checksum_; // See also location_checksum_
|
uint32_t checksum_; // See also location_checksum_
|
||||||
};
|
};
|
||||||
CREATE_FUNC_SYMBOL_ENTRY(std::unique_ptr<DexFile>, OpenMemory, const uint8_t* dex_file,
|
CREATE_FUNC_SYMBOL_ENTRY(std::unique_ptr<DexFile>, OpenMemory, const uint8_t* dex_file,
|
||||||
|
@ -13,7 +13,7 @@ class Thread {
|
|||||||
if (DecodeJObjectSym)
|
if (DecodeJObjectSym)
|
||||||
return DecodeJObjectSym(thiz, obj);
|
return DecodeJObjectSym(thiz, obj);
|
||||||
else
|
else
|
||||||
return { .data=nullptr };
|
return {.data = nullptr};
|
||||||
}
|
}
|
||||||
|
|
||||||
CREATE_FUNC_SYMBOL_ENTRY(Thread *, CurrentFromGdb) {
|
CREATE_FUNC_SYMBOL_ENTRY(Thread *, CurrentFromGdb) {
|
||||||
@ -24,17 +24,13 @@ class Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static Thread *Current() {
|
static Thread *Current() { return CurrentFromGdb(); }
|
||||||
return CurrentFromGdb();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool Init(const HookHandler &handler) {
|
static bool Init(const HookHandler &handler) {
|
||||||
if (!RETRIEVE_MEM_FUNC_SYMBOL(DecodeJObject,
|
if (!RETRIEVE_MEM_FUNC_SYMBOL(DecodeJObject, "_ZNK3art6Thread13DecodeJObjectEP8_jobject")) {
|
||||||
"_ZNK3art6Thread13DecodeJObjectEP8_jobject")) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!RETRIEVE_FUNC_SYMBOL(CurrentFromGdb,
|
if (!RETRIEVE_FUNC_SYMBOL(CurrentFromGdb, "_ZN3art6Thread14CurrentFromGdbEv")) {
|
||||||
"_ZN3art6Thread14CurrentFromGdbEv")) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -47,4 +43,4 @@ public:
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace lsplant::art
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string_view>
|
|
||||||
#include <shared_mutex>
|
|
||||||
#include <unordered_set>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <list>
|
|
||||||
#include <sys/system_properties.h>
|
#include <sys/system_properties.h>
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <shared_mutex>
|
||||||
|
#include <string_view>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
#include "logging.hpp"
|
#include "logging.hpp"
|
||||||
#include "utils/hook_helper.hpp"
|
|
||||||
#include "lsplant.hpp"
|
#include "lsplant.hpp"
|
||||||
|
#include "utils/hook_helper.hpp"
|
||||||
|
|
||||||
namespace lsplant {
|
namespace lsplant {
|
||||||
|
|
||||||
@ -19,7 +21,6 @@ enum class Arch {
|
|||||||
kX8664,
|
kX8664,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
consteval inline Arch GetArch() {
|
consteval inline Arch GetArch() {
|
||||||
#if defined(__i386__)
|
#if defined(__i386__)
|
||||||
return Arch::kX86;
|
return Arch::kX86;
|
||||||
@ -30,13 +31,13 @@ consteval inline Arch GetArch() {
|
|||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
return Arch::kArm64;
|
return Arch::kArm64;
|
||||||
#else
|
#else
|
||||||
# error "unsupported architecture"
|
#error "unsupported architecture"
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static constexpr auto kArch = GetArch();
|
inline static constexpr auto kArch = GetArch();
|
||||||
|
|
||||||
template<typename T>
|
template <typename T>
|
||||||
constexpr inline auto RoundUpTo(T v, size_t size) {
|
constexpr inline auto RoundUpTo(T v, size_t size) {
|
||||||
return v + size - 1 - ((v + size - 1) & (size - 1));
|
return v + size - 1 - ((v + size - 1) & (size - 1));
|
||||||
}
|
}
|
||||||
@ -54,7 +55,7 @@ inline auto GetAndroidApiLevel() {
|
|||||||
|
|
||||||
inline static constexpr auto kPointerSize = sizeof(void *);
|
inline static constexpr auto kPointerSize = sizeof(void *);
|
||||||
|
|
||||||
template<typename T>
|
template <typename T>
|
||||||
inline T GetArtSymbol(const std::function<void *(std::string_view)> &resolver,
|
inline T GetArtSymbol(const std::function<void *(std::string_view)> &resolver,
|
||||||
std::string_view symbol) requires(std::is_pointer_v<T>) {
|
std::string_view symbol) requires(std::is_pointer_v<T>) {
|
||||||
if (auto *result = resolver(symbol); result) {
|
if (auto *result = resolver(symbol); result) {
|
||||||
@ -66,11 +67,11 @@ inline T GetArtSymbol(const std::function<void *(std::string_view)> &resolver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace art {
|
namespace art {
|
||||||
class ArtMethod;
|
class ArtMethod;
|
||||||
namespace dex {
|
namespace dex {
|
||||||
class ClassDef;
|
class ClassDef;
|
||||||
}
|
}
|
||||||
}
|
} // namespace art
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
// target, backup
|
// 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::list<std::pair<art::ArtMethod *, art::ArtMethod *>> jit_movements_;
|
||||||
inline std::shared_mutex jit_movements_lock_;
|
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::shared_mutex pending_classes_lock_;
|
||||||
|
|
||||||
inline std::unordered_set<const art::ArtMethod *> pending_methods_;
|
inline std::unordered_set<const art::ArtMethod *> pending_methods_;
|
||||||
inline std::shared_mutex pending_methods_lock_;
|
inline std::shared_mutex pending_methods_lock_;
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
inline bool IsHooked(art::ArtMethod *art_method) {
|
inline bool IsHooked(art::ArtMethod *art_method) {
|
||||||
std::shared_lock lk(hooked_methods_lock_);
|
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);
|
jit_movements_.emplace_back(target, backup);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void RecordPending(const art::dex::ClassDef *class_def, art::ArtMethod *target,
|
||||||
RecordPending(const art::dex::ClassDef *class_def, art::ArtMethod *target, art::ArtMethod *hook,
|
art::ArtMethod *hook, art::ArtMethod *backup) {
|
||||||
art::ArtMethod *backup) {
|
|
||||||
{
|
{
|
||||||
std::unique_lock lk(pending_methods_lock_);
|
std::unique_lock lk(pending_methods_lock_);
|
||||||
pending_methods_.emplace(target);
|
pending_methods_.emplace(target);
|
||||||
@ -143,7 +146,7 @@ inline void OnPending(const art::dex::ClassDef *class_def) {
|
|||||||
set = std::move(it->second);
|
set = std::move(it->second);
|
||||||
pending_classes_.erase(it);
|
pending_classes_.erase(it);
|
||||||
}
|
}
|
||||||
for (auto&[target, hook, backup]: set) {
|
for (auto &[target, hook, backup] : set) {
|
||||||
{
|
{
|
||||||
std::unique_lock mlk(pending_methods_lock_);
|
std::unique_lock mlk(pending_methods_lock_);
|
||||||
pending_methods_.erase(target);
|
pending_methods_.erase(target);
|
||||||
@ -151,4 +154,4 @@ inline void OnPending(const art::dex::ClassDef *class_def) {
|
|||||||
OnPending(target, hook, backup);
|
OnPending(target, hook, backup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} // namespace lsplant
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
#include <concepts>
|
#include <concepts>
|
||||||
|
|
||||||
#include "lsplant.hpp"
|
|
||||||
#include "jni_helper.hpp"
|
#include "jni_helper.hpp"
|
||||||
|
#include "lsplant.hpp"
|
||||||
|
|
||||||
#if defined(__LP64__)
|
#if defined(__LP64__)
|
||||||
# define LP_SELECT(lp32, lp64) lp64
|
#define LP_SELECT(lp32, lp64) lp64
|
||||||
#else
|
#else
|
||||||
# define LP_SELECT(lp32, lp64) lp32
|
#define LP_SELECT(lp32, lp64) lp32
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CONCATENATE(a, b) a##b
|
#define CONCATENATE(a, b) a##b
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
|
|
||||||
#ifndef LOG_TAG
|
#ifndef LOG_TAG
|
||||||
#define LOG_TAG "LSPlant"
|
#define LOG_TAG "LSPlant"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LOG_DISABLED
|
#ifdef LOG_DISABLED
|
||||||
@ -14,15 +14,23 @@
|
|||||||
#define LOGE(...)
|
#define LOGE(...)
|
||||||
#else
|
#else
|
||||||
#ifndef NDEBUG
|
#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 LOGD(fmt, ...) \
|
||||||
#define LOGV(fmt, ...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "%s:%d#%s" ": " fmt, __FILE_NAME__, __LINE__, __PRETTY_FUNCTION__ __VA_OPT__(,) __VA_ARGS__)
|
__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
|
#else
|
||||||
#define LOGD(...)
|
#define LOGD(...)
|
||||||
#define LOGV(...)
|
#define LOGV(...)
|
||||||
#endif
|
#endif
|
||||||
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, 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 LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)
|
||||||
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, 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 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))
|
#define PLOGE(fmt, args...) LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno))
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user