diff --git a/app/src/main/java/xfk233/GenshinProxy/MainHook.kt b/app/src/main/java/xfk233/GenshinProxy/MainHook.kt index a9474bb..754793e 100644 --- a/app/src/main/java/xfk233/GenshinProxy/MainHook.kt +++ b/app/src/main/java/xfk233/GenshinProxy/MainHook.kt @@ -85,6 +85,7 @@ class MainHook : IXposedHookLoadPackage, IXposedHookZygoteInit { override fun initZygote(startupParam: IXposedHookZygoteInit.StartupParam) { modulePath = startupParam.modulePath moduleRes = XModuleResources.createInstance(modulePath, null) + TrustMeAlready().initZygote(startupParam) } @SuppressLint("WrongConstant", "ClickableViewAccessibility") diff --git a/app/src/main/java/xfk233/GenshinProxy/TrustMeAlready.java b/app/src/main/java/xfk233/GenshinProxy/TrustMeAlready.java new file mode 100644 index 0000000..9b97685 --- /dev/null +++ b/app/src/main/java/xfk233/GenshinProxy/TrustMeAlready.java @@ -0,0 +1,77 @@ +package xfk233.GenshinProxy; + +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; + +import de.robv.android.xposed.IXposedHookZygoteInit; +import de.robv.android.xposed.XC_MethodReplacement; +import de.robv.android.xposed.XposedBridge; + +import static de.robv.android.xposed.XposedHelpers.*; + +public class TrustMeAlready implements IXposedHookZygoteInit { + + private static final String SSL_CLASS_NAME = "com.android.org.conscrypt.TrustManagerImpl"; + private static final String SSL_METHOD_NAME = "checkTrustedRecursive"; + private static final Class SSL_RETURN_TYPE = List.class; + private static final Class SSL_RETURN_PARAM_TYPE = X509Certificate.class; + + @Override + public void initZygote(StartupParam startupParam) throws Throwable { + XposedBridge.log("TrustMeAlready loading..."); + int hookedMethods = 0; + + for (Method method : findClass(SSL_CLASS_NAME, null).getDeclaredMethods()) { + if (!checkSSLMethod(method)) { + continue; + } + + List params = new ArrayList<>(); + params.addAll(Arrays.asList(method.getParameterTypes())); + params.add(new XC_MethodReplacement() { + @Override + protected Object replaceHookedMethod(MethodHookParam param) throws Throwable { + return new ArrayList(); + } + }); + + XposedBridge.log("Hooking method:"); + XposedBridge.log(method.toString()); + findAndHookMethod(SSL_CLASS_NAME, null, SSL_METHOD_NAME, params.toArray()); + hookedMethods++; + } + + XposedBridge.log(String.format(Locale.ENGLISH, "TrustMeAlready loaded! Hooked %d methods", hookedMethods)); + } + + private boolean checkSSLMethod(Method method) { + if (!method.getName().equals(SSL_METHOD_NAME)) { + return false; + } + + // check return type + if (!SSL_RETURN_TYPE.isAssignableFrom(method.getReturnType())) { + return false; + } + + // check if parameterized return type + Type returnType = method.getGenericReturnType(); + if (!(returnType instanceof ParameterizedType)) { + return false; + } + + // check parameter type + Type[] args = ((ParameterizedType) returnType).getActualTypeArguments(); + if (args.length != 1 || !(args[0].equals(SSL_RETURN_PARAM_TYPE))) { + return false; + } + + return true; + } +} \ No newline at end of file