Skip to content

Commit

Permalink
Merge pull request #8 from sysuid/KernelSU
Browse files Browse the repository at this point in the history
add KernelSU support
  • Loading branch information
Chainfire authored Jul 8, 2023
2 parents 22e3cf7 + f760667 commit 8379b10
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
25 changes: 23 additions & 2 deletions liveBootAni2/src/main/java/eu/chainfire/liveboot/Installer.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import eu.chainfire.liveboot.shell.Runner;

public class Installer {
public enum Mode { SU_D, INIT_D, SU_SU_D, SBIN_SU_D, MAGISK_CORE, MAGISK_ADB }
public enum Mode { SU_D, INIT_D, SU_SU_D, SBIN_SU_D, MAGISK_CORE, MAGISK_ADB, KERNELSU }

private static final int LAST_SCRIPT_UPDATE = 182;
private static final String[] SYSTEM_SCRIPTS_SU_D = new String[] { "/system/su.d/0000liveboot" };
Expand All @@ -48,6 +48,7 @@ public enum Mode { SU_D, INIT_D, SU_SU_D, SBIN_SU_D, MAGISK_CORE, MAGISK_ADB }
private static final String[] SYSTEM_SCRIPTS_SBIN_SU_D = new String[] { "/sbin/supersu/su.d/0000liveboot" };
private static final String[] SYSTEM_SCRIPTS_MAGISK_CORE = new String[] { "/sbin/.core/img/.core/post-fs-data.d/0000liveboot", "/sbin/.core/img/.core/service.d/0000liveboot" };
private static final String[] SYSTEM_SCRIPTS_MAGISK_ADB = new String[] { "/data/adb/post-fs-data.d/0000liveboot", "/data/adb/service.d/0000liveboot" };
private static final String[] SYSTEM_SCRIPTS_KERNELSU = new String[] { "/data/adb/post-fs-data.d/0000liveboot", "/data/adb/service.d/0000liveboot" };

public static String[] getScript(Mode mode) {
switch (mode) {
Expand All @@ -57,6 +58,7 @@ public static String[] getScript(Mode mode) {
case SBIN_SU_D: return SYSTEM_SCRIPTS_SBIN_SU_D;
case MAGISK_CORE: return SYSTEM_SCRIPTS_MAGISK_CORE;
case MAGISK_ADB: return SYSTEM_SCRIPTS_MAGISK_ADB;
case KERNELSU: return SYSTEM_SCRIPTS_KERNELSU;
}
return null;
}
Expand Down Expand Up @@ -319,6 +321,24 @@ public static void install(Context context, Mode mode) {
commands.add(String.format(Locale.ENGLISH, Toolbox.command("chown") + " 0.0 %s", script));
commands.add(String.format(Locale.ENGLISH, Toolbox.command("chmod") + " 0700 %s", script));
}
} else if (mode == Mode.KERNELSU) {
commands.add(Toolbox.command("mkdir") + " /data/adb/post-fs-data.d");
commands.add(Toolbox.command("chown") + " 0.0 /data/adb/post-fs-data.d");
commands.add(Toolbox.command("chmod") + " 0755 /data/adb/post-fs-data.d");
for (String script : SYSTEM_SCRIPTS_KERNELSU) {
commands.add(String.format(Locale.ENGLISH, "echo '#!%s' > %s", shell, script));
commands.add(String.format(Locale.ENGLISH, "echo '{' >> %s", script));
commands.add(String.format(Locale.ENGLISH, "echo ' while (true); do' >> %s", script));
commands.add(String.format(Locale.ENGLISH, "echo ' if [ -d \"%s\" ]; then' >> %s", filesDir, script));
commands.add(String.format(Locale.ENGLISH, "echo ' break;' >> %s", script));
commands.add(String.format(Locale.ENGLISH, "echo ' fi' >> %s", script));
commands.add(String.format(Locale.ENGLISH, "echo ' sleep 0.1' >> %s", script));
commands.add(String.format(Locale.ENGLISH, "echo ' done' >> %s", script));
commands.add(String.format(Locale.ENGLISH, "echo ' %s %s/liveboot' >> %s", shell, filesDir, script));
commands.add(String.format(Locale.ENGLISH, "echo '} &' >> %s", script));
commands.add(String.format(Locale.ENGLISH, Toolbox.command("chown") + " 0.0 %s", script));
commands.add(String.format(Locale.ENGLISH, Toolbox.command("chmod") + " 0700 %s", script));
}
}
if ((mode == Mode.SU_D) || (mode == Mode.INIT_D)) {
commands.add("mount -o ro,remount /system /system");
Expand Down Expand Up @@ -362,7 +382,8 @@ public static void uninstall(Context context) {
SYSTEM_SCRIPTS_SU_SU_D,
SYSTEM_SCRIPTS_SBIN_SU_D,
SYSTEM_SCRIPTS_MAGISK_CORE,
SYSTEM_SCRIPTS_MAGISK_ADB
SYSTEM_SCRIPTS_MAGISK_ADB,
SYSTEM_SCRIPTS_KERNELSU
}) {
for (String script : scripts) {
commands.add(String.format(Locale.ENGLISH, Toolbox.command("rm") + " %s", script));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,20 +207,22 @@ public void onCommandResult(int commandCode, int exitCode, List<String> output)
boolean sbinsud = false;
boolean magiskcore = false;
boolean magiskadb = false;
boolean kernelsu = false;

List<String> ls = Shell.SU.run("ls -ld /system/etc/init.d /su/su.d /sbin/supersu/su.d /data/adb/post-fs-data.d /sbin/.core/img/.core/post-fs-data.d 2> /dev/null");
List<String> ls = Shell.SU.run("ls -ld /system/etc/init.d /su/su.d /sbin/supersu/su.d /data/adb/post-fs-data.d /sbin/.core/img/.core/post-fs-data.d /data/adb/ksud 2> /dev/null");
if (ls != null) {
for (String line : ls) {
if (line.contains("init.d")) initd = true;
if (line.contains("su.d")) susud = true;
if (line.contains("su.d")) sbinsud = true;
if (line.contains("/adb/post-fs-data.d")) magiskadb = true;
if (line.contains("/.core/post-fs-data.d")) magiskcore = true;
if (line.contains("/adb/ksud")) kernelsu = true;
}
}

if (SuperSU && !SuperSU240 && !initd) return 2;
if (!SuperSU && !initd && !magiskcore && !magiskadb) return 3;
if (!SuperSU && !initd && !magiskcore && !magiskadb && !kernelsu) return 3;

if (magiskadb) {
mode = Mode.MAGISK_ADB;
Expand All @@ -232,6 +234,8 @@ public void onCommandResult(int commandCode, int exitCode, List<String> output)
mode = Mode.SU_SU_D;
} else if (!SuperSU240 && initd) {
mode = Mode.INIT_D;
} else if (kernelsu) {
mode = Mode.KERNELSU;
}

if (iap.haveService()) {
Expand Down

0 comments on commit 8379b10

Please sign in to comment.