Add TrustMeAlready

This commit is contained in:
方块君 2022-05-12 22:57:37 +08:00
parent 68e39ccbfa
commit 3aa837b62a
2 changed files with 78 additions and 0 deletions

View File

@ -85,6 +85,7 @@ class MainHook : IXposedHookLoadPackage, IXposedHookZygoteInit {
override fun initZygote(startupParam: IXposedHookZygoteInit.StartupParam) { override fun initZygote(startupParam: IXposedHookZygoteInit.StartupParam) {
modulePath = startupParam.modulePath modulePath = startupParam.modulePath
moduleRes = XModuleResources.createInstance(modulePath, null) moduleRes = XModuleResources.createInstance(modulePath, null)
TrustMeAlready().initZygote(startupParam)
} }
@SuppressLint("WrongConstant", "ClickableViewAccessibility") @SuppressLint("WrongConstant", "ClickableViewAccessibility")

View File

@ -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<Object> 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<X509Certificate>();
}
});
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;
}
}