mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 13:05:53 +08:00
Style: move LocalRef to header / move check_and_clear_exception to header
This commit is contained in:
1 parent
455986b08c
commit
8b0bf8f211
3 files changed
+34
-28
No files matched your search
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <jni.h>
|
||||
#include <jvmti.h>
|
||||
#include <JuiceAgent/Logger.hpp>
|
||||
|
||||
// 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;
|
||||
}
|
||||
@@ -2,37 +2,10 @@
|
||||
#include <libloader.hpp>
|
||||
#include <JuiceAgent/Config.hpp>
|
||||
#include <jvm.hpp>
|
||||
#include <JuiceAgent/Utils.hpp>
|
||||
|
||||
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<typename T>
|
||||
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";
|
||||
|
||||
@@ -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<typename T>
|
||||
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; }
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user