mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 21:15:56 +08:00
Impl: Data Structures and set/map
This commit is contained in:
1 parent
faeaf052b9
commit
ad69f9d11a
3 files changed
+38
No files matched your search
@@ -12,5 +12,7 @@ void JNICALL ClassFileLoadHook(
|
||||
const unsigned char* classbytes,
|
||||
jint* new_class_data_len,
|
||||
unsigned char** new_classbytes) {
|
||||
// Delete this log when the hook is stable, or it will cause performance issues
|
||||
std::cout << "ClassFileLoadHook: " << name << std::endl;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#include <global.hpp>
|
||||
|
||||
std::unordered_set<std::string> classToCapture;
|
||||
std::unordered_map<std::string, ClassFileData> classFileDataMap;
|
||||
std::mutex classDataMutex;
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <jni.h>
|
||||
#include <jvmti.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <mutex>
|
||||
|
||||
// Data Structures
|
||||
struct ClassFileData {
|
||||
std::string className;
|
||||
std::vector<unsigned char> bytecode;
|
||||
|
||||
// ======== Global references to prevent GC ========
|
||||
// Remember to release these references when they are no longer needed, otherwise it will cause memory leaks
|
||||
jclass clazz;
|
||||
jclass classloader;
|
||||
jobject protection_domain;
|
||||
|
||||
};
|
||||
|
||||
// Set of target class internal names to capture (e.g. java/lang/String)
|
||||
extern std::unordered_set<std::string> classToCapture;
|
||||
|
||||
// Cache of captured class bytecode, keyed by internal class name
|
||||
extern std::unordered_map<std::string, ClassFileData> classFileDataMap;
|
||||
|
||||
// Mutex protecting access to classToCapture and classFileDataMap (thread-safe for JVMTI callbacks)
|
||||
extern std::mutex classDataMutex;
|
||||
Reference in new issue
Block a user