diff --git a/includes/JuiceAgent/Utils.hpp b/includes/JuiceAgent/Utils.hpp new file mode 100644 index 0000000..8b224c8 --- /dev/null +++ b/includes/JuiceAgent/Utils.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include +#include +#include + +// Check for JNI exceptions and clear them +bool check_and_clear_exception(JNIEnv* env, const char* context) { + if (env->ExceptionCheck()) { + PLOGE << "JNI Exception occurred at: " << context; + env->ExceptionDescribe(); + env->ExceptionClear(); + return true; + } + return false; +} \ No newline at end of file diff --git a/src/libloader/common/libloader.cpp b/src/libloader/common/libloader.cpp index d992089..288a49b 100644 --- a/src/libloader/common/libloader.cpp +++ b/src/libloader/common/libloader.cpp @@ -2,37 +2,10 @@ #include #include #include +#include namespace libloader { -namespace { - // Check for JNI exceptions and clear them - bool check_and_clear_exception(JNIEnv* env, const char* context) { - if (env->ExceptionCheck()) { - PLOGE << "JNI Exception occurred at: " << context; - env->ExceptionDescribe(); - env->ExceptionClear(); - return true; - } - return false; - } - - // RAII wrapper for local JNI references - template - class LocalRef { - private: - JNIEnv* env; - T ref; - public: - LocalRef(JNIEnv* env, T ref) : env(env), ref(ref) {} - ~LocalRef() { - if (ref) env->DeleteLocalRef(ref); - } - T get() const { return ref; } - operator T() const { return ref; } - }; -} - // Invoke JuiceAgentBootstrap.start(String) via JNI bool invoke_juiceagent_init(JNIEnv* env, const InjectionInfo& info) { const char* bootstrap_class = "cn/xiaozhou233/juiceagent/api/JuiceAgentBootstrap"; diff --git a/src/libloader/includes/libloader.hpp b/src/libloader/includes/libloader.hpp index 7521fe0..d12141c 100644 --- a/src/libloader/includes/libloader.hpp +++ b/src/libloader/includes/libloader.hpp @@ -12,3 +12,20 @@ namespace libloader bool invoke_juiceagent_init(JNIEnv* env, const InjectionInfo& info); } // namespace libloader + +namespace { + // RAII wrapper for local JNI references + template + class LocalRef { + private: + JNIEnv* env; + T ref; + public: + LocalRef(JNIEnv* env, T ref) : env(env), ref(ref) {} + ~LocalRef() { + if (ref) env->DeleteLocalRef(ref); + } + T get() const { return ref; } + operator T() const { return ref; } + }; +} \ No newline at end of file