mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-28 04:25:27 +00:00
Update snet extension
This commit is contained in:
parent
c5a7ab2415
commit
499a157946
@ -23,6 +23,7 @@ import com.topjohnwu.magisk.asyncs.CheckUpdates;
|
|||||||
import com.topjohnwu.magisk.components.AlertDialogBuilder;
|
import com.topjohnwu.magisk.components.AlertDialogBuilder;
|
||||||
import com.topjohnwu.magisk.components.ExpandableView;
|
import com.topjohnwu.magisk.components.ExpandableView;
|
||||||
import com.topjohnwu.magisk.components.Fragment;
|
import com.topjohnwu.magisk.components.Fragment;
|
||||||
|
import com.topjohnwu.magisk.utils.ISafetyNetHelper;
|
||||||
import com.topjohnwu.magisk.utils.Const;
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
import com.topjohnwu.magisk.utils.RootUtils;
|
import com.topjohnwu.magisk.utils.RootUtils;
|
||||||
import com.topjohnwu.magisk.utils.ShowUI;
|
import com.topjohnwu.magisk.utils.ShowUI;
|
||||||
@ -39,14 +40,6 @@ import butterknife.Unbinder;
|
|||||||
public class MagiskFragment extends Fragment
|
public class MagiskFragment extends Fragment
|
||||||
implements Topic.Subscriber, SwipeRefreshLayout.OnRefreshListener, ExpandableView {
|
implements Topic.Subscriber, SwipeRefreshLayout.OnRefreshListener, ExpandableView {
|
||||||
|
|
||||||
private static final int CAUSE_SERVICE_DISCONNECTED = 0x01;
|
|
||||||
private static final int CAUSE_NETWORK_LOST = 0x02;
|
|
||||||
private static final int RESPONSE_ERR = 0x04;
|
|
||||||
private static final int CONNECTION_FAIL = 0x08;
|
|
||||||
|
|
||||||
private static final int BASIC_PASS = 0x10;
|
|
||||||
private static final int CTS_PASS = 0x20;
|
|
||||||
|
|
||||||
private Container expandableContainer = new Container();
|
private Container expandableContainer = new Container();
|
||||||
|
|
||||||
private MagiskManager mm;
|
private MagiskManager mm;
|
||||||
@ -285,12 +278,12 @@ public class MagiskFragment extends Fragment
|
|||||||
safetyNetStatusText.setText(R.string.safetyNet_check_success);
|
safetyNetStatusText.setText(R.string.safetyNet_check_success);
|
||||||
|
|
||||||
boolean b;
|
boolean b;
|
||||||
b = (response & CTS_PASS) != 0;
|
b = (response & ISafetyNetHelper.CTS_PASS) != 0;
|
||||||
ctsStatusText.setText("ctsProfile: " + b);
|
ctsStatusText.setText("ctsProfile: " + b);
|
||||||
ctsStatusIcon.setImageResource(b ? R.drawable.ic_check_circle : R.drawable.ic_cancel);
|
ctsStatusIcon.setImageResource(b ? R.drawable.ic_check_circle : R.drawable.ic_cancel);
|
||||||
ctsStatusIcon.setColorFilter(b ? colorOK : colorBad);
|
ctsStatusIcon.setColorFilter(b ? colorOK : colorBad);
|
||||||
|
|
||||||
b = (response & BASIC_PASS) != 0;
|
b = (response & ISafetyNetHelper.BASIC_PASS) != 0;
|
||||||
basicStatusText.setText("basicIntegrity: " + b);
|
basicStatusText.setText("basicIntegrity: " + b);
|
||||||
basicStatusIcon.setImageResource(b ? R.drawable.ic_check_circle : R.drawable.ic_cancel);
|
basicStatusIcon.setImageResource(b ? R.drawable.ic_check_circle : R.drawable.ic_cancel);
|
||||||
basicStatusIcon.setColorFilter(b ? colorOK : colorBad);
|
basicStatusIcon.setColorFilter(b ? colorOK : colorBad);
|
||||||
@ -299,16 +292,16 @@ public class MagiskFragment extends Fragment
|
|||||||
} else {
|
} else {
|
||||||
@StringRes int resid;
|
@StringRes int resid;
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case CAUSE_SERVICE_DISCONNECTED:
|
case ISafetyNetHelper.CAUSE_SERVICE_DISCONNECTED:
|
||||||
resid = R.string.safetyNet_network_loss;
|
resid = R.string.safetyNet_network_loss;
|
||||||
break;
|
break;
|
||||||
case CAUSE_NETWORK_LOST:
|
case ISafetyNetHelper.CAUSE_NETWORK_LOST:
|
||||||
resid = R.string.safetyNet_service_disconnected;
|
resid = R.string.safetyNet_service_disconnected;
|
||||||
break;
|
break;
|
||||||
case RESPONSE_ERR:
|
case ISafetyNetHelper.RESPONSE_ERR:
|
||||||
resid = R.string.safetyNet_res_invalid;
|
resid = R.string.safetyNet_res_invalid;
|
||||||
break;
|
break;
|
||||||
case CONNECTION_FAIL:
|
case ISafetyNetHelper.CONNECTION_FAIL:
|
||||||
default:
|
default:
|
||||||
resid = R.string.safetyNet_api_error;
|
resid = R.string.safetyNet_api_error;
|
||||||
break;
|
break;
|
||||||
|
@ -3,6 +3,7 @@ package com.topjohnwu.magisk.asyncs;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
|
import com.topjohnwu.magisk.utils.ISafetyNetHelper;
|
||||||
import com.topjohnwu.magisk.utils.Const;
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
import com.topjohnwu.magisk.utils.WebService;
|
import com.topjohnwu.magisk.utils.WebService;
|
||||||
import com.topjohnwu.superuser.Shell;
|
import com.topjohnwu.superuser.Shell;
|
||||||
@ -15,7 +16,6 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
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.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
|
||||||
import dalvik.system.DexClassLoader;
|
import dalvik.system.DexClassLoader;
|
||||||
@ -24,32 +24,33 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
|
|||||||
|
|
||||||
public static final File dexPath =
|
public static final File dexPath =
|
||||||
new File(MagiskManager.get().getFilesDir().getParent() + "/snet", "snet.apk");
|
new File(MagiskManager.get().getFilesDir().getParent() + "/snet", "snet.apk");
|
||||||
private DexClassLoader loader;
|
private ISafetyNetHelper helper;
|
||||||
private Class<?> helperClazz, callbackClazz;
|
|
||||||
|
|
||||||
public CheckSafetyNet(Activity activity) {
|
public CheckSafetyNet(Activity activity) {
|
||||||
super(activity);
|
super(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dlSnet() throws IOException {
|
private void dlSnet() throws Exception {
|
||||||
Shell.Sync.sh("rm -rf " + dexPath.getParent());
|
Shell.Sync.sh("rm -rf " + dexPath.getParent());
|
||||||
HttpURLConnection conn = WebService.request(Const.Url.SNET_URL, null);
|
|
||||||
dexPath.getParentFile().mkdir();
|
dexPath.getParentFile().mkdir();
|
||||||
|
HttpURLConnection conn = WebService.request(Const.Url.SNET_URL, null);
|
||||||
try (
|
try (
|
||||||
OutputStream out = new BufferedOutputStream(new FileOutputStream(dexPath));
|
OutputStream out = new BufferedOutputStream(new FileOutputStream(dexPath));
|
||||||
InputStream in = new BufferedInputStream(conn.getInputStream())) {
|
InputStream in = new BufferedInputStream(conn.getInputStream())) {
|
||||||
ShellUtils.pump(in, out);
|
ShellUtils.pump(in, out);
|
||||||
|
} finally {
|
||||||
|
conn.disconnect();
|
||||||
}
|
}
|
||||||
conn.disconnect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dyload() throws Exception {
|
private void dyload() throws Exception {
|
||||||
loader = new DexClassLoader(dexPath.getPath(), dexPath.getParent(),
|
DexClassLoader loader = new DexClassLoader(dexPath.getPath(), dexPath.getParent(),
|
||||||
null, ClassLoader.getSystemClassLoader());
|
null, ISafetyNetHelper.class.getClassLoader());
|
||||||
helperClazz = loader.loadClass(Const.SNET_PKG + ".SafetyNetHelper");
|
Class<?> clazz = loader.loadClass("com.topjohnwu.snet.SafetyNetHelper");
|
||||||
callbackClazz = loader.loadClass(Const.SNET_PKG + ".SafetyNetCallback");
|
helper = (ISafetyNetHelper) clazz.getConstructors()[0]
|
||||||
int snet_ver = (int) helperClazz.getMethod("getVersion").invoke(null);
|
.newInstance(getActivity(), (ISafetyNetHelper.Callback)
|
||||||
if (snet_ver != Const.SNET_VER) {
|
code -> MagiskManager.get().safetyNetDone.publish(false, code));
|
||||||
|
if (helper.getVersion() != Const.SNET_VER) {
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -72,21 +73,13 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Exception err) {
|
protected void onPostExecute(Exception e) {
|
||||||
MagiskManager mm = MagiskManager.get();
|
if (e == null) {
|
||||||
try {
|
helper.attest();
|
||||||
if (err != null) throw err;
|
} else {
|
||||||
Object helper = helperClazz.getConstructors()[0].newInstance(
|
|
||||||
getActivity(), dexPath.getPath(), Proxy.newProxyInstance(
|
|
||||||
loader, new Class[] { callbackClazz }, (proxy, method, args) -> {
|
|
||||||
mm.safetyNetDone.publish(false, args[0]);
|
|
||||||
return null;
|
|
||||||
}));
|
|
||||||
helperClazz.getMethod("attest").invoke(helper);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
mm.safetyNetDone.publish(false, -1);
|
MagiskManager.get().safetyNetDone.publish(false, -1);
|
||||||
}
|
}
|
||||||
super.onPostExecute(err);
|
super.onPostExecute(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ public abstract class FlavorActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private AssetManager swappedAssetManager = null;
|
private AssetManager swappedAssetManager = null;
|
||||||
private Resources swappedResources = null;
|
private Resources swappedResources = null;
|
||||||
private Resources.Theme swappedTheme = null;
|
private Resources.Theme backupTheme = null;
|
||||||
|
|
||||||
@StyleRes
|
@StyleRes
|
||||||
public int getDarkTheme() {
|
public int getDarkTheme() {
|
||||||
@ -25,7 +25,7 @@ public abstract class FlavorActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MagiskManager getMagiskManager() {
|
public MagiskManager getMagiskManager() {
|
||||||
return (MagiskManager) super.getApplicationContext();
|
return (MagiskManager) super.getApplication();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -48,17 +48,6 @@ public abstract class FlavorActivity extends AppCompatActivity {
|
|||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AssetManager getAssets(String apk) {
|
|
||||||
try {
|
|
||||||
AssetManager asset = AssetManager.class.newInstance();
|
|
||||||
AssetManager.class.getMethod("addAssetPath", String.class).invoke(asset, apk);
|
|
||||||
return asset;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setFloating() {
|
protected void setFloating() {
|
||||||
boolean isTablet = getResources().getBoolean(R.bool.isTablet);
|
boolean isTablet = getResources().getBoolean(R.bool.isTablet);
|
||||||
if (isTablet) {
|
if (isTablet) {
|
||||||
@ -75,7 +64,7 @@ public abstract class FlavorActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resources.Theme getTheme() {
|
public Resources.Theme getTheme() {
|
||||||
return swappedTheme == null ? super.getTheme() : swappedTheme;
|
return backupTheme == null ? super.getTheme() : backupTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -83,26 +72,37 @@ public abstract class FlavorActivity extends AppCompatActivity {
|
|||||||
return swappedAssetManager == null ? super.getAssets() : swappedAssetManager;
|
return swappedAssetManager == null ? super.getAssets() : swappedAssetManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AssetManager getAssets(String apk) {
|
||||||
|
try {
|
||||||
|
AssetManager asset = AssetManager.class.newInstance();
|
||||||
|
AssetManager.class.getMethod("addAssetPath", String.class).invoke(asset, apk);
|
||||||
|
return asset;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Resources getResources() {
|
public Resources getResources() {
|
||||||
return swappedResources == null ? super.getResources() : swappedResources;
|
return swappedResources == null ? super.getResources() : swappedResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Keep
|
@Keep
|
||||||
public void swapResources(String dexPath, int resId) {
|
public void swapResources(String dexPath) {
|
||||||
swappedAssetManager = getAssets(dexPath);
|
AssetManager asset = getAssets(dexPath);
|
||||||
if (swappedAssetManager == null)
|
if (asset != null) {
|
||||||
return;
|
backupTheme = super.getTheme();
|
||||||
Resources res = super.getResources();
|
Resources res = super.getResources();
|
||||||
swappedResources = new Resources(swappedAssetManager, res.getDisplayMetrics(), res.getConfiguration());
|
swappedResources = new Resources(asset, res.getDisplayMetrics(), res.getConfiguration());
|
||||||
swappedTheme = swappedResources.newTheme();
|
swappedAssetManager = asset;
|
||||||
swappedTheme.applyStyle(resId, true);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Keep
|
@Keep
|
||||||
public void restoreResources() {
|
public void restoreResources() {
|
||||||
swappedAssetManager = null;
|
swappedAssetManager = null;
|
||||||
swappedResources = null;
|
swappedResources = null;
|
||||||
swappedTheme = null;
|
backupTheme = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.topjohnwu.magisk.utils;
|
||||||
|
|
||||||
|
import android.support.annotation.Keep;
|
||||||
|
|
||||||
|
public interface ISafetyNetHelper {
|
||||||
|
|
||||||
|
int CAUSE_SERVICE_DISCONNECTED = 0x01;
|
||||||
|
int CAUSE_NETWORK_LOST = 0x02;
|
||||||
|
int RESPONSE_ERR = 0x04;
|
||||||
|
int CONNECTION_FAIL = 0x08;
|
||||||
|
|
||||||
|
int BASIC_PASS = 0x10;
|
||||||
|
int CTS_PASS = 0x20;
|
||||||
|
|
||||||
|
void attest();
|
||||||
|
int getVersion();
|
||||||
|
|
||||||
|
interface Callback {
|
||||||
|
@Keep
|
||||||
|
void onResponse(int responseCode);
|
||||||
|
}
|
||||||
|
}
|
@ -14,7 +14,6 @@ public class Const {
|
|||||||
|
|
||||||
public static final String DEBUG_TAG = "MagiskManager";
|
public static final String DEBUG_TAG = "MagiskManager";
|
||||||
public static final String ORIG_PKG_NAME = BuildConfig.APPLICATION_ID;
|
public static final String ORIG_PKG_NAME = BuildConfig.APPLICATION_ID;
|
||||||
public static final String SNET_PKG = "com.topjohnwu.snet";
|
|
||||||
public static final String MAGISKHIDE_PROP = "persist.magisk.hide";
|
public static final String MAGISKHIDE_PROP = "persist.magisk.hide";
|
||||||
|
|
||||||
// APK content
|
// APK content
|
||||||
@ -37,7 +36,7 @@ public class Const {
|
|||||||
|
|
||||||
// Versions
|
// Versions
|
||||||
public static final int UPDATE_SERVICE_VER = 1;
|
public static final int UPDATE_SERVICE_VER = 1;
|
||||||
public static final int SNET_VER = 7;
|
public static final int SNET_VER = 8;
|
||||||
|
|
||||||
public static int MIN_MODULE_VER() {
|
public static int MIN_MODULE_VER() {
|
||||||
return MagiskManager.get().magiskVersionCode >= MAGISK_VER.REMOVE_LEGACY_LINK ? 1500 : 1400;
|
return MagiskManager.get().magiskVersionCode >= MAGISK_VER.REMOVE_LEGACY_LINK ? 1500 : 1400;
|
||||||
@ -81,7 +80,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/a82a5e5a49285df65da91d2e8b24f4783841b515/snet.apk";
|
public static final String SNET_URL = "https://github.com/topjohnwu/MagiskManager/raw/788f01f499714471949613820d43bc364786e85d/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";
|
||||||
|
Loading…
Reference in New Issue
Block a user