Modularize interfaces

This commit is contained in:
LoveSy 2024-04-27 14:39:29 +08:00
parent 2db8b66b29
commit 29f124c576
No known key found for this signature in database
9 changed files with 226 additions and 115 deletions

View File

@ -18,6 +18,7 @@ endif()
set(SOURCES lsplant.cc)
file(GLOB_RECURSE MODULE_SOURCES "*.cxx")
file(GLOB_RECURSE MODULE_INTERFACES "*.ixx")
set(DEX_BUILDER_BUILD_SHARED OFF CACHE INTERNAL "" FORCE)
add_subdirectory(external/dex_builder)
@ -27,7 +28,8 @@ option(LSPLANT_BUILD_SHARED "If ON, lsplant will also build shared library" ON)
if (LSPLANT_BUILD_SHARED)
message(STATUS "Building lsplant as a shared library")
add_library(${PROJECT_NAME} SHARED ${SOURCES})
target_sources(${PROJECT_NAME} PRIVATE FILE_SET CXX_MODULES FILES ${MODULE_SOURCES})
target_sources(${PROJECT_NAME} PRIVATE FILE_SET ms TYPE CXX_MODULES FILES ${MODULE_SOURCES})
target_sources(${PROJECT_NAME} PUBLIC FILE_SET CXX_MODULES FILES ${MODULE_INTERFACES})
target_include_directories(${PROJECT_NAME} PUBLIC include)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_options(${PROJECT_NAME} PRIVATE -flto)
@ -43,7 +45,8 @@ if (LSPLANT_BUILD_SHARED)
endif()
add_library(${PROJECT_NAME}_static STATIC ${SOURCES})
target_sources(${PROJECT_NAME}_static PRIVATE FILE_SET CXX_MODULES FILES ${MODULE_SOURCES})
target_sources(${PROJECT_NAME}_static PRIVATE FILE_SET ms TYPE CXX_MODULES FILES ${MODULE_SOURCES})
target_sources(${PROJECT_NAME}_static PUBLIC FILE_SET CXX_MODULES FILES ${MODULE_INTERFACES})
target_include_directories(${PROJECT_NAME}_static PUBLIC include)
target_include_directories(${PROJECT_NAME}_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

View File

@ -1,8 +1,6 @@
module;
#include "logging.hpp"
#define JNI_HELPER_NO_NS
#include "utils/hook_helper.hpp"
export module art_method;

View File

@ -12,6 +12,7 @@ module;
#include "utils/jni_helper.hpp"
export module common;
export import jni_helper;
namespace lsplant {

View File

@ -0,0 +1,19 @@
module;
#include "lsplant.hpp"
export module lsplant;
export namespace lsplant {
inline namespace v2 {
using lsplant::v2::InitInfo;
using lsplant::v2::Init;
using lsplant::v2::Hook;
using lsplant::v2::UnHook;
using lsplant::v2::IsHooked;
using lsplant::v2::Deoptimize;
using lsplant::v2::GetNativeFunction;
using lsplant::v2::MakeClassInheritable;
using lsplant::v2::MakeDexFileTrusted;
}
}

View File

@ -1,9 +1,10 @@
#pragma once
#include <concepts>
#include <android/log.h>
#include "jni_helper.hpp"
#include "lsplant.hpp"
#include "type_traits.hpp"
#if defined(__LP64__)
#define LP_SELECT(lp32, lp64) lp64

View File

@ -6,6 +6,8 @@
#include <string>
#include <string_view>
#include "type_traits.hpp"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-partial-specialization"
#pragma clang diagnostic ignored "-Wunknown-pragmas"
@ -15,18 +17,7 @@
TypeName(const TypeName &) = delete; \
void operator=(const TypeName &) = delete
#ifndef JNI_HELPER_NO_NS // workaroud for https://github.com/llvm/llvm-project/issues/88400
namespace lsplant {
#endif
template <class, template <class, class...> class>
struct is_instance : public std::false_type {};
template <class... Ts, template <class, class...> class U>
struct is_instance<U<Ts...>, U> : public std::true_type {};
template <class T, template <class, class...> class U>
inline constexpr bool is_instance_v = is_instance<T, U>::value;
template <typename T>
concept JObject = std::is_base_of_v<std::remove_pointer_t<_jobject>, std::remove_pointer_t<T>>;
@ -120,11 +111,11 @@ public:
};
template <typename T, typename U>
concept ScopeOrRaw = std::is_convertible_v<T, U> ||
(is_instance_v<std::decay_t<T>, ScopedLocalRef>
&&std::is_convertible_v<typename std::decay_t<T>::BaseType, U>) ||
(std::is_same_v<std::decay_t<T>, JObjectArrayElement>
&&std::is_convertible_v<jobject, U>);
concept ScopeOrRaw =
std::is_convertible_v<T, U> ||
(is_instance_v<std::decay_t<T>, ScopedLocalRef> &&
std::is_convertible_v<typename std::decay_t<T>::BaseType, U>) ||
(std::is_same_v<std::decay_t<T>, JObjectArrayElement> && std::is_convertible_v<jobject, U>);
template <typename T>
concept ScopeOrClass = ScopeOrRaw<T, jclass>;
@ -188,8 +179,7 @@ public:
JUTFString(const ScopedLocalRef<jstring> &jstr)
: JUTFString(jstr.env_, jstr.local_ref_, nullptr) {}
JUTFString(JNIEnv *env, jstring jstr, const char *default_cstr)
: env_(env), jstr_(jstr) {
JUTFString(JNIEnv *env, jstring jstr, const char *default_cstr) : env_(env), jstr_(jstr) {
if (env_ && jstr_)
cstr_ = env_->GetStringUTFChars(jstr, nullptr);
else
@ -236,8 +226,8 @@ private:
};
template <typename Func, typename... Args>
requires(std::is_function_v<Func>)
[[maybe_unused]] inline auto JNI_SafeInvoke(JNIEnv *env, Func JNIEnv::*f, Args &&...args) {
requires(std::is_function_v<Func>)
[[maybe_unused]] inline auto JNI_SafeInvoke(JNIEnv *env, Func JNIEnv::*f, Args &&...args) {
struct finally {
finally(JNIEnv *env) : env_(env) {}
@ -677,81 +667,74 @@ template <ScopeOrClass Class, typename... Args>
// non-virtual methods
template <ScopeOrObject Object, ScopeOrClass Class, typename... Args>
[[maybe_unused]] inline auto JNI_CallCallNonvirtualVoidMethod(JNIEnv *env, Object &&obj,
Class &&clazz, jmethodID method,
Args &&...args) {
[[maybe_unused]] inline auto JNI_CallNonvirtualVoidMethod(JNIEnv *env, Object &&obj, Class &&clazz,
jmethodID method, Args &&...args) {
return JNI_SafeInvoke(env, &JNIEnv::CallNonvirtualVoidMethod, std::forward<Object>(obj),
std::forward<Class>(clazz), method, std::forward<Args>(args)...);
}
template <ScopeOrObject Object, ScopeOrClass Class, typename... Args>
[[maybe_unused]] inline auto JNI_CallCallNonvirtualObjectMethod(JNIEnv *env, Object &&obj,
Class &&clazz, jmethodID method,
Args &&...args) {
[[maybe_unused]] inline auto JNI_CallNonvirtualObjectMethod(JNIEnv *env, Object &&obj,
Class &&clazz, jmethodID method,
Args &&...args) {
return JNI_SafeInvoke(env, &JNIEnv::CallNonvirtualObjectMethod, std::forward<Object>(obj),
std::forward<Class>(clazz), method, std::forward<Args>(args)...);
}
template <ScopeOrObject Object, ScopeOrClass Class, typename... Args>
[[maybe_unused]] inline auto JNI_CallCallNonvirtualBooleanMethod(JNIEnv *env, Object &&obj,
Class &&clazz, jmethodID method,
Args &&...args) {
[[maybe_unused]] inline auto JNI_CallNonvirtualBooleanMethod(JNIEnv *env, Object &&obj,
Class &&clazz, jmethodID method,
Args &&...args) {
return JNI_SafeInvoke(env, &JNIEnv::CallNonvirtualBooleanMethod, std::forward<Object>(obj),
std::forward<Class>(clazz), method, std::forward<Args>(args)...);
}
template <ScopeOrObject Object, ScopeOrClass Class, typename... Args>
[[maybe_unused]] inline auto JNI_CallCallNonvirtualByteMethod(JNIEnv *env, Object &&obj,
Class &&clazz, jmethodID method,
Args &&...args) {
[[maybe_unused]] inline auto JNI_CallNonvirtualByteMethod(JNIEnv *env, Object &&obj, Class &&clazz,
jmethodID method, Args &&...args) {
return JNI_SafeInvoke(env, &JNIEnv::CallNonvirtualByteMethod, std::forward<Object>(obj),
std::forward<Class>(clazz), method, std::forward<Args>(args)...);
}
template <ScopeOrObject Object, ScopeOrClass Class, typename... Args>
[[maybe_unused]] inline auto JNI_CallCallNonvirtualCharMethod(JNIEnv *env, Object &&obj,
Class &&clazz, jmethodID method,
Args &&...args) {
[[maybe_unused]] inline auto JNI_CallNonvirtualCharMethod(JNIEnv *env, Object &&obj, Class &&clazz,
jmethodID method, Args &&...args) {
return JNI_SafeInvoke(env, &JNIEnv::CallNonvirtualCharMethod, std::forward<Object>(obj),
std::forward<Class>(clazz), method, std::forward<Args>(args)...);
}
template <ScopeOrObject Object, ScopeOrClass Class, typename... Args>
[[maybe_unused]] inline auto JNI_CallCallNonvirtualShortMethod(JNIEnv *env, Object &&obj,
Class &&clazz, jmethodID method,
Args &&...args) {
[[maybe_unused]] inline auto JNI_CallNonvirtualShortMethod(JNIEnv *env, Object &&obj, Class &&clazz,
jmethodID method, Args &&...args) {
return JNI_SafeInvoke(env, &JNIEnv::CallNonvirtualShortMethod, std::forward<Object>(obj),
std::forward<Class>(clazz), method, std::forward<Args>(args)...);
}
template <ScopeOrObject Object, ScopeOrClass Class, typename... Args>
[[maybe_unused]] inline auto JNI_CallCallNonvirtualIntMethod(JNIEnv *env, Object &&obj,
Class &&clazz, jmethodID method,
Args &&...args) {
[[maybe_unused]] inline auto JNI_CallNonvirtualIntMethod(JNIEnv *env, Object &&obj, Class &&clazz,
jmethodID method, Args &&...args) {
return JNI_SafeInvoke(env, &JNIEnv::CallNonvirtualIntMethod, std::forward<Object>(obj),
std::forward<Class>(clazz), method, std::forward<Args>(args)...);
}
template <ScopeOrObject Object, ScopeOrClass Class, typename... Args>
[[maybe_unused]] inline auto JNI_CallCallNonvirtualLongMethod(JNIEnv *env, Object &&obj,
Class &&clazz, jmethodID method,
Args &&...args) {
[[maybe_unused]] inline auto JNI_CallNonvirtualLongMethod(JNIEnv *env, Object &&obj, Class &&clazz,
jmethodID method, Args &&...args) {
return JNI_SafeInvoke(env, &JNIEnv::CallNonvirtualLongMethod, std::forward<Object>(obj),
std::forward<Class>(clazz), method, std::forward<Args>(args)...);
}
template <ScopeOrObject Object, ScopeOrClass Class, typename... Args>
[[maybe_unused]] inline auto JNI_CallCallNonvirtualFloatMethod(JNIEnv *env, Object &&obj,
Class &&clazz, jmethodID method,
Args &&...args) {
[[maybe_unused]] inline auto JNI_CallNonvirtualFloatMethod(JNIEnv *env, Object &&obj, Class &&clazz,
jmethodID method, Args &&...args) {
return JNI_SafeInvoke(env, &JNIEnv::CallNonvirtualFloatMethod, std::forward<Object>(obj),
std::forward<Class>(clazz), method, std::forward<Args>(args)...);
}
template <ScopeOrObject Object, ScopeOrClass Class, typename... Args>
[[maybe_unused]] inline auto JNI_CallCallNonvirtualDoubleMethod(JNIEnv *env, Object &&obj,
Class &&clazz, jmethodID method,
Args &&...args) {
[[maybe_unused]] inline auto JNI_CallNonvirtualDoubleMethod(JNIEnv *env, Object &&obj,
Class &&clazz, jmethodID method,
Args &&...args) {
return JNI_SafeInvoke(env, &JNIEnv::CallNonvirtualDoubleMethod, std::forward<Object>(obj),
std::forward<Class>(clazz), method, std::forward<Args>(args)...);
}
@ -787,8 +770,9 @@ template <ScopeOrObject Object>
}
template <typename U, typename T>
[[maybe_unused]] inline auto JNI_Cast(ScopedLocalRef<T> &&x) requires(
std::is_convertible_v<T, _jobject *>) {
[[maybe_unused]] inline auto JNI_Cast(ScopedLocalRef<T> &&x)
requires(std::is_convertible_v<T, _jobject *>)
{
return ScopedLocalRef<U>(std::move(x));
}
@ -906,9 +890,7 @@ public:
reset(local_ref);
}
ScopedLocalRef(ScopedLocalRef &&s) noexcept {
*this = std::move(s);
}
ScopedLocalRef(ScopedLocalRef &&s) noexcept { *this = std::move(s); }
template <JObject U>
ScopedLocalRef(ScopedLocalRef<U> &&s) noexcept : ScopedLocalRef(s.env_, (T)s.release()) {}
@ -1038,9 +1020,8 @@ class JObjectArrayElement {
return JNI_SafeInvoke(env_, &JNIEnv::GetObjectArrayElement, array_, i_);
}
explicit JObjectArrayElement(JNIEnv * env, jobjectArray array, int i, size_t size) :
env_(env), array_(array), i_(i), size_(size),
item_(obtain()) {}
explicit JObjectArrayElement(JNIEnv *env, jobjectArray array, int i, size_t size)
: env_(env), array_(array), i_(i), size_(size), item_(obtain()) {}
JObjectArrayElement &operator++() {
++i_;
@ -1054,36 +1035,29 @@ class JObjectArrayElement {
return *this;
}
JObjectArrayElement operator++(int) {
return JObjectArrayElement(env_, array_, i_ + 1, size_);
}
JObjectArrayElement operator++(int) { return JObjectArrayElement(env_, array_, i_ + 1, size_); }
JObjectArrayElement operator--(int) {
return JObjectArrayElement(env_, array_, i_ - 1, size_);
}
JObjectArrayElement operator--(int) { return JObjectArrayElement(env_, array_, i_ - 1, size_); }
public:
JObjectArrayElement(JObjectArrayElement&& s): env_(s.env_), array_(s.array_), i_(s.i_), size_(s.size_), item_(std::move(s.item_)) {}
JObjectArrayElement(JObjectArrayElement &&s)
: env_(s.env_), array_(s.array_), i_(s.i_), size_(s.size_), item_(std::move(s.item_)) {}
operator ScopedLocalRef<jobject>& () & {
return item_;
}
operator ScopedLocalRef<jobject> &() & { return item_; }
operator ScopedLocalRef<jobject>&& () && {
return std::move(item_);
}
operator ScopedLocalRef<jobject> &&() && { return std::move(item_); }
JObjectArrayElement& operator=(JObjectArrayElement&& s) {
JObjectArrayElement &operator=(JObjectArrayElement &&s) {
reset(s.item_.release());
return *this;
}
JObjectArrayElement& operator=(const JObjectArrayElement& s) {
JObjectArrayElement &operator=(const JObjectArrayElement &s) {
reset(env_->NewLocalRef(s.item_.get()));
return *this;
}
JObjectArrayElement& operator=(jobject s) {
JObjectArrayElement &operator=(jobject s) {
reset(env_->NewLocalRef(s));
return *this;
}
@ -1093,13 +1067,9 @@ public:
JNI_SafeInvoke(env_, &JNIEnv::SetObjectArrayElement, array_, i_, item_);
}
ScopedLocalRef<jobject> clone() const {
return item_.clone();
}
ScopedLocalRef<jobject> clone() const { return item_.clone(); }
operator jobject() const {
return item_;
}
operator jobject() const { return item_; }
jobject get() const { return item_.get(); }
@ -1108,16 +1078,17 @@ public:
jobject operator->() const { return item_.get(); }
jobject operator*() const { return item_.get(); }
private:
JNIEnv *env_;
jobjectArray array_;
int i_;
int size_;
ScopedLocalRef<jobject> item_;
JObjectArrayElement(const JObjectArrayElement&) = delete;
JObjectArrayElement(const JObjectArrayElement &) = delete;
};
template<>
template <>
class ScopedLocalRef<jobjectArray> {
public:
class Iterator {
@ -1125,6 +1096,7 @@ public:
Iterator(JObjectArrayElement &&e) : e_(std::move(e)) {}
Iterator(JNIEnv *env, jobjectArray array, int i, size_t size) : e_(env, array, i, size) {}
public:
auto &operator*() { return e_; }
@ -1140,17 +1112,14 @@ public:
return *this;
}
Iterator operator++(int) {
return Iterator(e_++);
}
Iterator operator++(int) { return Iterator(e_++); }
Iterator operator--(int) {
return Iterator(e_--);
}
Iterator operator--(int) { return Iterator(e_--); }
bool operator==(const Iterator &other) const { return other.e_.i_ == e_.i_; }
bool operator!=(const Iterator &other) const { return other.e_.i_ != e_.i_; }
private:
JObjectArrayElement e_;
};
@ -1163,7 +1132,9 @@ public:
return JNI_SafeInvoke(env_, &JNIEnv::GetObjectArrayElement, array_, i_);
}
ConstIterator(JNIEnv * env, jobjectArray array, int i, int size) : env_(env), array_(array), i_(i), size_(size), item_(obtain()) {}
ConstIterator(JNIEnv *env, jobjectArray array, int i, int size)
: env_(env), array_(array), i_(i), size_(size), item_(obtain()) {}
public:
auto &operator*() { return item_; }
@ -1181,19 +1152,16 @@ public:
return *this;
}
ConstIterator operator++(int) {
return ConstIterator(env_, array_, i_ + 1, size_);
}
ConstIterator operator++(int) { return ConstIterator(env_, array_, i_ + 1, size_); }
ConstIterator operator--(int) {
return ConstIterator(env_, array_, i_ - 1, size_);
}
ConstIterator operator--(int) { return ConstIterator(env_, array_, i_ - 1, size_); }
bool operator==(const ConstIterator &other) const { return other.i_ == i_; }
bool operator!=(const ConstIterator &other) const { return other.i_ != i_; }
private:
JNIEnv* env_;
JNIEnv *env_;
jobjectArray array_;
int i_;
int size_;
@ -1212,18 +1180,17 @@ public:
auto cend() const { return ConstIterator(env_, local_ref_, size_, size_); }
ScopedLocalRef(JNIEnv *env, jobjectArray local_ref) noexcept: env_(env), local_ref_(nullptr) {
ScopedLocalRef(JNIEnv *env, jobjectArray local_ref) noexcept : env_(env), local_ref_(nullptr) {
reset(local_ref);
}
ScopedLocalRef(ScopedLocalRef &&s) noexcept {
*this = std::move(s);
}
ScopedLocalRef(ScopedLocalRef &&s) noexcept { *this = std::move(s); }
template<JObject U>
ScopedLocalRef(ScopedLocalRef<U> &&s) noexcept : ScopedLocalRef(s.env_, (jobjectArray) s.release()) {}
template <JObject U>
ScopedLocalRef(ScopedLocalRef<U> &&s) noexcept
: ScopedLocalRef(s.env_, (jobjectArray)s.release()) {}
explicit ScopedLocalRef(JNIEnv *env) noexcept: ScopedLocalRef(env, jobjectArray {nullptr}) {}
explicit ScopedLocalRef(JNIEnv *env) noexcept : ScopedLocalRef(env, jobjectArray{nullptr}) {}
~ScopedLocalRef() { env_->DeleteLocalRef(release()); }
@ -1248,7 +1215,9 @@ public:
jobjectArray get() const { return local_ref_; }
JObjectArrayElement operator[](size_t index) {
return JObjectArrayElement(env_, local_ref_, index, JNI_SafeInvoke(env_, &JNIEnv::GetObjectArrayElement, local_ref_, index));
return JObjectArrayElement(
env_, local_ref_, index,
JNI_SafeInvoke(env_, &JNIEnv::GetObjectArrayElement, local_ref_, index));
}
const ScopedLocalRef<jobject> operator[](size_t index) const {
@ -1273,7 +1242,7 @@ public:
operator bool() const { return local_ref_; }
template<JObject U>
template <JObject U>
friend class ScopedLocalRef;
friend class JUTFString;
@ -1340,9 +1309,7 @@ template <ScopeOrObject Object>
env, o, JNI_GetFieldID(env, JNI_GetObjectClass(env, o), field_name, field_class));
}
#ifndef JNI_HELPER_NO_NS
} // namespace lsplant
#endif
#undef DISALLOW_COPY_AND_ASSIGN

View File

@ -0,0 +1,110 @@
module;
#include "utils/jni_helper.hpp"
export module jni_helper;
export namespace lsplant {
using lsplant::JNIMonitor;
using lsplant::JNIScopeFrame;
using lsplant::JUTFString;
using lsplant::ScopedLocalRef;
using lsplant::WrapScope;
using lsplant::JNI_GetBooleanField;
using lsplant::JNI_GetByteField;
using lsplant::JNI_GetCharField;
using lsplant::JNI_GetDoubleField;
using lsplant::JNI_GetFieldID;
using lsplant::JNI_GetFloatField;
using lsplant::JNI_GetIntField;
using lsplant::JNI_GetLongField;
using lsplant::JNI_GetObjectField;
using lsplant::JNI_GetShortField;
using lsplant::JNI_SetBooleanField;
using lsplant::JNI_SetByteField;
using lsplant::JNI_SetCharField;
using lsplant::JNI_SetDoubleField;
using lsplant::JNI_SetFloatField;
using lsplant::JNI_SetIntField;
using lsplant::JNI_SetLongField;
using lsplant::JNI_SetObjectField;
using lsplant::JNI_SetShortField;
using lsplant::JNI_GetStaticBooleanField;
using lsplant::JNI_GetStaticByteField;
using lsplant::JNI_GetStaticCharField;
using lsplant::JNI_GetStaticDoubleField;
using lsplant::JNI_GetStaticFieldID;
using lsplant::JNI_GetStaticFloatField;
using lsplant::JNI_GetStaticIntField;
using lsplant::JNI_GetStaticLongField;
using lsplant::JNI_GetStaticObjectField;
using lsplant::JNI_GetStaticShortField;
using lsplant::JNI_SetStaticBooleanField;
using lsplant::JNI_SetStaticByteField;
using lsplant::JNI_SetStaticCharField;
using lsplant::JNI_SetStaticDoubleField;
using lsplant::JNI_SetStaticFloatField;
using lsplant::JNI_SetStaticIntField;
using lsplant::JNI_SetStaticLongField;
using lsplant::JNI_SetStaticObjectField;
using lsplant::JNI_SetStaticShortField;
using lsplant::JNI_CallBooleanMethod;
using lsplant::JNI_CallByteMethod;
using lsplant::JNI_CallCharMethod;
using lsplant::JNI_CallDoubleMethod;
using lsplant::JNI_CallFloatMethod;
using lsplant::JNI_CallIntMethod;
using lsplant::JNI_CallLongMethod;
using lsplant::JNI_CallNonvirtualBooleanMethod;
using lsplant::JNI_CallNonvirtualByteMethod;
using lsplant::JNI_CallNonvirtualCharMethod;
using lsplant::JNI_CallNonvirtualDoubleMethod;
using lsplant::JNI_CallNonvirtualFloatMethod;
using lsplant::JNI_CallNonvirtualIntMethod;
using lsplant::JNI_CallNonvirtualLongMethod;
using lsplant::JNI_CallNonvirtualObjectMethod;
using lsplant::JNI_CallNonvirtualShortMethod;
using lsplant::JNI_CallNonvirtualVoidMethod;
using lsplant::JNI_CallObjectMethod;
using lsplant::JNI_CallShortMethod;
using lsplant::JNI_CallStaticBooleanMethod;
using lsplant::JNI_CallStaticByteMethod;
using lsplant::JNI_CallStaticCharMethod;
using lsplant::JNI_CallStaticDoubleMethod;
using lsplant::JNI_CallStaticFloatMethod;
using lsplant::JNI_CallStaticIntMethod;
using lsplant::JNI_CallStaticLongMethod;
using lsplant::JNI_CallStaticObjectMethod;
using lsplant::JNI_CallStaticShortMethod;
using lsplant::JNI_CallStaticVoidMethod;
using lsplant::JNI_CallVoidMethod;
using lsplant::JNI_GetMethodID;
using lsplant::JNI_GetStaticMethodID;
using lsplant::JNI_ToReflectedMethod;
using lsplant::JNI_NewBooleanArray;
using lsplant::JNI_NewByteArray;
using lsplant::JNI_NewCharArray;
using lsplant::JNI_NewDirectByteBuffer;
using lsplant::JNI_NewDoubleArray;
using lsplant::JNI_NewFloatArray;
using lsplant::JNI_NewIntArray;
using lsplant::JNI_NewLongArray;
using lsplant::JNI_NewObject;
using lsplant::JNI_NewObjectArray;
using lsplant::JNI_NewShortArray;
using lsplant::JNI_Cast;
using lsplant::JNI_FindClass;
using lsplant::JNI_GetArrayLength;
using lsplant::JNI_GetObjectClass;
using lsplant::JNI_GetObjectFieldOf;
using lsplant::JNI_IsInstanceOf;
using lsplant::JNI_NewGlobalRef;
using lsplant::JNI_NewStringUTF;
using lsplant::JNI_RegisterNatives;
} // namespace lsplant

View File

@ -0,0 +1,14 @@
#pragma once
#include <type_traits>
namespace lsplant {
template <class, template <class, class...> class>
struct is_instance : public std::false_type {};
template <class... Ts, template <class, class...> class U>
struct is_instance<U<Ts...>, U> : public std::true_type {};
template <class T, template <class, class...> class U>
inline constexpr bool is_instance_v = is_instance<T, U>::value;
} // namespace lsplant

View File

@ -12,9 +12,7 @@
#include "logging.hpp"
#include "lsplant.hpp"
#define JNI_HELPER_NO_NS
#include "utils/hook_helper.hpp"
#include "utils/jni_helper.hpp"
import common;
import art_method;
@ -482,7 +480,7 @@ std::tuple<jclass, jfieldID, jmethodID, jmethodID> BuildDex(JNIEnv *env, jobject
if (!dex) {
LOGE("Failed to open memory dex: %s", err_msg.data());
} else {
java_dex_file = WrapScope(env, dex ? dex->ToJavaDexFile(env) : jobject{nullptr});
java_dex_file = ScopedLocalRef(env, dex ? dex->ToJavaDexFile(env) : nullptr);
}
}