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

Commit d4ed158

Browse files
committed
Add support for Dynamic Installer (By BlassGO) magisk module template
1 parent efa6c14 commit d4ed158

File tree

5 files changed

+86
-17
lines changed

5 files changed

+86
-17
lines changed

app/src/main/assets/module_installer_compat.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ grep_get_prop() {
4242
}
4343
fi
4444

45+
# Prevent setenforce because it can causes issues on some devices
46+
setenforce() { true; }
4547
# prevent old modules from disabling hidden_apis, please use LSPosed library instead.
4648
# See: https://github.com/LSPosed/AndroidHiddenApiBypass
4749
settings() {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/sbin/sh
2+
3+
# echo before loading util_functions
4+
ui_print() { echo "$1"; }
5+
6+
OUTFD=$2
7+
ZIPFILE=$3
8+
TMPDIR=/dev/tmp
9+
10+
# Prevent setenforce because it can causes issues on some devices
11+
setenforce() { true; }
12+
# prevent old modules from disabling hidden_apis, please use LSPosed library instead.
13+
# See: https://github.com/LSPosed/AndroidHiddenApiBypass
14+
settings() {
15+
if [ "$1" == "put" ] && [ "$2" == "global" ] && ([ "$3" == "hidden_api_policy" ] || \
16+
[ "$3" == "hidden_api_policy_p_apps" ] || [ "$3" == "hidden_api_policy_pre_p_apps" ]); then
17+
true
18+
else
19+
"$(which settings)" "$@"
20+
fi
21+
}
22+
23+
rm -rf $TMPDIR 2>/dev/null
24+
mkdir -p $TMPDIR
25+
chcon u:object_r:system_file:s0 $TMPDIR || true
26+
cd $TMPDIR
27+
28+
abort() {
29+
ui_print "$1"
30+
rm -rf $TMPDIR
31+
exit 1
32+
}
33+
34+
unzip -o "$ZIPFILE" "META-INF/com/google/android/update-binary" -d $TMPDIR >&2
35+
[ ! -f "$TMPDIR/META-INF/com/google/android/update-binary" ] && abort "! Unable to extract zip file!"
36+
37+
. "$TMPDIR/META-INF/com/google/android/update-binary"
38+
39+
rm -rf $TMPDIR
40+
exit 0

app/src/main/java/com/fox2code/mmm/AppUpdateManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class AppUpdateManager {
2929
public static final int FLAG_COMPAT_FORCE_ANSI = 0x0040;
3030
public static final int FLAG_COMPAT_FORCE_HIDE = 0x0080;
3131
public static final int FLAG_COMPAT_MMT_REBORN = 0x0100;
32+
public static final int FLAG_COMPAT_ZIP_WRAPPER = 0x0200;
3233
private static final String TAG = "AppUpdateManager";
3334
private static final AppUpdateManager INSTANCE = new AppUpdateManager();
3435
private static final String RELEASES_API_URL =
@@ -217,6 +218,9 @@ private void parseCompatibilityFlags(InputStream inputStream) throws IOException
217218
case "mmtReborn":
218219
value |= FLAG_COMPAT_MMT_REBORN;
219220
break;
221+
case "wrapper":
222+
value |= FLAG_COMPAT_ZIP_WRAPPER;
223+
break;
220224
}
221225
}
222226
compatDataId.put(line.substring(0, i), value);

app/src/main/java/com/fox2code/mmm/NotificationType.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,11 @@ public boolean shouldRemove() {
9393
IntentHelper.openFileTo(compatActivity, module, (d, u, s) -> {
9494
if (s == IntentHelper.RESPONSE_FILE) {
9595
try {
96-
boolean needPatch;
97-
try (ZipFile zipFile = new ZipFile(d)) {
98-
needPatch = zipFile.getEntry("module.prop") == null &&
99-
zipFile.getEntry("anykernel.sh") == null;
100-
}
101-
if (needPatch) {
96+
if (needPatch(d)) {
10297
Files.patchModuleSimple(Files.read(d),
10398
new FileOutputStream(d));
10499
}
105-
try (ZipFile zipFile = new ZipFile(d)) {
106-
needPatch = zipFile.getEntry("module.prop") == null &&
107-
zipFile.getEntry("anykernel.sh") == null;
108-
}
109-
if (needPatch) {
100+
if (needPatch(d)) {
110101
if (d.exists() && !d.delete())
111102
Log.w(TAG, "Failed to delete non module zip");
112103
Toast.makeText(compatActivity,
@@ -141,6 +132,14 @@ public boolean shouldRemove() {
141132
}
142133
};
143134

135+
private static boolean needPatch(File target) throws IOException {
136+
try (ZipFile zipFile = new ZipFile(target)) {
137+
return zipFile.getEntry("module.prop") == null &&
138+
zipFile.getEntry("anykernel.sh") == null &&
139+
zipFile.getEntry("META-INF/com/google/android/magisk/module.prop") == null;
140+
}
141+
}
142+
144143
@StringRes
145144
public final int textId;
146145
@DrawableRes

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

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ protected void onCreate(Bundle savedInstanceState) {
189189
boolean noPatch = false;
190190
boolean isModule = false;
191191
boolean isAnyKernel3 = false;
192+
boolean isInstallZipModule = false;
192193
errMessage = "File is not a valid zip file";
193194
try (ZipInputStream zipInputStream = new ZipInputStream(
194195
new ByteArrayInputStream(rawModule))) {
@@ -203,14 +204,21 @@ protected void onCreate(Bundle savedInstanceState) {
203204
noPatch = true;
204205
isModule = true;
205206
break;
207+
} if (entryName.equals("META-INF/com/google/android/magisk/module.prop")) {
208+
noPatch = true;
209+
isInstallZipModule = true;
210+
break;
206211
} else if (entryName.endsWith("/tools/ak3-core.sh")) {
207212
isAnyKernel3 = true;
213+
} else if (entryName.endsWith(
214+
"/META-INF/com/google/android/magisk/module.prop")) {
215+
isInstallZipModule = true;
208216
} else if (entryName.endsWith("/module.prop")) {
209217
isModule = true;
210218
}
211219
}
212220
}
213-
if (!isModule && !isAnyKernel3) {
221+
if (!isModule && !isAnyKernel3 && !isInstallZipModule) {
214222
if (androidacyBlame) {
215223
this.installerTerminal.addLine(
216224
"! Note: The following error is probably an Androidacy backend error");
@@ -313,6 +321,7 @@ private void doInstall(File file, boolean noExtensions, boolean rootless) {
313321
String moduleId = null;
314322
boolean anyKernel3 = false;
315323
boolean magiskModule = false;
324+
boolean installZipMagiskModule = false;
316325
boolean mmtReborn = false;
317326
String MAGISK_PATH = InstallerInitializer.peekMagiskPath();
318327
if (MAGISK_PATH == null) {
@@ -338,10 +347,11 @@ private void doInstall(File file, boolean noExtensions, boolean rootless) {
338347
bufferedReader.close();
339348
}
340349
}
341-
if (zipFile.getEntry( // Check if module hard require 32bit support
350+
if ((zipFile.getEntry( // Check if module hard require 32bit support
342351
"common/addon/Volume-Key-Selector/tools/arm64/keycheck") == null &&
343-
zipFile.getEntry(
344-
"common/addon/Volume-Key-Selector/install.sh") != null) {
352+
zipFile.getEntry("common/addon/Volume-Key-Selector/install.sh") != null) ||
353+
(zipFile.getEntry("META-INF/zbin/keycheck_arm64") == null &&
354+
zipFile.getEntry("META-INF/zbin/keycheck_arm") != null)) {
345355
needs32bit = true;
346356
}
347357
ZipEntry moduleProp = zipFile.getEntry("module.prop");
@@ -351,8 +361,11 @@ private void doInstall(File file, boolean noExtensions, boolean rootless) {
351361
zipFile.getEntry("setup.sh") != null && magiskModule) {
352362
mmtReborn = true; // MMT-Reborn require a separate runtime
353363
}
354-
moduleId = PropUtils.readModuleId(zipFile
355-
.getInputStream(zipFile.getEntry("module.prop")));
364+
if (!magiskModule && (moduleProp = zipFile.getEntry(
365+
"META-INF/com/google/android/magisk/module.prop")) != null) {
366+
installZipMagiskModule = true;
367+
}
368+
moduleId = PropUtils.readModuleId(zipFile.getInputStream(moduleProp));
356369
} catch (IOException ignored) {
357370
}
358371
int compatFlags = AppUpdateManager.getFlagsForModule(moduleId);
@@ -406,6 +419,17 @@ private void doInstall(File file, boolean noExtensions, boolean rootless) {
406419
installCommand = "unshare -m " + ASH + " \"" +
407420
installExecutable.getAbsolutePath() + "\"" +
408421
" 3 1 \"" + file.getAbsolutePath() + "\"";
422+
} else if (installZipMagiskModule ||
423+
(compatFlags & AppUpdateManager.FLAG_COMPAT_ZIP_WRAPPER) != 0) {
424+
installExecutable = this.extractInstallScript("module_installer_wrapper.sh");
425+
if (installExecutable == null) {
426+
this.setInstallStateFinished(false,
427+
"! Failed to extract Magisk module wrapper script", "");
428+
return;
429+
}
430+
installCommand = ASH + " \"" +
431+
installExecutable.getAbsolutePath() + "\"" +
432+
" 3 1 \"" + file.getAbsolutePath() + "\"";
409433
} else if (InstallerInitializer.peekMagiskVersion() >=
410434
Constants.MAGISK_VER_CODE_INSTALL_COMMAND &&
411435
((compatFlags & AppUpdateManager.FLAG_COMPAT_MAGISK_CMD) != 0 ||

0 commit comments

Comments
 (0)