mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 13:05:53 +08:00
Feat: EventBus
This commit is contained in:
1 parent
a64bbb8bb8
commit
49d2499f73
7 files changed
+176
-43
No files matched your search
@@ -1,5 +1,5 @@
|
||||
#include <jni_impl.hpp>
|
||||
#include <iostream>
|
||||
#include <event_type.hpp>
|
||||
|
||||
void JNICALL ClassFileLoadHook(
|
||||
jvmtiEnv* jvmti_env,
|
||||
@@ -17,46 +17,17 @@ void JNICALL ClassFileLoadHook(
|
||||
return;
|
||||
}
|
||||
|
||||
/* =========================
|
||||
* 1. Capture original bytes
|
||||
* ========================= */
|
||||
std::lock_guard<std::mutex> lock(classDataMutex);
|
||||
if (classToCapture.contains(name)) {
|
||||
if (!classFileDataMap.contains(name)) {
|
||||
ClassFileData data;
|
||||
|
||||
data.classname = name;
|
||||
data.bytecode.assign(classbytes, classbytes + class_data_len);
|
||||
// Experimental: class/classloader/protection_domain references (to be used in future features, e.g. dynamic patching)
|
||||
data.clazz = class_being_redefined;
|
||||
data.classloader = loader;
|
||||
data.protection_domain = protection_domain;
|
||||
|
||||
|
||||
classFileDataMap[name] = std::move(data);
|
||||
|
||||
classToCapture.erase(name);
|
||||
|
||||
PLOGI << "Captured class: " << name << " (length: " << class_data_len << ")";
|
||||
}
|
||||
}
|
||||
|
||||
/* =========================
|
||||
* 2. Apply patches
|
||||
* ========================= */
|
||||
if (pendingRetransform.contains(name)) {
|
||||
auto& bytes = pendingRetransform[name];
|
||||
|
||||
unsigned char* new_buf = nullptr;
|
||||
jvmti_env->Allocate(bytes.size(), &new_buf);
|
||||
|
||||
memcpy(new_buf, bytes.data(), bytes.size());
|
||||
|
||||
*new_class_data_len = (jint)bytes.size();
|
||||
*new_classbytes = new_buf;
|
||||
|
||||
pendingRetransform.erase(name);
|
||||
|
||||
PLOGI << "Retransformed: " << name << " (new length: " << bytes.size() << ")";
|
||||
}
|
||||
auto& agent = JuiceAgent::Agent::instance();
|
||||
agent.get_eventbus().post(EventClassFileLoadHook{
|
||||
.jvmti_env = jvmti_env,
|
||||
.jni_env = jni_env,
|
||||
.class_being_redefined = class_being_redefined,
|
||||
.loader = loader,
|
||||
.name = name,
|
||||
.protection_domain = protection_domain,
|
||||
.class_data_len = class_data_len,
|
||||
.classbytes = classbytes,
|
||||
.new_class_data_len = new_class_data_len,
|
||||
.new_classbytes = new_classbytes
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user