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>
</properties>
<plugins>
<plugin>
<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.Class;
import java.lang.String;
import java.lang.Exception;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
import net.x3f200c.pala4linux.launcherpatch.LauncherPatcher;
public class LauncherPatch {
public static void premain(String agentArgs, Instrumentation inst) {
try {
prepareCertificates();
} catch (Exception e) {
System.out.println("[PalaLauncher4Linux] Failed to prepare certificates. ");
}
patch(inst);
}
public static void agentmain(String agentArgs, Instrumentation inst) {
try {
prepareCertificates();
} catch (Exception e) {
System.out.println("[PalaLauncher4Linux] Failed to prepare certificates. ");
}
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) {
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);
LauncherPatcher dt = new LauncherPatcher(routeHandlerClass.getName());
inst.addTransformer(dt, true);

View File

@ -10,24 +10,22 @@ import javassist.NotFoundException;
import javassist.CannotCompileException;
class LauncherPatcher implements ClassFileTransformer {
private final String targetClassName;
private final String routeTargetClassName;
public LauncherPatcher(String className, ClassLoader classLoader) {
this.targetClassName = className;
public LauncherPatcher(String routerClassName) {
this.routeTargetClassName = routerClassName;
}
@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;
}
ClassPool cp = ClassPool.getDefault();
if (className.equals(finalTargetClassName)) {
String finalRouterClassName = this.routeTargetClassName.replaceAll("\\.", "/");
if (className.equals(finalRouterClassName)) {
try {
ClassPool cp = ClassPool.getDefault();
CtClass crClass = cp.get("fr.paladium.router.route.common.CommonRoute");
CtMethod osGetterMethod = crClass.getDeclaredMethod("handleGetOS");