Refactor: Move bytecodes_opt -> BytecodeService

This commit is contained in:
xiaozhou233 committed 2026-05-07 15:34:59 +08:00
1 parent 637640b938
commit 882c19ad8f
5 files changed
+23 -25

No files matched your search

-10
View File
@@ -1,10 +0,0 @@
#pragma once
#include "event/event_type.hpp"
namespace JuiceAgent::Bytecodes {
void register_bytecodes();
void capture_bytecodes(const EventClassFileLoadHook& e);
void patch_bytecodes(const EventClassFileLoadHook& e);
}
+5
View File
@@ -29,4 +29,9 @@ namespace JuiceAgent::services
void start();
} // namespace JarLoader
namespace Bytecode
{
void init();
void start();
}
} // namespace JuiceAgent::services
-4
View File
@@ -1,6 +1,5 @@
#include <libagent.hpp>
#include <jni_impl.hpp>
#include <bytecodes_opt.hpp>
#include <event/event_type.hpp>
#include <event/eventbus.hpp>
#include <JuiceAgent/Config.hpp>
@@ -82,9 +81,6 @@ namespace JuiceAgent {
PLOGE << "Failed to enable event notification: " << result;
}
// register bytecodes_opt
JuiceAgent::Bytecodes::register_bytecodes();
// Loaded Event
eventbus.post(EventLoaded{
.jvm = jvm,
@@ -1,16 +1,8 @@
#include <bytecodes_opt.hpp>
#include <services.hpp>
#include <jni_impl.hpp>
#include <event/event_type.hpp>
namespace JuiceAgent::Bytecodes {
void register_bytecodes() {
auto& agent = JuiceAgent::Agent::instance();
agent.get_eventbus().subscribe<EventClassFileLoadHook>(capture_bytecodes);
agent.get_eventbus().subscribe<EventClassFileLoadHook>(patch_bytecodes);
}
void capture_bytecodes(const EventClassFileLoadHook& e) {
namespace JuiceAgent::services::Bytecode {
void capture_bytecodes(const EventClassFileLoadHook& e) {
/* =========================
* 1. Capture original bytes
* ========================= */
@@ -56,4 +48,14 @@ namespace JuiceAgent::Bytecodes {
PLOGI << "Retransformed: " << e.name << " (new length: " << bytes.size() << ")";
}
}
void init() {
agent.get_eventbus().subscribe<EventClassFileLoadHook>(capture_bytecodes);
agent.get_eventbus().subscribe<EventClassFileLoadHook>(patch_bytecodes);
}
void start() {
}
}
@@ -19,12 +19,17 @@ namespace JuiceAgent::services::Manager {
// JarLoader
JuiceAgent::services::JarLoader::init();
// Bytecode
JuiceAgent::services::Bytecode::init();
}
void start(const EventLoaded& event) {
PLOGI << "Starting services";
// JarLoader
JuiceAgent::services::JarLoader::start();
// Bytecode
JuiceAgent::services::Bytecode::start();
}
void stop() {