Refactor: rebuild libagent with simplified lifecycle

- Replace eventbus/services with Agent preload/init lifecycle
- Move JNI header to shared includes; add jni_common.hpp umbrella header
- Reduce ClassFileLoadHook to a stub for later implementation
- Add eventpp dependency
- Document custom API JAR workflow (WIP)
This commit is contained in:
xiaozhou233 committed 2026-08-16 21:14:44 +08:00
1 parent 3b180e7199
commit 51bcfbd549
47 files changed
+5583 -1462

No files matched your search

-64
View File
@@ -1,64 +0,0 @@
#include <services.hpp>
#include <jni_impl.hpp>
namespace JuiceAgent::services::Bytecode {
void capture_bytecodes(const EventClassFileLoadHook& e) {
std::lock_guard<std::mutex> lock(classDataMutex);
if (!classToCapture.contains(e.name) || classFileDataMap.contains(e.name)) {
return;
}
ClassFileData data;
data.classname = e.name;
data.bytecode.assign(e.classbytes, e.classbytes + e.class_data_len);
if (e.jni_env) {
if (e.class_being_redefined) data.clazz = static_cast<jclass>(e.jni_env->NewGlobalRef(e.class_being_redefined));
if (e.loader) data.classloader = e.jni_env->NewGlobalRef(e.loader);
if (e.protection_domain) data.protection_domain = e.jni_env->NewGlobalRef(e.protection_domain);
}
classFileDataMap[e.name] = std::move(data);
classToCapture.erase(e.name);
spdlog::info("Captured class: {} (length: {})", e.name, e.class_data_len);
}
void patch_bytecodes(const EventClassFileLoadHook& e) {
std::lock_guard<std::mutex> lock(pendingRetransformMutex);
auto it = pendingRetransform.find(e.name);
if (it == pendingRetransform.end()) {
return;
}
auto& bytes = it->second;
const jint new_len = static_cast<jint>(bytes.size());
unsigned char* new_buf = nullptr;
if (e.jvmti_env->Allocate(bytes.size(), &new_buf) != JVMTI_ERROR_NONE) {
spdlog::error("Failed to allocate buffer for retransform: {}", e.name);
return;
}
memcpy(new_buf, bytes.data(), bytes.size());
*e.new_class_data_len = new_len;
*e.new_classbytes = new_buf;
pendingRetransform.erase(it);
spdlog::info("Retransformed: {} (new length: {})", e.name, new_len);
}
void init() {
agent().get_eventbus().subscribe<EventClassFileLoadHook>(capture_bytecodes);
agent().get_eventbus().subscribe<EventClassFileLoadHook>(patch_bytecodes);
}
void start() {
}
}