mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-01-12 11:33:37 +00:00
Add version check within binary
This commit is contained in:
parent
a82a5e5a49
commit
b2483ba437
@ -12,6 +12,7 @@ import java.io.BufferedInputStream;
|
|||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.lang.reflect.Proxy;
|
import java.lang.reflect.Proxy;
|
||||||
@ -23,26 +24,15 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
|
|||||||
|
|
||||||
private File dexPath;
|
private File dexPath;
|
||||||
private DexClassLoader loader;
|
private DexClassLoader loader;
|
||||||
|
private Class<?> helperClazz, callbackClazz;
|
||||||
|
|
||||||
public CheckSafetyNet(Activity activity) {
|
public CheckSafetyNet(Activity activity) {
|
||||||
super(activity);
|
super(activity);
|
||||||
dexPath = new File(activity.getCacheDir().getParent() + "/snet", "snet.apk");
|
dexPath = new File(activity.getCacheDir().getParent() + "/snet", "snet.apk");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void dlSnet() throws IOException {
|
||||||
protected void onPreExecute() {
|
|
||||||
MagiskManager mm = MagiskManager.get();
|
|
||||||
if (mm.snetVersion != Const.Value.SNET_VER) {
|
|
||||||
Shell.sh("rm -rf " + dexPath.getParent());
|
Shell.sh("rm -rf " + dexPath.getParent());
|
||||||
}
|
|
||||||
mm.snetVersion = Const.Value.SNET_VER;
|
|
||||||
mm.prefs.edit().putInt(Const.Key.SNET_VER, Const.Value.SNET_VER).apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Exception doInBackground(Void... voids) {
|
|
||||||
try {
|
|
||||||
if (!dexPath.exists()) {
|
|
||||||
HttpURLConnection conn = WebService.request(Const.Url.SNET_URL, null);
|
HttpURLConnection conn = WebService.request(Const.Url.SNET_URL, null);
|
||||||
dexPath.getParentFile().mkdir();
|
dexPath.getParentFile().mkdir();
|
||||||
try (
|
try (
|
||||||
@ -52,21 +42,47 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
|
|||||||
}
|
}
|
||||||
conn.disconnect();
|
conn.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadClasses() throws ClassNotFoundException {
|
||||||
loader = new DexClassLoader(dexPath.toString(), dexPath.getParent(),
|
loader = new DexClassLoader(dexPath.toString(), dexPath.getParent(),
|
||||||
null, ClassLoader.getSystemClassLoader());
|
null, ClassLoader.getSystemClassLoader());
|
||||||
|
helperClazz = loader.loadClass(Const.SNET_PKG + ".SafetyNetHelper");
|
||||||
|
callbackClazz = loader.loadClass(Const.SNET_PKG + ".SafetyNetCallback");
|
||||||
|
}
|
||||||
|
|
||||||
|
@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.Value.SNET_VER) {
|
||||||
|
dlSnet();
|
||||||
|
loadClasses();
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Exception err) {
|
protected void onPostExecute(Exception err) {
|
||||||
MagiskManager mm = MagiskManager.get();
|
MagiskManager mm = MagiskManager.get();
|
||||||
|
mm.snetVersion = Const.Value.SNET_VER;
|
||||||
|
mm.prefs.edit().putInt(Const.Key.SNET_VER, Const.Value.SNET_VER).apply();
|
||||||
try {
|
try {
|
||||||
if (err != null) throw err;
|
if (err != null) throw err;
|
||||||
Class<?> helperClazz = loader.loadClass(Const.SNET_PKG + ".SafetyNetHelper");
|
|
||||||
Class<?> callbackClazz = loader.loadClass(Const.SNET_PKG + ".SafetyNetCallback");
|
|
||||||
Object helper = helperClazz.getConstructors()[0].newInstance(
|
Object helper = helperClazz.getConstructors()[0].newInstance(
|
||||||
getActivity(), dexPath.getPath(), Proxy.newProxyInstance(
|
getActivity(), dexPath.getPath(), Proxy.newProxyInstance(
|
||||||
loader, new Class[] { callbackClazz }, (proxy, method, args) -> {
|
loader, new Class[] { callbackClazz }, (proxy, method, args) -> {
|
||||||
|
@ -84,7 +84,7 @@ public class Const {
|
|||||||
public static class Url {
|
public static class Url {
|
||||||
public static final String STABLE_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/stable.json";
|
public static final String STABLE_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/stable.json";
|
||||||
public static final String BETA_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/beta.json";
|
public static final String BETA_URL = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/beta.json";
|
||||||
public static final String SNET_URL = "https://github.com/topjohnwu/MagiskManager/raw/afff3c0a49cec8d797e486be3092e256b4bf5375/snet.apk";
|
public static final String SNET_URL = "https://github.com/topjohnwu/MagiskManager/raw/a82a5e5a49285df65da91d2e8b24f4783841b515/snet.apk";
|
||||||
public static final String REPO_URL = "https://api.github.com/users/Magisk-Modules-Repo/repos?per_page=100&page=%d";
|
public static final String REPO_URL = "https://api.github.com/users/Magisk-Modules-Repo/repos?per_page=100&page=%d";
|
||||||
public static final String FILE_URL = "https://raw.githubusercontent.com/Magisk-Modules-Repo/%s/master/%s";
|
public static final String FILE_URL = "https://raw.githubusercontent.com/Magisk-Modules-Repo/%s/master/%s";
|
||||||
public static final String ZIP_URL = "https://github.com/Magisk-Modules-Repo/%s/archive/master.zip";
|
public static final String ZIP_URL = "https://github.com/Magisk-Modules-Repo/%s/archive/master.zip";
|
||||||
@ -159,7 +159,7 @@ public class Const {
|
|||||||
public static final String FLASH_MAGISK = "magisk";
|
public static final String FLASH_MAGISK = "magisk";
|
||||||
public static final int[] timeoutList = {0, -1, 10, 20, 30, 60};
|
public static final int[] timeoutList = {0, -1, 10, 20, 30, 60};
|
||||||
public static final int UPDATE_SERVICE_VER = 1;
|
public static final int UPDATE_SERVICE_VER = 1;
|
||||||
public static final int SNET_VER = 6;
|
public static final int SNET_VER = 7;
|
||||||
public static final int MIN_MODULE_VER = 1400;
|
public static final int MIN_MODULE_VER = 1400;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user