mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 13:05:53 +08:00
BugFix and Update: C++ 20
This commit is contained in:
1 parent
ad69f9d11a
commit
9aa77848d7
4 files changed
+30
-2
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
project(JuiceAgent LANGUAGES C CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# output directories
|
||||
|
||||
@@ -14,5 +14,32 @@ void JNICALL ClassFileLoadHook(
|
||||
unsigned char** new_classbytes) {
|
||||
// Delete this log when the hook is stable, or it will cause performance issues
|
||||
std::cout << "ClassFileLoadHook: " << name << std::endl;
|
||||
if (!name) {
|
||||
PLOGW << "name is null";
|
||||
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 << ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ struct ClassFileData {
|
||||
// ======== 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 classloader;
|
||||
jobject protection_domain;
|
||||
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <JuiceAgent/Logger.hpp>
|
||||
#include <libagent.hpp>
|
||||
#include <utils.hpp>
|
||||
#include <global.hpp>
|
||||
|
||||
// Generated by JuiceAgent-API
|
||||
#include <cn_xiaozhou233_juiceagent_api_JuiceAgent.h>
|
||||
|
||||
Reference in new issue
Block a user