Refine code and try to add SSL certificate fix

This commit is contained in:
X3F200C 2024-03-21 22:26:21 -04:00
parent 7eb2aeff75
commit fa7205ca0a
3 changed files with 28 additions and 13 deletions

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");