Refine code and try to add SSL certificate fix
This commit is contained in:
parent
7eb2aeff75
commit
fa7205ca0a
1
pom.xml
1
pom.xml
@ -12,7 +12,6 @@
|
||||
<maven.compiler.target>1.7</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
if (className.equals(finalTargetClassName)) {
|
||||
try {
|
||||
ClassPool cp = ClassPool.getDefault();
|
||||
|
||||
String finalRouterClassName = this.routeTargetClassName.replaceAll("\\.", "/");
|
||||
|
||||
if (className.equals(finalRouterClassName)) {
|
||||
try {
|
||||
CtClass crClass = cp.get("fr.paladium.router.route.common.CommonRoute");
|
||||
CtMethod osGetterMethod = crClass.getDeclaredMethod("handleGetOS");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user