mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 13:05:53 +08:00
Refactor: auto-register services and inline BytecodeService
- add ServiceRegistry and JUICEAGENT_REGISTER_SERVICE macro so each service self-registers at static init; initializeAll() no longer includes concrete service headers - move BytecodeService class entirely into its .cpp (no header needed, only accessed via IService) - split ClassFileLoadHook handling into captureBytecodes and patchBytecodes listeners, registered in order
This commit is contained in:
1 parent
6962c4a477
commit
8e1b8b38e4
4 files changed
+98
-46
No files matched your search
@@ -1,32 +1,49 @@
|
||||
#include <services/bytecode_service.hpp>
|
||||
#include <services/base.hpp>
|
||||
#include <services/service_manager.hpp>
|
||||
#include <event/event_type.hpp>
|
||||
#include <JuiceAgent/Logger.hpp>
|
||||
|
||||
namespace JuiceAgent {
|
||||
namespace Services {
|
||||
|
||||
BytecodeService& BytecodeService::getInstance() {
|
||||
static BytecodeService instance;
|
||||
return instance;
|
||||
}
|
||||
class BytecodeService : public IService {
|
||||
public:
|
||||
const char* name() const override { return "BytecodeService"; }
|
||||
|
||||
bool BytecodeService::onInitialize() {
|
||||
listen<BytecodeService, EventClassFileLoadHook>(
|
||||
EventId::ClassFileLoadHook,
|
||||
&BytecodeService::onClassFileLoad
|
||||
);
|
||||
bool onInitialize() override {
|
||||
listen<BytecodeService, EventClassFileLoadHook>(
|
||||
EventId::ClassFileLoadHook,
|
||||
&BytecodeService::captureBytecodes
|
||||
);
|
||||
|
||||
spdlog::info("[BytecodeService] Initialized");
|
||||
return true;
|
||||
}
|
||||
listen<BytecodeService, EventClassFileLoadHook>(
|
||||
EventId::ClassFileLoadHook,
|
||||
&BytecodeService::patchBytecodes
|
||||
);
|
||||
|
||||
void BytecodeService::onShutdown() {
|
||||
spdlog::info("[BytecodeService] Shutdown");
|
||||
}
|
||||
spdlog::info("[BytecodeService] Initialized");
|
||||
return true;
|
||||
}
|
||||
|
||||
void BytecodeService::onClassFileLoad(const EventClassFileLoadHook& event) {
|
||||
spdlog::trace("[BytecodeService] ClassFileLoadHook: {}",
|
||||
event.name ? event.name : "<null>");
|
||||
}
|
||||
void onShutdown() override {
|
||||
spdlog::info("[BytecodeService] Shutdown");
|
||||
}
|
||||
|
||||
private:
|
||||
void captureBytecodes(const EventClassFileLoadHook& e) {
|
||||
// TODO: Capture original bytes
|
||||
spdlog::trace("[BytecodeService] Capture original bytes: {}",
|
||||
e.name ? e.name : "<null>");
|
||||
}
|
||||
|
||||
void patchBytecodes(const EventClassFileLoadHook& e) {
|
||||
// TODO: Apply patches
|
||||
spdlog::trace("[BytecodeService] Apply patches: {}",
|
||||
e.name ? e.name : "<null>");
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
JUICEAGENT_REGISTER_SERVICE(::JuiceAgent::Services::BytecodeService)
|
||||
Reference in new issue
Block a user