Improve root detection, update libsu.

pull/27/head
Fox2Code 3 years ago
parent 7e4003b00f
commit ff2d5abda2

@ -64,7 +64,7 @@ dependencies {
// Utils // Utils
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.9.3' implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.9.3'
implementation 'com.squareup.okhttp3:okhttp-brotli:4.9.3' implementation 'com.squareup.okhttp3:okhttp-brotli:4.9.3'
implementation 'com.github.topjohnwu.libsu:io:4.0.0' implementation 'com.github.topjohnwu.libsu:io:4.0.2'
// Markdown // Markdown
implementation "io.noties.markwon:core:4.6.2" implementation "io.noties.markwon:core:4.6.2"

@ -256,7 +256,7 @@ public class InstallerActivity extends CompatActivity {
return; return;
} }
installerMonitor = new InstallerMonitor(installScript); installerMonitor = new InstallerMonitor(installScript);
installJob = Shell.sh("export MMM_EXT_SUPPORT=1", installJob = Shell.cmd("export MMM_EXT_SUPPORT=1",
"cd \"" + this.moduleCache.getAbsolutePath() + "\"", "cd \"" + this.moduleCache.getAbsolutePath() + "\"",
"sh \"" + installScript.getAbsolutePath() + "\"" + "sh \"" + installScript.getAbsolutePath() + "\"" +
" /dev/null 1 \"" + file.getAbsolutePath() + "\"") " /dev/null 1 \"" + file.getAbsolutePath() + "\"")
@ -324,11 +324,11 @@ public class InstallerActivity extends CompatActivity {
installerMonitor = new InstallerMonitor(installExecutable); installerMonitor = new InstallerMonitor(installExecutable);
if (moduleId != null) installerMonitor.setForCleanUp(moduleId); if (moduleId != null) installerMonitor.setForCleanUp(moduleId);
if (noExtensions) { if (noExtensions) {
installJob = Shell.su(arch32, // No Extensions installJob = Shell.cmd(arch32, // No Extensions
"cd \"" + this.moduleCache.getAbsolutePath() + "\"", "cd \"" + this.moduleCache.getAbsolutePath() + "\"",
installCommand).to(installerController, installerMonitor); installCommand).to(installerController, installerMonitor);
} else { } else {
installJob = Shell.su(arch32, "export MMM_EXT_SUPPORT=1", installJob = Shell.cmd(arch32, "export MMM_EXT_SUPPORT=1",
"export MMM_USER_LANGUAGE=" + (MainApplication.isForceEnglish() ? "export MMM_USER_LANGUAGE=" + (MainApplication.isForceEnglish() ?
"en-US" : Resources.getSystem() "en-US" : Resources.getSystem()
.getConfiguration().locale.toLanguageTag()), .getConfiguration().locale.toLanguageTag()),

@ -7,8 +7,10 @@ import androidx.annotation.NonNull;
import com.fox2code.mmm.Constants; import com.fox2code.mmm.Constants;
import com.fox2code.mmm.MainApplication; import com.fox2code.mmm.MainApplication;
import com.fox2code.mmm.utils.Files;
import com.topjohnwu.superuser.NoShellException; import com.topjohnwu.superuser.NoShellException;
import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.io.SuFile;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -87,17 +89,19 @@ public class InstallerInitializer extends Shell.Initializer {
int MAGISK_VERSION_CODE; int MAGISK_VERSION_CODE;
if (MAGISK_PATH != null && !forceCheck) return MAGISK_PATH; if (MAGISK_PATH != null && !forceCheck) return MAGISK_PATH;
ArrayList<String> output = new ArrayList<>(); ArrayList<String> output = new ArrayList<>();
if(!Shell.su( "magisk -V", "magisk --path").to(output).exec().isSuccess()) { if(!Shell.cmd("magisk -V", "magisk --path").to(output).exec().isSuccess()) {
return null; return null;
} }
MAGISK_PATH = output.size() < 2 ? "" : output.get(1); MAGISK_PATH = output.size() < 2 ? "" : output.get(1);
Log.d(TAG, "Magisk runtime path: " + MAGISK_PATH);
MAGISK_VERSION_CODE = Integer.parseInt(output.get(0)); MAGISK_VERSION_CODE = Integer.parseInt(output.get(0));
Log.d(TAG, "Magisk version code: " + MAGISK_VERSION_CODE);
if (MAGISK_VERSION_CODE >= Constants.MAGISK_VER_CODE_FLAT_MODULES && if (MAGISK_VERSION_CODE >= Constants.MAGISK_VER_CODE_FLAT_MODULES &&
MAGISK_VERSION_CODE < Constants.MAGISK_VER_CODE_PATH_SUPPORT && MAGISK_VERSION_CODE < Constants.MAGISK_VER_CODE_PATH_SUPPORT &&
(MAGISK_PATH.isEmpty() || !new File(MAGISK_PATH).exists())) { (MAGISK_PATH.isEmpty() || !new File(MAGISK_PATH).exists())) {
MAGISK_PATH = "/sbin"; MAGISK_PATH = "/sbin";
} }
if (MAGISK_PATH.length() != 0 && new File(MAGISK_PATH).exists()) { if (MAGISK_PATH.length() != 0 && Files.existsSU(new File(MAGISK_PATH))) {
InstallerInitializer.MAGISK_PATH = MAGISK_PATH; InstallerInitializer.MAGISK_PATH = MAGISK_PATH;
} else { } else {
Log.e(TAG, "Failed to get Magisk path (Got " + MAGISK_PATH + ")"); Log.e(TAG, "Failed to get Magisk path (Got " + MAGISK_PATH + ")");

@ -243,13 +243,13 @@ public final class ModuleManager {
line.equals("/data/adb/magisk.db")) continue; line.equals("/data/adb/magisk.db")) continue;
line = line.replace("\\", "\\\\") line = line.replace("\\", "\\\\")
.replace("\"", "\\\""); .replace("\"", "\\\"");
Shell.su("rm -rf \"" + line + "\"").exec(); Shell.cmd("rm -rf \"" + line + "\"").exec();
} }
} }
} catch (IOException ignored) {} } catch (IOException ignored) {}
Shell.su("rm -rf /data/adb/modules/" + escapedId + "/").exec(); Shell.cmd("rm -rf /data/adb/modules/" + escapedId + "/").exec();
Shell.su("rm -f /data/adb/modules/." + escapedId + "-files").exec(); Shell.cmd("rm -f /data/adb/modules/." + escapedId + "-files").exec();
Shell.su("rm -rf /data/adb/modules_update/" + escapedId + "/").exec(); Shell.cmd("rm -rf /data/adb/modules_update/" + escapedId + "/").exec();
moduleInfo.flags = ModuleInfo.FLAG_METADATA_INVALID; moduleInfo.flags = ModuleInfo.FLAG_METADATA_INVALID;
return true; return true;
} }

@ -1,5 +1,6 @@
package com.fox2code.mmm.utils; package com.fox2code.mmm.utils;
import com.topjohnwu.superuser.io.SuFile;
import com.topjohnwu.superuser.io.SuFileInputStream; import com.topjohnwu.superuser.io.SuFileInputStream;
import com.topjohnwu.superuser.io.SuFileOutputStream; import com.topjohnwu.superuser.io.SuFileOutputStream;
@ -43,6 +44,10 @@ public class Files {
} }
} }
public static boolean existsSU(File file) {
return file.exists() || new SuFile(file.getAbsolutePath()).exists();
}
public static void copy(InputStream inputStream,OutputStream outputStream) throws IOException { public static void copy(InputStream inputStream,OutputStream outputStream) throws IOException {
int nRead; int nRead;
byte[] data = new byte[16384]; byte[] data = new byte[16384];

Loading…
Cancel
Save