mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-10 04:31:55 +00:00
Fixed rewritten java code being java-styled in kotlin
Fixed accessing kotlin code illegally via companion helper
This commit is contained in:
committed by
topjohnwu
parent
0a703585b0
commit
79d704008b
@@ -89,7 +89,7 @@ public class DownloadApp {
|
||||
// Make it world readable
|
||||
apk.setReadable(true, false);
|
||||
if (Shell.su("pm install " + apk).exec().isSuccess())
|
||||
RootUtils.Companion.rmAndLaunch(app.getPackageName(),
|
||||
RootUtils.rmAndLaunch(app.getPackageName(),
|
||||
new ComponentName(BuildConfig.APPLICATION_ID,
|
||||
ClassMap.get(SplashActivity.class).getName()));
|
||||
progress.dismiss();
|
||||
|
||||
@@ -3,8 +3,6 @@ package com.topjohnwu.magisk.utils;
|
||||
import android.content.ComponentName;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import com.topjohnwu.magisk.App;
|
||||
import com.topjohnwu.magisk.BuildConfig;
|
||||
import com.topjohnwu.magisk.ClassMap;
|
||||
@@ -29,6 +27,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarEntry;
|
||||
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
public class PatchAPK {
|
||||
|
||||
public static final String LOWERALPHA = "abcdefghijklmnopqrstuvwxyz";
|
||||
@@ -56,7 +56,7 @@ public class PatchAPK {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static boolean findAndPatch(byte xml[], String from, String to) {
|
||||
private static boolean findAndPatch(byte[] xml, String from, String to) {
|
||||
if (from.length() != to.length())
|
||||
return false;
|
||||
CharBuffer buf = ByteBuffer.wrap(xml).order(ByteOrder.LITTLE_ENDIAN).asCharBuffer();
|
||||
@@ -83,7 +83,7 @@ public class PatchAPK {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean findAndPatch(byte xml[], int a, int b) {
|
||||
private static boolean findAndPatch(byte[] xml, int a, int b) {
|
||||
IntBuffer buf = ByteBuffer.wrap(xml).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();
|
||||
int len = xml.length / 4;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
@@ -112,7 +112,7 @@ public class PatchAPK {
|
||||
|
||||
Config.set(Config.Key.SU_MANAGER, pkg);
|
||||
Config.export();
|
||||
RootUtils.Companion.rmAndLaunch(BuildConfig.APPLICATION_ID,
|
||||
RootUtils.rmAndLaunch(BuildConfig.APPLICATION_ID,
|
||||
new ComponentName(pkg, ClassMap.get(SplashActivity.class).getName()));
|
||||
|
||||
return true;
|
||||
@@ -122,7 +122,7 @@ public class PatchAPK {
|
||||
try {
|
||||
JarMap jar = new JarMap(in);
|
||||
JarEntry je = jar.getJarEntry(Const.ANDROID_MANIFEST);
|
||||
byte xml[] = jar.getRawData(je);
|
||||
byte[] xml = jar.getRawData(je);
|
||||
|
||||
if (!findAndPatch(xml, BuildConfig.APPLICATION_ID, pkg) ||
|
||||
!findAndPatch(xml, R.string.app_name, R.string.re_app_name))
|
||||
|
||||
@@ -38,72 +38,70 @@ fun Intent.toCommand(args: MutableList<String>) {
|
||||
}
|
||||
val extras = extras
|
||||
if (extras != null) {
|
||||
for (key in extras.keySet()) {
|
||||
loop@ for (key in extras.keySet()) {
|
||||
val v = extras.get(key) ?: continue
|
||||
var value: Any = v
|
||||
val arg: String
|
||||
if (v is String)
|
||||
arg = "--es"
|
||||
else if (v is Boolean)
|
||||
arg = "--ez"
|
||||
else if (v is Int)
|
||||
arg = "--ei"
|
||||
else if (v is Long)
|
||||
arg = "--el"
|
||||
else if (v is Float)
|
||||
arg = "--ef"
|
||||
else if (v is Uri)
|
||||
arg = "--eu"
|
||||
else if (v is ComponentName) {
|
||||
arg = "--ecn"
|
||||
value = v.flattenToString()
|
||||
} else if (v is ArrayList<*>) {
|
||||
if (v.size <= 0)
|
||||
/* Impossible to know the type due to type erasure */
|
||||
continue
|
||||
|
||||
arg = if (v[0] is Int)
|
||||
"--eial"
|
||||
else if (v[0] is Long)
|
||||
"--elal"
|
||||
else if (v[0] is Float)
|
||||
"--efal"
|
||||
else if (v[0] is String)
|
||||
"--esal"
|
||||
else
|
||||
continue /* Unsupported */
|
||||
|
||||
val sb = StringBuilder()
|
||||
for (o in v) {
|
||||
sb.append(o.toString().replace(",", "\\,"))
|
||||
sb.append(',')
|
||||
when {
|
||||
v is String -> arg = "--es"
|
||||
v is Boolean -> arg = "--ez"
|
||||
v is Int -> arg = "--ei"
|
||||
v is Long -> arg = "--el"
|
||||
v is Float -> arg = "--ef"
|
||||
v is Uri -> arg = "--eu"
|
||||
v is ComponentName -> {
|
||||
arg = "--ecn"
|
||||
value = v.flattenToString()
|
||||
}
|
||||
// Remove trailing comma
|
||||
sb.deleteCharAt(sb.length - 1)
|
||||
value = sb
|
||||
} else if (v.javaClass.isArray) {
|
||||
arg = if (v is IntArray)
|
||||
"--eia"
|
||||
else if (v is LongArray)
|
||||
"--ela"
|
||||
else if (v is FloatArray)
|
||||
"--efa"
|
||||
else if (v is Array<*> && v.isArrayOf<String>())
|
||||
"--esa"
|
||||
else
|
||||
continue /* Unsupported */
|
||||
v is ArrayList<*> -> {
|
||||
if (v.size <= 0)
|
||||
/* Impossible to know the type due to type erasure */
|
||||
continue@loop
|
||||
|
||||
val sb = StringBuilder()
|
||||
val len = RArray.getLength(v)
|
||||
for (i in 0 until len) {
|
||||
sb.append(RArray.get(v, i)!!.toString().replace(",", "\\,"))
|
||||
sb.append(',')
|
||||
arg = if (v[0] is Int)
|
||||
"--eial"
|
||||
else if (v[0] is Long)
|
||||
"--elal"
|
||||
else if (v[0] is Float)
|
||||
"--efal"
|
||||
else if (v[0] is String)
|
||||
"--esal"
|
||||
else
|
||||
continue@loop /* Unsupported */
|
||||
|
||||
val sb = StringBuilder()
|
||||
for (o in v) {
|
||||
sb.append(o.toString().replace(",", "\\,"))
|
||||
sb.append(',')
|
||||
}
|
||||
// Remove trailing comma
|
||||
sb.deleteCharAt(sb.length - 1)
|
||||
value = sb
|
||||
}
|
||||
// Remove trailing comma
|
||||
sb.deleteCharAt(sb.length - 1)
|
||||
value = sb
|
||||
} else
|
||||
continue /* Unsupported */
|
||||
v.javaClass.isArray -> {
|
||||
arg = if (v is IntArray)
|
||||
"--eia"
|
||||
else if (v is LongArray)
|
||||
"--ela"
|
||||
else if (v is FloatArray)
|
||||
"--efa"
|
||||
else if (v is Array<*> && v.isArrayOf<String>())
|
||||
"--esa"
|
||||
else
|
||||
continue@loop /* Unsupported */
|
||||
|
||||
val sb = StringBuilder()
|
||||
val len = RArray.getLength(v)
|
||||
for (i in 0 until len) {
|
||||
sb.append(RArray.get(v, i)!!.toString().replace(",", "\\,"))
|
||||
sb.append(',')
|
||||
}
|
||||
// Remove trailing comma
|
||||
sb.deleteCharAt(sb.length - 1)
|
||||
value = sb
|
||||
}
|
||||
else -> continue@loop
|
||||
} /* Unsupported */
|
||||
|
||||
args.add(arg)
|
||||
args.add(key)
|
||||
@@ -153,10 +151,12 @@ class RootUtils : Shell.Initializer() {
|
||||
|
||||
companion object {
|
||||
|
||||
@JvmStatic
|
||||
fun rmAndLaunch(rm: String, component: ComponentName) {
|
||||
Shell.su("(rm_launch $rm ${component.flattenToString()})").exec()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun reboot() {
|
||||
Shell.su("/system/bin/reboot ${if (Config.recovery) "recovery" else ""}").submit()
|
||||
}
|
||||
|
||||
@@ -9,16 +9,16 @@ import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipInputStream
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun unzip(zip: File, folder: File, path: String = "", junkPath: Boolean = false) {
|
||||
zip.inputStream().buffered().use {
|
||||
unzip(it, folder, path, junkPath)
|
||||
fun File.unzip(folder: File, path: String = "", junkPath: Boolean = false) {
|
||||
inputStream().buffered().use {
|
||||
it.unzip(folder, path, junkPath)
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun unzip(zip: InputStream, folder: File, path: String, junkPath: Boolean) {
|
||||
fun InputStream.unzip(folder: File, path: String, junkPath: Boolean) {
|
||||
try {
|
||||
val zin = ZipInputStream(zip)
|
||||
val zin = ZipInputStream(this)
|
||||
var entry: ZipEntry
|
||||
while (true) {
|
||||
entry = zin.nextEntry ?: break
|
||||
|
||||
Reference in New Issue
Block a user