2021-12-06 10:49:40 +08:00
|
|
|
package com.janetfilter.core;
|
2021-11-30 17:06:48 +08:00
|
|
|
|
2021-12-06 10:49:40 +08:00
|
|
|
import com.janetfilter.core.commons.DebugInfo;
|
|
|
|
import com.janetfilter.core.plugin.PluginManager;
|
2021-11-30 17:06:48 +08:00
|
|
|
|
|
|
|
import java.lang.instrument.Instrumentation;
|
2021-12-02 10:58:59 +08:00
|
|
|
import java.util.Set;
|
2021-11-30 17:06:48 +08:00
|
|
|
|
|
|
|
public class Initializer {
|
2021-12-27 14:16:35 +08:00
|
|
|
public static void init(Instrumentation inst, Environment environment) {
|
2022-01-13 19:31:41 +08:00
|
|
|
DebugInfo.output(environment.toString());
|
|
|
|
|
2021-12-06 10:49:40 +08:00
|
|
|
Dispatcher dispatcher = new Dispatcher();
|
2021-12-27 14:16:35 +08:00
|
|
|
new PluginManager(inst, dispatcher, environment).loadPlugins();
|
2021-11-30 17:06:48 +08:00
|
|
|
|
2021-12-06 10:49:40 +08:00
|
|
|
inst.addTransformer(dispatcher, true);
|
2021-12-01 11:35:06 +08:00
|
|
|
|
2021-12-06 10:49:40 +08:00
|
|
|
Set<String> classSet = dispatcher.getHookClassNames();
|
2021-11-30 17:06:48 +08:00
|
|
|
for (Class<?> c : inst.getAllLoadedClasses()) {
|
2021-12-01 12:33:37 +08:00
|
|
|
String name = c.getName();
|
2021-12-06 10:49:40 +08:00
|
|
|
if (!classSet.contains(name)) {
|
2021-12-01 12:33:37 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-11-30 17:06:48 +08:00
|
|
|
try {
|
|
|
|
inst.retransformClasses(c);
|
2021-12-01 12:33:37 +08:00
|
|
|
} catch (Throwable e) {
|
2021-12-28 15:02:34 +08:00
|
|
|
DebugInfo.output("Retransform class failed: " + name, e);
|
2021-11-30 17:06:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|