funpatch( context: Context, apk: File, out: OutputStream, pkg: String, label: CharSequence ): Boolean { val info = context.packageManager.getPackageArchiveInfo(apk.path, 0) ?: returnfalse val name = info.applicationInfo.nonLocalizedLabel.toString() try { JarMap.open(apk, true).use { jar -> val je = jar.getJarEntry(ANDROID_MANIFEST) val xml = AXML(jar.getRawData(je))//打开原apk的AndroidManifest.xml文件
if (!xml.findAndPatch(APPLICATION_ID to pkg, name to label.toString())) //替换掉原包名和应用名. returnfalse