mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-04-22 15:31:34 +00:00
Update snet extension
This commit is contained in:
parent
f2494374f8
commit
a797d5d396
@ -19,8 +19,8 @@ object Const {
|
|||||||
const val MAGISK_LOG = "/cache/magisk.log"
|
const val MAGISK_LOG = "/cache/magisk.log"
|
||||||
|
|
||||||
// Versions
|
// Versions
|
||||||
const val SNET_EXT_VER = 12
|
const val SNET_EXT_VER = 13
|
||||||
const val SNET_REVISION = "b66b1a914978e5f4c4bbfd74a59f4ad371bac107"
|
const val SNET_REVISION = "5adbc435ce93ded953c30ebe587edfd50b5503bc"
|
||||||
const val BOOTCTL_REVISION = "9c5dfc1b8245c0b5b524901ef0ff0f8335757b77"
|
const val BOOTCTL_REVISION = "9c5dfc1b8245c0b5b524901ef0ff0f8335757b77"
|
||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
|
@ -28,7 +28,7 @@ interface GithubRawServices {
|
|||||||
@GET
|
@GET
|
||||||
fun fetchCustomUpdate(@Url url: String): Single<UpdateInfo>
|
fun fetchCustomUpdate(@Url url: String): Single<UpdateInfo>
|
||||||
|
|
||||||
@GET("$MAGISK_FILES/{$REVISION}/snet.apk")
|
@GET("$MAGISK_FILES/{$REVISION}/snet.jar")
|
||||||
@Streaming
|
@Streaming
|
||||||
fun fetchSafetynet(@Path(REVISION) revision: String = Const.SNET_REVISION): Single<ResponseBody>
|
fun fetchSafetynet(@Path(REVISION) revision: String = Const.SNET_REVISION): Single<ResponseBody>
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package com.topjohnwu.magisk.ui.home
|
package com.topjohnwu.magisk.ui.home
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Bundle
|
|
||||||
import com.skoumal.teanity.extensions.subscribeK
|
import com.skoumal.teanity.extensions.subscribeK
|
||||||
import com.skoumal.teanity.viewevents.ViewEvent
|
import com.skoumal.teanity.viewevents.ViewEvent
|
||||||
import com.topjohnwu.magisk.BuildConfig
|
import com.topjohnwu.magisk.BuildConfig
|
||||||
@ -11,7 +9,6 @@ import com.topjohnwu.magisk.Info
|
|||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
import com.topjohnwu.magisk.data.repository.MagiskRepository
|
import com.topjohnwu.magisk.data.repository.MagiskRepository
|
||||||
import com.topjohnwu.magisk.databinding.FragmentMagiskBinding
|
import com.topjohnwu.magisk.databinding.FragmentMagiskBinding
|
||||||
import com.topjohnwu.magisk.extensions.get
|
|
||||||
import com.topjohnwu.magisk.extensions.inject
|
import com.topjohnwu.magisk.extensions.inject
|
||||||
import com.topjohnwu.magisk.extensions.writeTo
|
import com.topjohnwu.magisk.extensions.writeTo
|
||||||
import com.topjohnwu.magisk.model.events.*
|
import com.topjohnwu.magisk.model.events.*
|
||||||
@ -22,16 +19,20 @@ import com.topjohnwu.magisk.utils.SafetyNetHelper
|
|||||||
import com.topjohnwu.magisk.view.MarkDownWindow
|
import com.topjohnwu.magisk.view.MarkDownWindow
|
||||||
import com.topjohnwu.magisk.view.dialogs.*
|
import com.topjohnwu.magisk.view.dialogs.*
|
||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
|
import dalvik.system.DexFile
|
||||||
|
import io.reactivex.Completable
|
||||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.lang.reflect.InvocationHandler
|
||||||
|
|
||||||
class HomeFragment : MagiskFragment<HomeViewModel, FragmentMagiskBinding>(),
|
class HomeFragment : MagiskFragment<HomeViewModel, FragmentMagiskBinding>(),
|
||||||
SafetyNetHelper.Callback {
|
SafetyNetHelper.Callback {
|
||||||
|
|
||||||
override val layoutRes: Int = R.layout.fragment_magisk
|
override val layoutRes: Int = R.layout.fragment_magisk
|
||||||
override val viewModel: HomeViewModel by viewModel()
|
override val viewModel: HomeViewModel by viewModel()
|
||||||
val magiskRepo: MagiskRepository by inject()
|
|
||||||
lateinit var EXT_FILE: File
|
private val magiskRepo: MagiskRepository by inject()
|
||||||
|
private val EXT_APK by lazy { File("${activity.filesDir.parent}/snet", "snet.jar") }
|
||||||
|
|
||||||
override fun onResponse(responseCode: Int) = viewModel.finishSafetyNetCheck(responseCode)
|
override fun onResponse(responseCode: Int) = viewModel.finishSafetyNetCheck(responseCode)
|
||||||
|
|
||||||
@ -48,11 +49,6 @@ class HomeFragment : MagiskFragment<HomeViewModel, FragmentMagiskBinding>(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
super.onCreate(savedInstanceState)
|
|
||||||
EXT_FILE = File("${requireActivity().filesDir.parent}/snet", "snet.apk")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
setHasOptionsMenu(true)
|
setHasOptionsMenu(true)
|
||||||
@ -78,7 +74,7 @@ class HomeFragment : MagiskFragment<HomeViewModel, FragmentMagiskBinding>(),
|
|||||||
|
|
||||||
private fun downloadSafetyNet(requiresUserInput: Boolean = true) {
|
private fun downloadSafetyNet(requiresUserInput: Boolean = true) {
|
||||||
fun download() = magiskRepo.fetchSafetynet()
|
fun download() = magiskRepo.fetchSafetynet()
|
||||||
.map { it.byteStream().writeTo(EXT_FILE) }
|
.map { it.byteStream().writeTo(EXT_APK) }
|
||||||
.subscribeK { updateSafetyNet(true) }
|
.subscribeK { updateSafetyNet(true) }
|
||||||
|
|
||||||
if (!requiresUserInput) {
|
if (!requiresUserInput) {
|
||||||
@ -96,29 +92,40 @@ class HomeFragment : MagiskFragment<HomeViewModel, FragmentMagiskBinding>(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateSafetyNet(dieOnError: Boolean) {
|
private fun updateSafetyNet(dieOnError: Boolean) {
|
||||||
try {
|
Completable.fromAction {
|
||||||
val loader = DynamicClassLoader(EXT_APK)
|
val loader = DynamicClassLoader(EXT_APK)
|
||||||
val clazz = loader.loadClass("com.topjohnwu.snet.Snet")
|
val dex = DexFile.loadDex(EXT_APK.path, EXT_APK.parent, 0)
|
||||||
val helper = clazz.getMethod("newHelper",
|
|
||||||
Class::class.java, String::class.java, Activity::class.java, Any::class.java)
|
// Scan through the dex and find our helper class
|
||||||
.invoke(null, SafetyNetHelper::class.java, EXT_APK.path,
|
var helperClass: Class<*>? = null
|
||||||
activity, this) as SafetyNetHelper
|
for (className in dex.entries()) {
|
||||||
|
if (className.startsWith("x.")) {
|
||||||
|
val cls = loader.loadClass(className)
|
||||||
|
if (InvocationHandler::class.java.isAssignableFrom(cls)) {
|
||||||
|
helperClass = cls
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
helperClass ?: throw Exception()
|
||||||
|
|
||||||
|
val helper = helperClass.getMethod("get",
|
||||||
|
Class::class.java, Context::class.java, Any::class.java)
|
||||||
|
.invoke(null, SafetyNetHelper::class.java, activity, this) as SafetyNetHelper
|
||||||
|
|
||||||
if (helper.version < Const.SNET_EXT_VER)
|
if (helper.version < Const.SNET_EXT_VER)
|
||||||
throw Exception()
|
throw Exception()
|
||||||
|
|
||||||
helper.attest()
|
helper.attest()
|
||||||
} catch (e: Exception) {
|
}.subscribeK(onError = {
|
||||||
if (dieOnError) {
|
if (dieOnError) {
|
||||||
viewModel.finishSafetyNetCheck(-1)
|
viewModel.finishSafetyNetCheck(-1)
|
||||||
return
|
} else {
|
||||||
|
Shell.sh("rm -rf " + EXT_APK.parent).exec()
|
||||||
|
EXT_APK.parentFile?.mkdir()
|
||||||
|
downloadSafetyNet(!dieOnError)
|
||||||
}
|
}
|
||||||
Shell.sh("rm -rf " + EXT_APK.parent).exec()
|
})
|
||||||
EXT_APK.parentFile?.mkdir()
|
|
||||||
downloadSafetyNet(!dieOnError)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
val EXT_APK by lazy { File("${get<Context>().filesDir.parent}/snet", "snet.apk") }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package com.topjohnwu.magisk.ui.home
|
package com.topjohnwu.magisk.ui.home
|
||||||
|
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import com.skoumal.teanity.extensions.addOnPropertyChangedCallback
|
import com.skoumal.teanity.extensions.addOnPropertyChangedCallback
|
||||||
import com.skoumal.teanity.extensions.doOnSubscribeUi
|
import com.skoumal.teanity.extensions.doOnSubscribeUi
|
||||||
import com.skoumal.teanity.extensions.subscribeK
|
import com.skoumal.teanity.extensions.subscribeK
|
||||||
import com.skoumal.teanity.util.KObservableField
|
import com.skoumal.teanity.util.KObservableField
|
||||||
import com.topjohnwu.magisk.*
|
import com.topjohnwu.magisk.*
|
||||||
import com.topjohnwu.magisk.data.repository.MagiskRepository
|
import com.topjohnwu.magisk.data.repository.MagiskRepository
|
||||||
|
import com.topjohnwu.magisk.extensions.get
|
||||||
import com.topjohnwu.magisk.extensions.packageName
|
import com.topjohnwu.magisk.extensions.packageName
|
||||||
import com.topjohnwu.magisk.extensions.res
|
import com.topjohnwu.magisk.extensions.res
|
||||||
import com.topjohnwu.magisk.extensions.toggle
|
import com.topjohnwu.magisk.extensions.toggle
|
||||||
@ -31,6 +33,10 @@ class HomeViewModel(
|
|||||||
private val magiskRepo: MagiskRepository
|
private val magiskRepo: MagiskRepository
|
||||||
) : MagiskViewModel() {
|
) : MagiskViewModel() {
|
||||||
|
|
||||||
|
val hasGMS = runCatching {
|
||||||
|
get<PackageManager>().getPackageInfo("com.google.android.gms", 0); true
|
||||||
|
}.getOrElse { false }
|
||||||
|
|
||||||
val isAdvancedExpanded = KObservableField(false)
|
val isAdvancedExpanded = KObservableField(false)
|
||||||
|
|
||||||
val isForceEncryption = KObservableField(Info.keepEnc)
|
val isForceEncryption = KObservableField(Info.keepEnc)
|
||||||
|
@ -196,7 +196,7 @@
|
|||||||
android:layout_margin="@dimen/margin_generic" />
|
android:layout_margin="@dimen/margin_generic" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
gone="@{!viewModel.hasRoot || !viewModel.isConnected}"
|
gone="@{!viewModel.isConnected || !viewModel.hasGMS}"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
7
build.py
7
build.py
@ -283,12 +283,11 @@ def build_snet(args):
|
|||||||
error('Build snet extention failed!')
|
error('Build snet extention failed!')
|
||||||
source = os.path.join('snet', 'build', 'outputs', 'apk',
|
source = os.path.join('snet', 'build', 'outputs', 'apk',
|
||||||
'release', 'snet-release-unsigned.apk')
|
'release', 'snet-release-unsigned.apk')
|
||||||
target = os.path.join(config['outdir'], 'snet.apk')
|
target = os.path.join(config['outdir'], 'snet.jar')
|
||||||
# Re-compress the whole APK for smaller size
|
# Extract classes.dex
|
||||||
with zipfile.ZipFile(target, 'w', compression=zipfile.ZIP_DEFLATED, allowZip64=False) as zout:
|
with zipfile.ZipFile(target, 'w', compression=zipfile.ZIP_DEFLATED, allowZip64=False) as zout:
|
||||||
with zipfile.ZipFile(source) as zin:
|
with zipfile.ZipFile(source) as zin:
|
||||||
for item in zin.infolist():
|
zout.writestr('classes.dex', zin.read('classes.dex'))
|
||||||
zout.writestr(item.filename, zin.read(item))
|
|
||||||
rm(source)
|
rm(source)
|
||||||
header('Output: ' + target)
|
header('Output: ' + target)
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ android {
|
|||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId 'com.topjohnwu.snet'
|
applicationId 'com.topjohnwu.snet'
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
versionCode 12
|
versionCode 13
|
||||||
versionName 'snet'
|
versionName 'snet'
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,5 +19,5 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
implementation 'com.google.android.gms:play-services-safetynet:16.0.0'
|
implementation 'com.google.android.gms:play-services-safetynet:17.0.0'
|
||||||
}
|
}
|
||||||
|
7
snet/proguard-rules.pro
vendored
7
snet/proguard-rules.pro
vendored
@ -20,7 +20,10 @@
|
|||||||
# hide the original source file name.
|
# hide the original source file name.
|
||||||
#-renamesourcefileattribute SourceFile
|
#-renamesourcefileattribute SourceFile
|
||||||
|
|
||||||
-keep class com.topjohnwu.snet.Snet { *; }
|
-keep,allowobfuscation class com.topjohnwu.snet.SafetyNetHelper
|
||||||
|
-keepclassmembers class com.topjohnwu.snet.SafetyNetHelper {
|
||||||
|
** get(...);
|
||||||
|
}
|
||||||
|
|
||||||
-repackageclasses ''
|
-repackageclasses 'x'
|
||||||
-allowaccessmodification
|
-allowaccessmodification
|
||||||
|
@ -1,18 +1,14 @@
|
|||||||
package com.topjohnwu.snet;
|
package com.topjohnwu.snet;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.google.android.gms.common.ConnectionResult;
|
import com.google.android.gms.common.ConnectionResult;
|
||||||
import com.google.android.gms.common.GoogleApiAvailability;
|
import com.google.android.gms.common.GoogleApiAvailability;
|
||||||
import com.google.android.gms.common.api.ApiException;
|
import com.google.android.gms.common.api.ApiException;
|
||||||
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.safetynet.SafetyNetClient;
|
||||||
@ -24,10 +20,9 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
import java.lang.reflect.InvocationHandler;
|
import java.lang.reflect.InvocationHandler;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
public class SafetyNetHelper implements InvocationHandler,
|
public class SafetyNetHelper implements InvocationHandler,
|
||||||
OnSuccessListener<SafetyNetApi.AttestationResponse>, OnFailureListener {
|
OnSuccessListener<SafetyNetApi.AttestationResponse>, OnFailureListener {
|
||||||
|
|
||||||
@ -40,11 +35,16 @@ public class SafetyNetHelper implements InvocationHandler,
|
|||||||
private static final SecureRandom RANDOM = new SecureRandom();
|
private static final SecureRandom RANDOM = new SecureRandom();
|
||||||
private static final String TAG = "SNET";
|
private static final String TAG = "SNET";
|
||||||
|
|
||||||
private final Activity mActivity;
|
private final Context context;
|
||||||
private final Object callback;
|
private final Object callback;
|
||||||
|
|
||||||
SafetyNetHelper(Activity activity, Object cb) {
|
public static Object get(Class<?> interfaceClass, Context context, Object cb) {
|
||||||
mActivity = activity;
|
return Proxy.newProxyInstance(SafetyNetHelper.class.getClassLoader(),
|
||||||
|
new Class[]{interfaceClass}, new SafetyNetHelper(context, cb));
|
||||||
|
}
|
||||||
|
|
||||||
|
private SafetyNetHelper(Context c, Object cb) {
|
||||||
|
context = c;
|
||||||
callback = cb;
|
callback = cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +52,8 @@ public class SafetyNetHelper implements InvocationHandler,
|
|||||||
Class<?> clazz = callback.getClass();
|
Class<?> clazz = callback.getClass();
|
||||||
try {
|
try {
|
||||||
clazz.getMethod("onResponse", int.class).invoke(callback, code);
|
clazz.getMethod("onResponse", int.class).invoke(callback, code);
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return magic API key here :) */
|
/* Return magic API key here :) */
|
||||||
@ -60,17 +61,14 @@ public class SafetyNetHelper implements InvocationHandler,
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Override ISafetyNetHelper.getVersion */
|
|
||||||
private int getVersion() {
|
private int getVersion() {
|
||||||
return BuildConfig.VERSION_CODE;
|
return BuildConfig.VERSION_CODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Override ISafetyNetHelper.attest */
|
|
||||||
private void attest() {
|
private void attest() {
|
||||||
int code = API_AVAIL.isGooglePlayServicesAvailable(mActivity);
|
int code = API_AVAIL.isGooglePlayServicesAvailable(context);
|
||||||
if (code != ConnectionResult.SUCCESS) {
|
if (code != ConnectionResult.SUCCESS) {
|
||||||
if (API_AVAIL.isUserResolvableError(code))
|
Log.e(TAG, API_AVAIL.getErrorString(code));
|
||||||
getErrorDialog(code, 0).show();
|
|
||||||
invokeCallback(CONNECTION_FAIL);
|
invokeCallback(CONNECTION_FAIL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -78,28 +76,10 @@ public class SafetyNetHelper implements InvocationHandler,
|
|||||||
byte[] nonce = new byte[24];
|
byte[] nonce = new byte[24];
|
||||||
RANDOM.nextBytes(nonce);
|
RANDOM.nextBytes(nonce);
|
||||||
|
|
||||||
SafetyNetClient client = SafetyNet.getClient(mActivity.getBaseContext());
|
SafetyNetClient client = SafetyNet.getClient(context);
|
||||||
client.attest(nonce, getApiKey()).addOnSuccessListener(this).addOnFailureListener(this);
|
client.attest(nonce, getApiKey()).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 onSuccess(SafetyNetApi.AttestationResponse result) {
|
public void onSuccess(SafetyNetApi.AttestationResponse result) {
|
||||||
int code = 0;
|
int code = 0;
|
||||||
@ -121,12 +101,9 @@ public class SafetyNetHelper implements InvocationHandler,
|
|||||||
public void onFailure(@NonNull Exception e) {
|
public void onFailure(@NonNull Exception e) {
|
||||||
if (e instanceof ApiException) {
|
if (e instanceof ApiException) {
|
||||||
int errCode = ((ApiException) e).getStatusCode();
|
int errCode = ((ApiException) e).getStatusCode();
|
||||||
if (API_AVAIL.isUserResolvableError(errCode))
|
Log.e(TAG, API_AVAIL.getErrorString(errCode));
|
||||||
getErrorDialog(errCode, 0).show();
|
|
||||||
else
|
|
||||||
Log.e(TAG, "Cannot resolve: " + e.getMessage());
|
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Unknown: " + e.getMessage());
|
Log.e(TAG, "Unknown: " + e);
|
||||||
}
|
}
|
||||||
invokeCallback(CONNECTION_FAIL);
|
invokeCallback(CONNECTION_FAIL);
|
||||||
}
|
}
|
||||||
@ -136,11 +113,10 @@ public class SafetyNetHelper implements InvocationHandler,
|
|||||||
switch (method.getName()) {
|
switch (method.getName()) {
|
||||||
case "attest":
|
case "attest":
|
||||||
attest();
|
attest();
|
||||||
return null;
|
break;
|
||||||
case "getVersion":
|
case "getVersion":
|
||||||
return getVersion();
|
return getVersion();
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
package com.topjohnwu.snet;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
|
|
||||||
import java.lang.reflect.Proxy;
|
|
||||||
|
|
||||||
public class Snet {
|
|
||||||
static String dexPath;
|
|
||||||
|
|
||||||
public static Object newHelper(Class<?> interfaceClass, String dexPath, Activity activity, Object cb) {
|
|
||||||
Snet.dexPath = dexPath;
|
|
||||||
return Proxy.newProxyInstance(SafetyNetHelper.class.getClassLoader(),
|
|
||||||
new Class[] { interfaceClass }, new SafetyNetHelper(activity, cb));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
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…
x
Reference in New Issue
Block a user