From fb5e8ef40c2a2be9b630459859186c14258867bf Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 5 Apr 2018 20:52:34 +0800 Subject: [PATCH] Improve handling of snet extention --- .../magisk/asyncs/CheckSafetyNet.java | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/topjohnwu/magisk/asyncs/CheckSafetyNet.java b/src/main/java/com/topjohnwu/magisk/asyncs/CheckSafetyNet.java index 8899755b5..603c7aefb 100644 --- a/src/main/java/com/topjohnwu/magisk/asyncs/CheckSafetyNet.java +++ b/src/main/java/com/topjohnwu/magisk/asyncs/CheckSafetyNet.java @@ -43,31 +43,26 @@ public class CheckSafetyNet extends ParallelTask { conn.disconnect(); } - private void loadClasses() throws ClassNotFoundException { - loader = new DexClassLoader(dexPath.toString(), dexPath.getParent(), + private void dyload() throws ReflectiveOperationException { + loader = new DexClassLoader(dexPath.getPath(), dexPath.getParent(), null, ClassLoader.getSystemClassLoader()); helperClazz = loader.loadClass(Const.SNET_PKG + ".SafetyNetHelper"); callbackClazz = loader.loadClass(Const.SNET_PKG + ".SafetyNetCallback"); + int snet_ver = (int) helperClazz.getMethod("getVersion").invoke(null); + if (snet_ver != Const.SNET_VER) { + throw new ReflectiveOperationException(); + } } @Override protected Exception doInBackground(Void... voids) { - int snet_ver = -1; - try { - if (!dexPath.exists()) - dlSnet(); - loadClasses(); - try { - snet_ver = (int) helperClazz.getMethod("getVersion").invoke(null); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } - - if (snet_ver != Const.SNET_VER) { + dyload(); + } catch (ReflectiveOperationException e) { + // If dynamic load failed, try re-downloading and reload dlSnet(); - loadClasses(); + dyload(); } } catch (Exception e) { return e;