Signed-off-by: Faumaray <faumaray@gmail.com>
This commit is contained in:
12 files changed
+647
-17
No files matched your search
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include <jvmti.h>
|
||||
#include <string>
|
||||
|
||||
class ClassTransformer {
|
||||
public:
|
||||
static void JNICALL classFileLoadHook(jvmtiEnv* jvmti, JNIEnv* jni,
|
||||
jclass class_being_redefined,
|
||||
jobject loader, const char* name,
|
||||
jobject protection_domain,
|
||||
jint class_data_len,
|
||||
const unsigned char* class_data,
|
||||
jint* new_class_data_len,
|
||||
unsigned char** new_class_data);
|
||||
|
||||
private:
|
||||
static bool shouldTransform(const std::string& class_name);
|
||||
static bool transformClass(jvmtiEnv* jvmti,
|
||||
const unsigned char* original_data,
|
||||
jint original_len,
|
||||
unsigned char** new_data,
|
||||
jint* new_len);
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include <jvmti.h>
|
||||
#include <jni.h>
|
||||
#include <iostream>
|
||||
|
||||
class JvmtiHandler {
|
||||
public:
|
||||
static void JNICALL vmInit(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread);
|
||||
static void JNICALL vmDeath(jvmtiEnv* jvmti, JNIEnv* jni);
|
||||
|
||||
// Accessor methods for global variables
|
||||
static jvmtiEnv* getJvmti();
|
||||
static JavaVM* getJavaVM();
|
||||
static bool isAgentInitialized();
|
||||
|
||||
// Setter methods
|
||||
static void setJvmti(jvmtiEnv* jvmti);
|
||||
static void setJavaVM(JavaVM* jvm);
|
||||
static void setAgentInitialized(bool initialized);
|
||||
|
||||
private:
|
||||
// No global variable declarations here - they'll be in agent.cpp
|
||||
};
|
||||
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
#include <jvmti.h>
|
||||
|
||||
enum class ModType {
|
||||
JAR, // Java/bytecode mod
|
||||
NATIVE // Native C++ mod
|
||||
};
|
||||
|
||||
struct ModInfo {
|
||||
std::string name;
|
||||
std::string version;
|
||||
std::string file_path;
|
||||
ModType type;
|
||||
bool enabled;
|
||||
|
||||
// Mod metadata (from fabric.mod.json or similar)
|
||||
std::string author;
|
||||
std::string description;
|
||||
std::vector<std::string> dependencies;
|
||||
};
|
||||
|
||||
class ModManager {
|
||||
public:
|
||||
ModManager();
|
||||
~ModManager();
|
||||
|
||||
// Discover and load mods from directory
|
||||
void discoverMods(const std::string& mods_dir);
|
||||
|
||||
// Load a single mod
|
||||
void loadMod(const std::filesystem::path& mod_path);
|
||||
|
||||
// Apply transformations from all mods to a class
|
||||
void applyTransformations(
|
||||
const std::string& class_name,
|
||||
const unsigned char* class_data,
|
||||
jint class_data_len
|
||||
);
|
||||
|
||||
// Get list of loaded mods
|
||||
const std::vector<ModInfo>& getLoadedMods() const;
|
||||
|
||||
// Enable/disable a mod
|
||||
void setModEnabled(const std::string& mod_name, bool enabled);
|
||||
|
||||
private:
|
||||
std::vector<ModInfo> loaded_mods;
|
||||
|
||||
// Parse mod metadata
|
||||
void parseJarMod(const std::filesystem::path& jar_path, ModInfo& mod);
|
||||
void parseNativeMod(const std::filesystem::path& native_path, ModInfo& mod);
|
||||
};
|
||||
Reference in new issue
Block a user