-
-
Save apkunpacker/28a95d39b29a6582a06b90d623ecbe68 to your computer and use it in GitHub Desktop.
CorePatch detector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.github.a13e300.demo.maho | |
import android.app.PendingIntent | |
import android.content.BroadcastReceiver | |
import android.content.Context | |
import android.content.Intent | |
import android.content.IntentFilter | |
import android.content.pm.PackageInstaller | |
import android.content.pm.PackageInstaller.EXTRA_STATUS | |
import android.content.pm.PackageInstaller.STATUS_PENDING_USER_ACTION | |
import io.github.a13e300.demo.BuildConfig | |
import java.util.UUID | |
import java.util.concurrent.CountDownLatch | |
import java.util.concurrent.TimeUnit | |
import java.util.zip.ZipEntry | |
import java.util.zip.ZipFile | |
import java.util.zip.ZipOutputStream | |
// code decompiled from momo-v4.4.1 (class: Bi) | |
// momo: https://t.me/magiskalpha/529 | |
// https://t.me/real5ec1cff/32 | |
// true meaning abnormal | |
fun detectCorePatch(context: Context): Boolean { | |
val session: PackageInstaller.Session | |
val uuid = UUID.randomUUID().toString() | |
var result = false | |
val broadcast = PendingIntent.getBroadcast( | |
context, | |
0, | |
Intent(uuid).setPackage(BuildConfig.APPLICATION_ID), | |
PendingIntent.FLAG_MUTABLE | |
) | |
val countDownLatch = CountDownLatch(1) | |
val receiver: BroadcastReceiver = object : BroadcastReceiver() { | |
override fun onReceive(context: Context, intent: Intent) { | |
val extras = intent.extras ?: return | |
result = extras.getInt(EXTRA_STATUS) == STATUS_PENDING_USER_ACTION | |
countDownLatch.countDown() | |
} | |
} | |
context.registerReceiver(receiver, IntentFilter(uuid)) | |
val packageInstaller = context.packageManager.packageInstaller | |
try { | |
session = packageInstaller.openSession( | |
packageInstaller.createSession( | |
PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL) | |
) | |
) | |
} catch (t: SecurityException) { | |
return true | |
} | |
ZipOutputStream(session.openWrite("package", 0L, -1L)).use { zipOutputStream -> | |
zipOutputStream.putNextEntry(ZipEntry("AndroidManifest.xml")) | |
ZipFile(context.packageCodePath).use { zipFile -> | |
zipFile.getInputStream(zipFile.getEntry("AndroidManifest.xml")) | |
.use { it.copyTo(zipOutputStream) } | |
} | |
zipOutputStream.finish() | |
} | |
session.commit(broadcast.intentSender) | |
countDownLatch.await(4L, TimeUnit.SECONDS) | |
context.unregisterReceiver(receiver) | |
session.abandon() | |
session.close() | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment