Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit ff2d5ab

Browse files
committed
Improve root detection, update libsu.
1 parent 7e4003b commit ff2d5ab

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ dependencies {
6464
// Utils
6565
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.9.3'
6666
implementation 'com.squareup.okhttp3:okhttp-brotli:4.9.3'
67-
implementation 'com.github.topjohnwu.libsu:io:4.0.0'
67+
implementation 'com.github.topjohnwu.libsu:io:4.0.2'
6868

6969
// Markdown
7070
implementation "io.noties.markwon:core:4.6.2"

app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ private void doInstall(File file,boolean noExtensions,boolean rootless) {
256256
return;
257257
}
258258
installerMonitor = new InstallerMonitor(installScript);
259-
installJob = Shell.sh("export MMM_EXT_SUPPORT=1",
259+
installJob = Shell.cmd("export MMM_EXT_SUPPORT=1",
260260
"cd \"" + this.moduleCache.getAbsolutePath() + "\"",
261261
"sh \"" + installScript.getAbsolutePath() + "\"" +
262262
" /dev/null 1 \"" + file.getAbsolutePath() + "\"")
@@ -324,11 +324,11 @@ private void doInstall(File file,boolean noExtensions,boolean rootless) {
324324
installerMonitor = new InstallerMonitor(installExecutable);
325325
if (moduleId != null) installerMonitor.setForCleanUp(moduleId);
326326
if (noExtensions) {
327-
installJob = Shell.su(arch32, // No Extensions
327+
installJob = Shell.cmd(arch32, // No Extensions
328328
"cd \"" + this.moduleCache.getAbsolutePath() + "\"",
329329
installCommand).to(installerController, installerMonitor);
330330
} else {
331-
installJob = Shell.su(arch32, "export MMM_EXT_SUPPORT=1",
331+
installJob = Shell.cmd(arch32, "export MMM_EXT_SUPPORT=1",
332332
"export MMM_USER_LANGUAGE=" + (MainApplication.isForceEnglish() ?
333333
"en-US" : Resources.getSystem()
334334
.getConfiguration().locale.toLanguageTag()),

app/src/main/java/com/fox2code/mmm/installer/InstallerInitializer.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
import com.fox2code.mmm.Constants;
99
import com.fox2code.mmm.MainApplication;
10+
import com.fox2code.mmm.utils.Files;
1011
import com.topjohnwu.superuser.NoShellException;
1112
import com.topjohnwu.superuser.Shell;
13+
import com.topjohnwu.superuser.io.SuFile;
1214

1315
import java.io.File;
1416
import java.util.ArrayList;
@@ -87,17 +89,19 @@ private static String tryGetMagiskPath(boolean forceCheck) {
8789
int MAGISK_VERSION_CODE;
8890
if (MAGISK_PATH != null && !forceCheck) return MAGISK_PATH;
8991
ArrayList<String> output = new ArrayList<>();
90-
if(!Shell.su( "magisk -V", "magisk --path").to(output).exec().isSuccess()) {
92+
if(!Shell.cmd("magisk -V", "magisk --path").to(output).exec().isSuccess()) {
9193
return null;
9294
}
9395
MAGISK_PATH = output.size() < 2 ? "" : output.get(1);
96+
Log.d(TAG, "Magisk runtime path: " + MAGISK_PATH);
9497
MAGISK_VERSION_CODE = Integer.parseInt(output.get(0));
98+
Log.d(TAG, "Magisk version code: " + MAGISK_VERSION_CODE);
9599
if (MAGISK_VERSION_CODE >= Constants.MAGISK_VER_CODE_FLAT_MODULES &&
96100
MAGISK_VERSION_CODE < Constants.MAGISK_VER_CODE_PATH_SUPPORT &&
97101
(MAGISK_PATH.isEmpty() || !new File(MAGISK_PATH).exists())) {
98102
MAGISK_PATH = "/sbin";
99103
}
100-
if (MAGISK_PATH.length() != 0 && new File(MAGISK_PATH).exists()) {
104+
if (MAGISK_PATH.length() != 0 && Files.existsSU(new File(MAGISK_PATH))) {
101105
InstallerInitializer.MAGISK_PATH = MAGISK_PATH;
102106
} else {
103107
Log.e(TAG, "Failed to get Magisk path (Got " + MAGISK_PATH + ")");

app/src/main/java/com/fox2code/mmm/manager/ModuleManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,13 @@ public boolean masterClear(ModuleInfo moduleInfo) {
243243
line.equals("/data/adb/magisk.db")) continue;
244244
line = line.replace("\\", "\\\\")
245245
.replace("\"", "\\\"");
246-
Shell.su("rm -rf \"" + line + "\"").exec();
246+
Shell.cmd("rm -rf \"" + line + "\"").exec();
247247
}
248248
}
249249
} catch (IOException ignored) {}
250-
Shell.su("rm -rf /data/adb/modules/" + escapedId + "/").exec();
251-
Shell.su("rm -f /data/adb/modules/." + escapedId + "-files").exec();
252-
Shell.su("rm -rf /data/adb/modules_update/" + escapedId + "/").exec();
250+
Shell.cmd("rm -rf /data/adb/modules/" + escapedId + "/").exec();
251+
Shell.cmd("rm -f /data/adb/modules/." + escapedId + "-files").exec();
252+
Shell.cmd("rm -rf /data/adb/modules_update/" + escapedId + "/").exec();
253253
moduleInfo.flags = ModuleInfo.FLAG_METADATA_INVALID;
254254
return true;
255255
}

app/src/main/java/com/fox2code/mmm/utils/Files.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fox2code.mmm.utils;
22

3+
import com.topjohnwu.superuser.io.SuFile;
34
import com.topjohnwu.superuser.io.SuFileInputStream;
45
import com.topjohnwu.superuser.io.SuFileOutputStream;
56

@@ -43,6 +44,10 @@ public static byte[] readSU(File file) throws IOException {
4344
}
4445
}
4546

47+
public static boolean existsSU(File file) {
48+
return file.exists() || new SuFile(file.getAbsolutePath()).exists();
49+
}
50+
4651
public static void copy(InputStream inputStream,OutputStream outputStream) throws IOException {
4752
int nRead;
4853
byte[] data = new byte[16384];

0 commit comments

Comments
 (0)