Compare commits

..

2 Commits
v1.0 ... main

4 changed files with 29 additions and 14 deletions

View File

@ -15,5 +15,5 @@ This is pretty straightforward, just make a `.jar` file with the contents of the
## Using ## Using
Simple, just add `-javaagent:path/to/the/built.jar` before `.jar` when you start the launcher located in the `~/paladium-games` folder. Simple, just add `-javaagent:path/to/the/built.jar` before `-jar` when you start the launcher located in the `~/paladium-games` folder.
Also be sure to use Java 8 for better compatibility. Also be sure to use Java 8 for better compatibility.

View File

@ -12,7 +12,6 @@
<maven.compiler.target>1.7</maven.compiler.target> <maven.compiler.target>1.7</maven.compiler.target>
</properties> </properties>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>

View File

@ -4,27 +4,45 @@ import java.lang.instrument.Instrumentation;
import java.lang.instrument.UnmodifiableClassException; import java.lang.instrument.UnmodifiableClassException;
import java.lang.Class; import java.lang.Class;
import java.lang.String; import java.lang.String;
import java.lang.Exception;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
import net.x3f200c.pala4linux.launcherpatch.LauncherPatcher; import net.x3f200c.pala4linux.launcherpatch.LauncherPatcher;
public class LauncherPatch { public class LauncherPatch {
public static void premain(String agentArgs, Instrumentation inst) { public static void premain(String agentArgs, Instrumentation inst) {
try {
prepareCertificates();
} catch (Exception e) {
System.out.println("[PalaLauncher4Linux] Failed to prepare certificates. ");
}
patch(inst); patch(inst);
} }
public static void agentmain(String agentArgs, Instrumentation inst) { public static void agentmain(String agentArgs, Instrumentation inst) {
try {
prepareCertificates();
} catch (Exception e) {
System.out.println("[PalaLauncher4Linux] Failed to prepare certificates. ");
}
patch(inst); patch(inst);
} }
public static void prepareCertificates() throws Exception {
URL apacheMavenRepository = new URL("https://repo.maven.apache.org");
HttpsURLConnection connection = (HttpsURLConnection) apacheMavenRepository.openConnection();
connection.connect();
connection.disconnect();
}
public static void patch(Instrumentation inst) { public static void patch(Instrumentation inst) {
Class<?> routeHandlerClass = null; Class<?> routeHandlerClass = null;
ClassLoader routeHandlerClassLoader = null;
try { try {
routeHandlerClass = Class.forName("fr.paladium.router.route.common.CommonRoute"); routeHandlerClass = Class.forName("fr.paladium.router.route.common.CommonRoute");
routeHandlerClassLoader = routeHandlerClass.getClassLoader();
} catch(ClassNotFoundException e) { } catch(ClassNotFoundException e) {
} }
LauncherPatcher dt = new LauncherPatcher(routeHandlerClass.getName(), routeHandlerClassLoader); LauncherPatcher dt = new LauncherPatcher(routeHandlerClass.getName());
inst.addTransformer(dt, true); inst.addTransformer(dt, true);

View File

@ -10,24 +10,22 @@ import javassist.NotFoundException;
import javassist.CannotCompileException; import javassist.CannotCompileException;
class LauncherPatcher implements ClassFileTransformer { class LauncherPatcher implements ClassFileTransformer {
private final String targetClassName; private final String routeTargetClassName;
public LauncherPatcher(String className, ClassLoader classLoader) { public LauncherPatcher(String routerClassName) {
this.targetClassName = className; this.routeTargetClassName = routerClassName;
} }
@Override @Override
public byte[] transform(ClassLoader loader, String className, Class<?> redefinedClass, ProtectionDomain protectionDomain, byte[] classBuffer) { public byte[] transform(ClassLoader loader, String className, Class<?> redefinedClass, ProtectionDomain protectionDomain, byte[] classBuffer) {
byte[] bytecode = classBuffer; byte[] bytecode = classBuffer;
String finalTargetClassName = this.targetClassName.replaceAll("\\.", "/"); ClassPool cp = ClassPool.getDefault();
if (!className.equals(finalTargetClassName)) {
return bytecode;
}
if (className.equals(finalTargetClassName)) { String finalRouterClassName = this.routeTargetClassName.replaceAll("\\.", "/");
if (className.equals(finalRouterClassName)) {
try { try {
ClassPool cp = ClassPool.getDefault();
CtClass crClass = cp.get("fr.paladium.router.route.common.CommonRoute"); CtClass crClass = cp.get("fr.paladium.router.route.common.CommonRoute");
CtMethod osGetterMethod = crClass.getDeclaredMethod("handleGetOS"); CtMethod osGetterMethod = crClass.getDeclaredMethod("handleGetOS");