Check apk before patch

This commit is contained in:
vvb2060 2022-02-15 16:18:53 +08:00 committed by John Wu
parent 8cc76b1d86
commit 02bf7dca01

View File

@ -33,7 +33,6 @@ object HideAPK {
private const val ALPHA = "abcdefghijklmnopqrstuvwxyz" private const val ALPHA = "abcdefghijklmnopqrstuvwxyz"
private const val ALPHADOTS = "$ALPHA....." private const val ALPHADOTS = "$ALPHA....."
private const val APP_NAME = "Magisk"
private const val ANDROID_MANIFEST = "AndroidManifest.xml" private const val ANDROID_MANIFEST = "AndroidManifest.xml"
// Some arbitrary limit // Some arbitrary limit
@ -69,12 +68,14 @@ object HideAPK {
apk: File, out: File, apk: File, out: File,
pkg: String, label: CharSequence pkg: String, label: CharSequence
): Boolean { ): Boolean {
val info = context.packageManager.getPackageArchiveInfo(apk.path, 0) ?: return false
val name = info.applicationInfo.nonLocalizedLabel.toString()
try { try {
val jar = JarMap.open(apk, true) val jar = JarMap.open(apk, true)
val je = jar.getJarEntry(ANDROID_MANIFEST) val je = jar.getJarEntry(ANDROID_MANIFEST)
val xml = AXML(jar.getRawData(je)) val xml = AXML(jar.getRawData(je))
if (!xml.findAndPatch(APPLICATION_ID to pkg, APP_NAME to label.toString())) if (!xml.findAndPatch(APPLICATION_ID to pkg, name to label.toString()))
return false return false
// Write apk changes // Write apk changes