mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-23 18:15:30 +00:00
Update snet extension
This commit is contained in:
parent
e42b608444
commit
d2c196896d
@ -79,7 +79,7 @@
|
|||||||
<!-- Hardcode GMS version -->
|
<!-- Hardcode GMS version -->
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="com.google.android.gms.version"
|
android:name="com.google.android.gms.version"
|
||||||
android:value="7095000" />
|
android:value="12451000" />
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
@ -34,7 +34,6 @@ 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 = 10;
|
|
||||||
|
|
||||||
public static int MIN_MODULE_VER() {
|
public static int MIN_MODULE_VER() {
|
||||||
return Data.magiskVersionCode >= MAGISK_VER.REMOVE_LEGACY_LINK ? 1500 : 1400;
|
return Data.magiskVersionCode >= MAGISK_VER.REMOVE_LEGACY_LINK ? 1500 : 1400;
|
||||||
@ -76,7 +75,6 @@ public class Const {
|
|||||||
public static class Url {
|
public static class Url {
|
||||||
public static final String STABLE_URL = "https://raw.githubusercontent.com/topjohnwu/magisk_files/master/stable.json";
|
public static final String STABLE_URL = "https://raw.githubusercontent.com/topjohnwu/magisk_files/master/stable.json";
|
||||||
public static final String BETA_URL = "https://raw.githubusercontent.com/topjohnwu/magisk_files/master/beta.json";
|
public static final String BETA_URL = "https://raw.githubusercontent.com/topjohnwu/magisk_files/master/beta.json";
|
||||||
public static final String SNET_URL = "https://github.com/topjohnwu/magisk_files/raw/a300521162587da23e45010797bfd8c9a03594f6/snet.apk";
|
|
||||||
public static final String REPO_URL = "https://api.github.com/users/Magisk-Modules-Repo/repos?per_page=100&sort=pushed&page=%d";
|
public static final String REPO_URL = "https://api.github.com/users/Magisk-Modules-Repo/repos?per_page=100&sort=pushed&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";
|
||||||
|
@ -39,6 +39,8 @@ public class Data {
|
|||||||
public static String managerLink;
|
public static String managerLink;
|
||||||
public static String managerNoteLink;
|
public static String managerNoteLink;
|
||||||
public static String uninstallerLink;
|
public static String uninstallerLink;
|
||||||
|
public static int snetVersionCode;
|
||||||
|
public static String snetLink;
|
||||||
|
|
||||||
// Install flags
|
// Install flags
|
||||||
public static boolean keepVerity = false;
|
public static boolean keepVerity = false;
|
||||||
|
@ -226,11 +226,9 @@ public class MagiskFragment extends BaseFragment
|
|||||||
|
|
||||||
boolean hasNetwork = Download.checkNetworkStatus(mm);
|
boolean hasNetwork = Download.checkNetworkStatus(mm);
|
||||||
boolean hasRoot = Shell.rootAccess();
|
boolean hasRoot = Shell.rootAccess();
|
||||||
boolean hasGms = hasGms();
|
|
||||||
boolean isUpToDate = Data.magiskVersionCode > Const.MAGISK_VER.UNIFIED;
|
boolean isUpToDate = Data.magiskVersionCode > Const.MAGISK_VER.UNIFIED;
|
||||||
|
|
||||||
magiskUpdate.setVisibility(hasNetwork ? View.VISIBLE : View.GONE);
|
magiskUpdate.setVisibility(hasNetwork ? View.VISIBLE : View.GONE);
|
||||||
safetyNetCard.setVisibility(hasNetwork && hasGms ? View.VISIBLE : View.GONE);
|
|
||||||
installOptionCard.setVisibility(hasNetwork ? View.VISIBLE : View.GONE);
|
installOptionCard.setVisibility(hasNetwork ? View.VISIBLE : View.GONE);
|
||||||
uninstallButton.setVisibility(isUpToDate && hasRoot ? View.VISIBLE : View.GONE);
|
uninstallButton.setVisibility(isUpToDate && hasRoot ? View.VISIBLE : View.GONE);
|
||||||
coreOnlyNotice.setVisibility(mm.prefs.getBoolean(Const.Key.COREONLY, false) ? View.VISIBLE : View.GONE);
|
coreOnlyNotice.setVisibility(mm.prefs.getBoolean(Const.Key.COREONLY, false) ? View.VISIBLE : View.GONE);
|
||||||
@ -254,6 +252,8 @@ public class MagiskFragment extends BaseFragment
|
|||||||
private void updateCheckUI() {
|
private void updateCheckUI() {
|
||||||
int image, color;
|
int image, color;
|
||||||
|
|
||||||
|
safetyNetCard.setVisibility(hasGms() ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
if (Data.remoteMagiskVersionCode < 0) {
|
if (Data.remoteMagiskVersionCode < 0) {
|
||||||
color = colorNeutral;
|
color = colorNeutral;
|
||||||
image = R.drawable.ic_help;
|
image = R.drawable.ic_help;
|
||||||
@ -312,12 +312,6 @@ public class MagiskFragment extends BaseFragment
|
|||||||
} else {
|
} else {
|
||||||
@StringRes int resid;
|
@StringRes int resid;
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case ISafetyNetHelper.CAUSE_SERVICE_DISCONNECTED:
|
|
||||||
resid = R.string.safetyNet_network_loss;
|
|
||||||
break;
|
|
||||||
case ISafetyNetHelper.CAUSE_NETWORK_LOST:
|
|
||||||
resid = R.string.safetyNet_service_disconnected;
|
|
||||||
break;
|
|
||||||
case ISafetyNetHelper.RESPONSE_ERR:
|
case ISafetyNetHelper.RESPONSE_ERR:
|
||||||
resid = R.string.safetyNet_res_invalid;
|
resid = R.string.safetyNet_res_invalid;
|
||||||
break;
|
break;
|
||||||
|
@ -2,7 +2,6 @@ package com.topjohnwu.magisk.asyncs;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.Const;
|
|
||||||
import com.topjohnwu.magisk.Data;
|
import com.topjohnwu.magisk.Data;
|
||||||
import com.topjohnwu.magisk.utils.ISafetyNetHelper;
|
import com.topjohnwu.magisk.utils.ISafetyNetHelper;
|
||||||
import com.topjohnwu.magisk.utils.Topic;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
@ -20,7 +19,7 @@ import java.net.HttpURLConnection;
|
|||||||
|
|
||||||
import dalvik.system.DexClassLoader;
|
import dalvik.system.DexClassLoader;
|
||||||
|
|
||||||
public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
|
public class CheckSafetyNet extends ParallelTask<Void, Void, Void> {
|
||||||
|
|
||||||
public static final File dexPath =
|
public static final File dexPath =
|
||||||
new File(Data.MM().getFilesDir().getParent() + "/snet", "snet.apk");
|
new File(Data.MM().getFilesDir().getParent() + "/snet", "snet.apk");
|
||||||
@ -33,7 +32,7 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
|
|||||||
private void dlSnet() throws Exception {
|
private void dlSnet() throws Exception {
|
||||||
Shell.sh("rm -rf " + dexPath.getParent()).exec();
|
Shell.sh("rm -rf " + dexPath.getParent()).exec();
|
||||||
dexPath.getParentFile().mkdir();
|
dexPath.getParentFile().mkdir();
|
||||||
HttpURLConnection conn = WebService.mustRequest(Const.Url.SNET_URL, null);
|
HttpURLConnection conn = WebService.mustRequest(Data.snetLink, 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())) {
|
||||||
@ -52,13 +51,13 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
|
|||||||
.invoke(null, ISafetyNetHelper.class, dexPath.getPath(), getActivity(),
|
.invoke(null, ISafetyNetHelper.class, dexPath.getPath(), getActivity(),
|
||||||
(ISafetyNetHelper.Callback) code ->
|
(ISafetyNetHelper.Callback) code ->
|
||||||
Topic.publish(false, Topic.SNET_CHECK_DONE, code));
|
Topic.publish(false, Topic.SNET_CHECK_DONE, code));
|
||||||
if (helper.getVersion() != Const.SNET_VER) {
|
if (helper.getVersion() < Data.snetVersionCode) {
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Exception doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
dyload();
|
dyload();
|
||||||
@ -67,21 +66,12 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
|
|||||||
dlSnet();
|
dlSnet();
|
||||||
dyload();
|
dyload();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
// Run attestation
|
||||||
return e;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Exception e) {
|
|
||||||
if (e == null) {
|
|
||||||
helper.attest();
|
helper.attest();
|
||||||
} else {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Topic.publish(false, Topic.SNET_CHECK_DONE, -1);
|
Topic.publish(false, Topic.SNET_CHECK_DONE, -1);
|
||||||
}
|
}
|
||||||
super.onPostExecute(e);
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,10 @@ public class CheckUpdates {
|
|||||||
|
|
||||||
JSONObject uninstaller = getJson(json, "uninstaller");
|
JSONObject uninstaller = getJson(json, "uninstaller");
|
||||||
Data.uninstallerLink = getString(uninstaller, "link", null);
|
Data.uninstallerLink = getString(uninstaller, "link", null);
|
||||||
|
|
||||||
|
JSONObject snet = getJson(json, "snet");
|
||||||
|
Data.snetVersionCode = getInt(snet, "versionCode", -1);
|
||||||
|
Data.snetLink = getString(snet, "link", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void check(Runnable cb) {
|
public static void check(Runnable cb) {
|
||||||
|
@ -4,10 +4,8 @@ import android.support.annotation.Keep;
|
|||||||
|
|
||||||
public interface ISafetyNetHelper {
|
public interface ISafetyNetHelper {
|
||||||
|
|
||||||
int CAUSE_SERVICE_DISCONNECTED = 0x01;
|
int RESPONSE_ERR = 0x01;
|
||||||
int CAUSE_NETWORK_LOST = 0x02;
|
int CONNECTION_FAIL = 0x02;
|
||||||
int RESPONSE_ERR = 0x04;
|
|
||||||
int CONNECTION_FAIL = 0x08;
|
|
||||||
|
|
||||||
int BASIC_PASS = 0x10;
|
int BASIC_PASS = 0x10;
|
||||||
int CTS_PASS = 0x20;
|
int CTS_PASS = 0x20;
|
||||||
|
@ -154,6 +154,7 @@
|
|||||||
android:layout_marginEnd="5dp"
|
android:layout_marginEnd="5dp"
|
||||||
android:layout_marginStart="5dp"
|
android:layout_marginStart="5dp"
|
||||||
android:layout_marginTop="4dp"
|
android:layout_marginTop="4dp"
|
||||||
|
android:visibility="gone"
|
||||||
app:cardCornerRadius="@dimen/card_corner_radius"
|
app:cardCornerRadius="@dimen/card_corner_radius"
|
||||||
app:cardElevation="@dimen/card_elevation">
|
app:cardElevation="@dimen/card_elevation">
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ allprojects {
|
|||||||
|
|
||||||
ext {
|
ext {
|
||||||
compileSdkVersion = 28
|
compileSdkVersion = 28
|
||||||
buildToolsVersion = "28.0.0"
|
buildToolsVersion = "28.0.2"
|
||||||
supportLibVersion = "27.1.1"
|
supportLibVersion = "27.1.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,23 +8,20 @@ android {
|
|||||||
applicationId "com.topjohnwu.snet"
|
applicationId "com.topjohnwu.snet"
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion rootProject.ext.compileSdkVersion
|
targetSdkVersion rootProject.ext.compileSdkVersion
|
||||||
versionCode 1
|
versionCode 11
|
||||||
versionName "1.0"
|
versionName "snet"
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
minifyEnabled true
|
minifyEnabled true
|
||||||
shrinkResources true
|
shrinkResources true
|
||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
/* The oldest version */
|
implementation 'com.google.android.gms:play-services-safetynet:15.0.1'
|
||||||
implementation('com.google.android.gms:play-services-safetynet:7.0.0') {
|
|
||||||
exclude module: 'support-v4'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
3
snet/proguard-rules.pro
vendored
3
snet/proguard-rules.pro
vendored
@ -20,7 +20,4 @@
|
|||||||
# hide the original source file name.
|
# hide the original source file name.
|
||||||
#-renamesourcefileattribute SourceFile
|
#-renamesourcefileattribute SourceFile
|
||||||
|
|
||||||
-ignorewarnings
|
|
||||||
-keep class com.topjohnwu.snet.Snet { *; }
|
-keep class com.topjohnwu.snet.Snet { *; }
|
||||||
-dontwarn java.lang.invoke**
|
|
||||||
-dontwarn com.google.android.gms.common.GooglePlayServicesUtil**
|
|
||||||
|
@ -1,148 +0,0 @@
|
|||||||
package com.topjohnwu.snet;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.ContextWrapper;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.content.res.AssetManager;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.google.android.gms.common.GooglePlayServicesUtil;
|
|
||||||
import com.google.android.gms.internal.zzlu;
|
|
||||||
|
|
||||||
/* Decompiled and modified from GooglePlayServiceUtil.class */
|
|
||||||
public class ModdedGPSUtil {
|
|
||||||
|
|
||||||
private static final String TAG = "GooglePlayServicesUtil";
|
|
||||||
static String dexPath;
|
|
||||||
|
|
||||||
static Dialog getErrorDialog(int errCode, final Activity activity, final int requestCode) {
|
|
||||||
SwapResContext ctx = new SwapResContext(activity, dexPath);
|
|
||||||
Resources res = ctx.getResources();
|
|
||||||
if (zzlu.zzQ(ctx) && errCode == 2) {
|
|
||||||
errCode = 42;
|
|
||||||
}
|
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
||||||
|
|
||||||
builder.setMessage(GooglePlayServicesUtil.zze(ctx, errCode));
|
|
||||||
|
|
||||||
String btnMsg = GooglePlayServicesUtil.zzf(ctx, errCode);
|
|
||||||
if (btnMsg != null) {
|
|
||||||
final Intent intent = GooglePlayServicesUtil.zzan(errCode);
|
|
||||||
builder.setPositiveButton(btnMsg, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int i) {
|
|
||||||
PackageManager pm = activity.getPackageManager();
|
|
||||||
if (intent != null && intent.resolveActivity(pm) != null)
|
|
||||||
activity.startActivityForResult(intent, requestCode);
|
|
||||||
dialog.dismiss();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(errCode) {
|
|
||||||
case 0:
|
|
||||||
return null;
|
|
||||||
case 1:
|
|
||||||
return builder.setTitle(res.getString(com.google.android.gms.R.string.common_google_play_services_install_title)).create();
|
|
||||||
case 2:
|
|
||||||
return builder.setTitle(res.getString(com.google.android.gms.R.string.common_google_play_services_update_title)).create();
|
|
||||||
case 3:
|
|
||||||
return builder.setTitle(res.getString(com.google.android.gms.R.string.common_google_play_services_enable_title)).create();
|
|
||||||
case 4:
|
|
||||||
case 6:
|
|
||||||
return builder.create();
|
|
||||||
case 5:
|
|
||||||
Log.e(TAG, "An invalid account was specified when connecting. Please provide a valid account.");
|
|
||||||
return builder.setTitle(res.getString(com.google.android.gms.R.string.common_google_play_services_invalid_account_title)).create();
|
|
||||||
case 7:
|
|
||||||
Log.e(TAG, "Network error occurred. Please retry request later.");
|
|
||||||
return builder.setTitle(res.getString(com.google.android.gms.R.string.common_google_play_services_network_error_title)).create();
|
|
||||||
case 8:
|
|
||||||
Log.e(TAG, "Internal error occurred. Please see logs for detailed information");
|
|
||||||
return builder.create();
|
|
||||||
case 9:
|
|
||||||
Log.e(TAG, "Google Play services is invalid. Cannot recover.");
|
|
||||||
return builder.setTitle(res.getString(com.google.android.gms.R.string.common_google_play_services_unsupported_title)).create();
|
|
||||||
case 10:
|
|
||||||
Log.e(TAG, "Developer error occurred. Please see logs for detailed information");
|
|
||||||
return builder.create();
|
|
||||||
case 11:
|
|
||||||
Log.e(TAG, "The application is not licensed to the user.");
|
|
||||||
return builder.create();
|
|
||||||
case 12:
|
|
||||||
case 13:
|
|
||||||
case 14:
|
|
||||||
case 15:
|
|
||||||
case 18:
|
|
||||||
case 19:
|
|
||||||
case 20:
|
|
||||||
case 21:
|
|
||||||
case 22:
|
|
||||||
case 23:
|
|
||||||
case 24:
|
|
||||||
case 25:
|
|
||||||
case 26:
|
|
||||||
case 27:
|
|
||||||
case 28:
|
|
||||||
case 29:
|
|
||||||
case 30:
|
|
||||||
case 31:
|
|
||||||
case 32:
|
|
||||||
case 33:
|
|
||||||
case 34:
|
|
||||||
case 35:
|
|
||||||
case 36:
|
|
||||||
case 37:
|
|
||||||
case 38:
|
|
||||||
case 39:
|
|
||||||
case 40:
|
|
||||||
case 41:
|
|
||||||
default:
|
|
||||||
Log.e(TAG, "Unexpected error code " + errCode);
|
|
||||||
return builder.create();
|
|
||||||
case 16:
|
|
||||||
Log.e(TAG, "One of the API components you attempted to connect to is not available.");
|
|
||||||
return builder.create();
|
|
||||||
case 17:
|
|
||||||
Log.e(TAG, "The specified account could not be signed in.");
|
|
||||||
return builder.setTitle(res.getString(com.google.android.gms.R.string.common_google_play_services_sign_in_failed_title)).create();
|
|
||||||
case 42:
|
|
||||||
return builder.setTitle(res.getString(com.google.android.gms.R.string.common_android_wear_update_title)).create();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class SwapResContext extends ContextWrapper {
|
|
||||||
|
|
||||||
private AssetManager asset;
|
|
||||||
private Resources resources;
|
|
||||||
|
|
||||||
public SwapResContext(Context base, String apk) {
|
|
||||||
super(base);
|
|
||||||
try {
|
|
||||||
asset = AssetManager.class.newInstance();
|
|
||||||
AssetManager.class.getMethod("addAssetPath", String.class).invoke(asset, apk);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
Resources res = base.getResources();
|
|
||||||
resources = new Resources(asset, res.getDisplayMetrics(), res.getConfiguration());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Resources getResources() {
|
|
||||||
return resources;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AssetManager getAssets() {
|
|
||||||
return asset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +1,24 @@
|
|||||||
package com.topjohnwu.snet;
|
package com.topjohnwu.snet;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.google.android.gms.common.ConnectionResult;
|
import com.google.android.gms.common.ConnectionResult;
|
||||||
import com.google.android.gms.common.GooglePlayServicesUtil;
|
import com.google.android.gms.common.GoogleApiAvailability;
|
||||||
import com.google.android.gms.common.api.GoogleApiClient;
|
import com.google.android.gms.common.api.ApiException;
|
||||||
import com.google.android.gms.common.api.ResultCallback;
|
import com.google.android.gms.common.internal.ConnectionErrorMessages;
|
||||||
|
import com.google.android.gms.common.internal.DialogRedirect;
|
||||||
import com.google.android.gms.safetynet.SafetyNet;
|
import com.google.android.gms.safetynet.SafetyNet;
|
||||||
import com.google.android.gms.safetynet.SafetyNetApi;
|
import com.google.android.gms.safetynet.SafetyNetApi;
|
||||||
|
import com.google.android.gms.safetynet.SafetyNetClient;
|
||||||
|
import com.google.android.gms.tasks.OnFailureListener;
|
||||||
|
import com.google.android.gms.tasks.OnSuccessListener;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@ -18,54 +27,29 @@ import java.lang.reflect.InvocationHandler;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
|
|
||||||
public class SafetyNetHelper implements InvocationHandler, GoogleApiClient.ConnectionCallbacks,
|
public class SafetyNetHelper implements InvocationHandler,
|
||||||
GoogleApiClient.OnConnectionFailedListener, ResultCallback<SafetyNetApi.AttestationResult> {
|
OnSuccessListener<SafetyNetApi.AttestationResponse>, OnFailureListener {
|
||||||
|
|
||||||
public static final int CAUSE_SERVICE_DISCONNECTED = 0x01;
|
private static final int RESPONSE_ERR = 0x01;
|
||||||
public static final int CAUSE_NETWORK_LOST = 0x02;
|
private static final int CONNECTION_FAIL = 0x02;
|
||||||
public static final int RESPONSE_ERR = 0x04;
|
private static final int BASIC_PASS = 0x10;
|
||||||
public static final int CONNECTION_FAIL = 0x08;
|
private static final int CTS_PASS = 0x20;
|
||||||
|
|
||||||
public static final int BASIC_PASS = 0x10;
|
private static final GoogleApiAvailability API_AVAIL = GoogleApiAvailability.getInstance();
|
||||||
public static final int CTS_PASS = 0x20;
|
private static final SecureRandom RANDOM = new SecureRandom();
|
||||||
|
private static final String TAG = "SNET";
|
||||||
|
|
||||||
public static final int SNET_EXT_VER = 10;
|
/* Insert the magic API key here :) */
|
||||||
|
private static final String API_KEY = "";
|
||||||
|
|
||||||
private GoogleApiClient mGoogleApiClient;
|
private final Activity mActivity;
|
||||||
private Activity mActivity;
|
private final Object callback;
|
||||||
private Object callback;
|
|
||||||
|
|
||||||
SafetyNetHelper(Activity activity, Object cb) {
|
SafetyNetHelper(Activity activity, Object cb) {
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
callback = cb;
|
callback = cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Override ISafetyNetHelper.getVersion */
|
|
||||||
private int getVersion() {
|
|
||||||
return SNET_EXT_VER;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Override ISafetyNetHelper.attest */
|
|
||||||
private void attest() {
|
|
||||||
// Connect Google Service
|
|
||||||
mGoogleApiClient = new GoogleApiClient.Builder(mActivity)
|
|
||||||
.addApi(SafetyNet.API)
|
|
||||||
.addOnConnectionFailedListener(this)
|
|
||||||
.addConnectionCallbacks(this)
|
|
||||||
.build();
|
|
||||||
mGoogleApiClient.connect();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object invoke(Object o, Method method, Object[] args) {
|
|
||||||
if (method.getName().equals("attest")) {
|
|
||||||
attest();
|
|
||||||
} else if (method.getName().equals("getVersion")) {
|
|
||||||
return getVersion();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void invokeCallback(int code) {
|
private void invokeCallback(int code) {
|
||||||
Class<?> clazz = callback.getClass();
|
Class<?> clazz = callback.getClass();
|
||||||
try {
|
try {
|
||||||
@ -73,34 +57,50 @@ public class SafetyNetHelper implements InvocationHandler, GoogleApiClient.Conne
|
|||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/* Override ISafetyNetHelper.getVersion */
|
||||||
public void onConnectionSuspended(int i) {
|
private int getVersion() {
|
||||||
invokeCallback(i);
|
return BuildConfig.VERSION_CODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/* Override ISafetyNetHelper.attest */
|
||||||
public void onConnectionFailed(ConnectionResult result) {
|
private void attest() {
|
||||||
if (GooglePlayServicesUtil.isUserRecoverableError(result.getErrorCode()))
|
int code = API_AVAIL.isGooglePlayServicesAvailable(mActivity);
|
||||||
ModdedGPSUtil.getErrorDialog(result.getErrorCode(), mActivity, 0).show();
|
if (code != ConnectionResult.SUCCESS) {
|
||||||
invokeCallback(CONNECTION_FAIL);
|
if (API_AVAIL.isUserResolvableError(code))
|
||||||
}
|
getErrorDialog(code, 0).show();
|
||||||
|
invokeCallback(CONNECTION_FAIL);
|
||||||
@Override
|
return;
|
||||||
public void onConnected(Bundle bundle) {
|
}
|
||||||
// Create nonce
|
// Create nonce
|
||||||
byte[] nonce = new byte[24];
|
byte[] nonce = new byte[24];
|
||||||
new SecureRandom().nextBytes(nonce);
|
RANDOM.nextBytes(nonce);
|
||||||
|
|
||||||
// Call SafetyNet
|
SafetyNetClient client = SafetyNet.getClient(mActivity.getBaseContext());
|
||||||
SafetyNet.SafetyNetApi.attest(mGoogleApiClient, nonce).setResultCallback(this);
|
client.attest(nonce, API_KEY).addOnSuccessListener(this).addOnFailureListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dialog getErrorDialog(int errorCode, int requestCode) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
|
||||||
|
Context swapCtx = new SwapResContext(mActivity, Snet.dexPath);
|
||||||
|
Intent intent = API_AVAIL.getErrorResolutionIntent(swapCtx, errorCode, "d");
|
||||||
|
|
||||||
|
builder.setMessage(ConnectionErrorMessages.getErrorMessage(swapCtx, errorCode));
|
||||||
|
builder.setPositiveButton(
|
||||||
|
ConnectionErrorMessages.getErrorDialogButtonMessage(swapCtx, errorCode),
|
||||||
|
DialogRedirect.getInstance(mActivity, intent, requestCode));
|
||||||
|
|
||||||
|
String title;
|
||||||
|
if ((title = ConnectionErrorMessages.getErrorTitle(swapCtx, errorCode)) != null) {
|
||||||
|
builder.setTitle(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResult(SafetyNetApi.AttestationResult result) {
|
public void onSuccess(SafetyNetApi.AttestationResponse result) {
|
||||||
int code = 0;
|
int code = 0;
|
||||||
try {
|
try {
|
||||||
if (!result.getStatus().isSuccess())
|
|
||||||
throw new JSONException("");
|
|
||||||
String jsonStr = new String(Base64.decode(
|
String jsonStr = new String(Base64.decode(
|
||||||
result.getJwsResult().split("\\.")[1], Base64.DEFAULT));
|
result.getJwsResult().split("\\.")[1], Base64.DEFAULT));
|
||||||
JSONObject json = new JSONObject(jsonStr);
|
JSONObject json = new JSONObject(jsonStr);
|
||||||
@ -110,10 +110,34 @@ public class SafetyNetHelper implements InvocationHandler, GoogleApiClient.Conne
|
|||||||
code = RESPONSE_ERR;
|
code = RESPONSE_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disconnect
|
|
||||||
mGoogleApiClient.disconnect();
|
|
||||||
|
|
||||||
// Return results
|
// Return results
|
||||||
invokeCallback(code);
|
invokeCallback(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Exception e) {
|
||||||
|
if (e instanceof ApiException) {
|
||||||
|
int errCode = ((ApiException) e).getStatusCode();
|
||||||
|
if (API_AVAIL.isUserResolvableError(errCode))
|
||||||
|
getErrorDialog(errCode, 0).show();
|
||||||
|
else
|
||||||
|
Log.e(TAG, "Cannot resolve: " + e.getMessage());
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Unknown: " + e.getMessage());
|
||||||
|
}
|
||||||
|
invokeCallback(CONNECTION_FAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object invoke(Object proxy, Method method, Object[] args) {
|
||||||
|
switch (method.getName()) {
|
||||||
|
case "attest":
|
||||||
|
attest();
|
||||||
|
return null;
|
||||||
|
case "getVersion":
|
||||||
|
return getVersion();
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,11 @@ import android.app.Activity;
|
|||||||
import java.lang.reflect.Proxy;
|
import java.lang.reflect.Proxy;
|
||||||
|
|
||||||
public class Snet {
|
public class Snet {
|
||||||
public static Object newHelper(Class<?> clazz, String dexPath, Activity activity, Object cb) {
|
static String dexPath;
|
||||||
ModdedGPSUtil.dexPath = dexPath;
|
|
||||||
|
public static Object newHelper(Class<?> interfaceClass, String dexPath, Activity activity, Object cb) {
|
||||||
|
Snet.dexPath = dexPath;
|
||||||
return Proxy.newProxyInstance(SafetyNetHelper.class.getClassLoader(),
|
return Proxy.newProxyInstance(SafetyNetHelper.class.getClassLoader(),
|
||||||
new Class[] { clazz }, new SafetyNetHelper(activity, cb));
|
new Class[] { interfaceClass }, new SafetyNetHelper(activity, cb));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
34
snet/src/main/java/com/topjohnwu/snet/SwapResContext.java
Normal file
34
snet/src/main/java/com/topjohnwu/snet/SwapResContext.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package com.topjohnwu.snet;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.ContextWrapper;
|
||||||
|
import android.content.res.AssetManager;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
|
||||||
|
public class SwapResContext extends ContextWrapper {
|
||||||
|
|
||||||
|
private AssetManager asset;
|
||||||
|
private Resources resources;
|
||||||
|
|
||||||
|
public SwapResContext(Context base, String apk) {
|
||||||
|
super(base);
|
||||||
|
try {
|
||||||
|
asset = AssetManager.class.newInstance();
|
||||||
|
AssetManager.class.getMethod("addAssetPath", String.class).invoke(asset, apk);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
Resources res = base.getResources();
|
||||||
|
resources = new Resources(asset, res.getDisplayMetrics(), res.getConfiguration());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Resources getResources() {
|
||||||
|
return resources;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AssetManager getAssets() {
|
||||||
|
return asset;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user