Add the current files and make a README.md for those who are not coming from the tutorial or want to build this themselves
This commit is contained in:
@ -0,0 +1,37 @@
|
||||
package net.x3f200c.pala4linux.launcherpatch;
|
||||
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.lang.instrument.UnmodifiableClassException;
|
||||
import java.lang.Class;
|
||||
import java.lang.String;
|
||||
import net.x3f200c.pala4linux.launcherpatch.LauncherPatcher;
|
||||
|
||||
public class LauncherPatch {
|
||||
public static void premain(String agentArgs, Instrumentation inst) {
|
||||
patch(inst);
|
||||
}
|
||||
public static void agentmain(String agentArgs, Instrumentation inst) {
|
||||
patch(inst);
|
||||
}
|
||||
public static void patch(Instrumentation inst) {
|
||||
Class<?> routeHandlerClass = null;
|
||||
ClassLoader routeHandlerClassLoader = null;
|
||||
|
||||
try {
|
||||
routeHandlerClass = Class.forName("fr.paladium.router.route.common.CommonRoute");
|
||||
routeHandlerClassLoader = routeHandlerClass.getClassLoader();
|
||||
} catch(ClassNotFoundException e) {
|
||||
|
||||
}
|
||||
|
||||
LauncherPatcher dt = new LauncherPatcher(routeHandlerClass.getName(), routeHandlerClassLoader);
|
||||
|
||||
inst.addTransformer(dt, true);
|
||||
|
||||
try {
|
||||
inst.retransformClasses(routeHandlerClass);
|
||||
} catch(UnmodifiableClassException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package net.x3f200c.pala4linux.launcherpatch;
|
||||
|
||||
import java.lang.instrument.ClassFileTransformer;
|
||||
import java.io.IOException;
|
||||
import java.security.ProtectionDomain;
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.CtMethod;
|
||||
import javassist.NotFoundException;
|
||||
import javassist.CannotCompileException;
|
||||
|
||||
class LauncherPatcher implements ClassFileTransformer {
|
||||
private final String targetClassName;
|
||||
|
||||
public LauncherPatcher(String className, ClassLoader classLoader) {
|
||||
this.targetClassName = className;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(ClassLoader loader, String className, Class<?> redefinedClass, ProtectionDomain protectionDomain, byte[] classBuffer) {
|
||||
byte[] bytecode = classBuffer;
|
||||
|
||||
String finalTargetClassName = this.targetClassName.replaceAll("\\.", "/");
|
||||
if (!className.equals(finalTargetClassName)) {
|
||||
return bytecode;
|
||||
}
|
||||
|
||||
if (className.equals(finalTargetClassName)) {
|
||||
try {
|
||||
ClassPool cp = ClassPool.getDefault();
|
||||
CtClass crClass = cp.get("fr.paladium.router.route.common.CommonRoute");
|
||||
CtMethod osGetterMethod = crClass.getDeclaredMethod("handleGetOS");
|
||||
|
||||
osGetterMethod.setBody("{ return fr.paladium.router.handler.CefRouteHandler.create().success(\"os\", \"windows\"); }");
|
||||
|
||||
bytecode = crClass.toBytecode();
|
||||
crClass.detach();
|
||||
} catch(NotFoundException | CannotCompileException | IOException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return bytecode;
|
||||
}
|
||||
}
|
4
src/main/resources/META-INF/MANIFEST.MF
Normal file
4
src/main/resources/META-INF/MANIFEST.MF
Normal file
@ -0,0 +1,4 @@
|
||||
Agent-Class: net.x3f200c.pala4linux.launcherpatch.LauncherPatch
|
||||
Can-Redefine-Classes: true
|
||||
Can-Retransform-Classes: true
|
||||
Premain-Class: net.x3f200c.pala4linux.launcherpatch.LauncherPatch
|
Reference in New Issue
Block a user