forked from ReVanced/revanced-cli
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
- Loading branch information
Showing
4 changed files
with
99 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,57 @@ | ||
package app.revanced.utils.adb | ||
|
||
internal object Constants { | ||
// template placeholder to replace a string in commands | ||
internal const val PLACEHOLDER = "TEMPLATE_PACKAGE_NAME" | ||
|
||
internal const val NAME_MOUNT_SCRIPT = "mount.sh" | ||
// utility commands | ||
private const val COMMAND_CHMOD_MOUNT = "chmod +x" | ||
internal const val COMMAND_PID_OF = "pidof -s" | ||
internal const val COMMAND_CREATE_DIR = "mkdir -p" | ||
internal const val COMMAND_LOGCAT = "logcat -c && logcat --pid=$($COMMAND_PID_OF $PLACEHOLDER)" | ||
internal const val COMMAND_RESTART = "monkey -p $PLACEHOLDER 1 && kill ${'$'}($COMMAND_PID_OF $PLACEHOLDER)" | ||
|
||
internal const val PATH_DATA = "/data/adb/revanced/" | ||
internal const val PATH_INIT_PUSH = "/sdcard/revanced" | ||
// default mount file name | ||
private const val NAME_MOUNT_SCRIPT = "mount_$PLACEHOLDER.sh" | ||
|
||
internal const val COMMAND_PID_OF = "pidof -s " | ||
internal const val COMMAND_CREATE_DIR = "mkdir -p " | ||
internal const val COMMAND_MOVE_BASE = "mv $PATH_INIT_PUSH $PATH_DATA/base.apk" | ||
internal const val COMMAND_MOVE_MOUNT = "mv $PATH_INIT_PUSH $PATH_DATA/$NAME_MOUNT_SCRIPT" | ||
internal const val COMMAND_CHMOD_MOUNT = "chmod +x $PATH_DATA" | ||
internal const val COMMAND_MOUNT = "./$PATH_DATA/$NAME_MOUNT_SCRIPT" | ||
internal const val COMMAND_UNMOUNT = "umount -l $(pm path $PLACEHOLDER | grep base | sed 's/package://g')" | ||
internal const val COMMAND_LOGCAT = "logcat -c && logcat --pid=$($COMMAND_PID_OF $PLACEHOLDER)" | ||
internal const val COMMAND_RUN_APP = "monkey -p $PLACEHOLDER 1" | ||
internal const val COMMAND_KILL_APP = "kill \$($COMMAND_PID_OF $PLACEHOLDER)" | ||
// initial directory to push files to via adb push | ||
internal const val PATH_INIT_PUSH = "/sdcard/revanced.delete" | ||
|
||
// revanced path | ||
internal const val PATH_REVANCED = "/data/adb/revanced/" | ||
|
||
// revanced apk path | ||
private const val PATH_REVANCED_APP = "$PATH_REVANCED$PLACEHOLDER.apk" | ||
|
||
// (un)mount script paths | ||
internal const val PATH_MOUNT = "/data/adb/service.d/$NAME_MOUNT_SCRIPT" | ||
internal const val PATH_UMOUNT = "/data/adb/post-fs-data.d/un$NAME_MOUNT_SCRIPT" | ||
|
||
// move to revanced apk path & set permissions | ||
internal const val COMMAND_INSTALL_APK = | ||
"base_path=\"$PATH_REVANCED_APP\" && mv $PATH_INIT_PUSH ${'$'}base_path && chmod 644 ${'$'}base_path && chown system:system ${'$'}base_path && chcon u:object_r:apk_data_file:s0 ${'$'}base_path" | ||
|
||
// install mount script & set permissions | ||
internal const val COMMAND_INSTALL_MOUNT = "mv $PATH_INIT_PUSH $PATH_MOUNT && $COMMAND_CHMOD_MOUNT $PATH_MOUNT" | ||
|
||
// install umount script & set permissions | ||
internal const val COMMAND_INSTALL_UMOUNT = "mv $PATH_INIT_PUSH $PATH_UMOUNT && $COMMAND_CHMOD_MOUNT $PATH_UMOUNT" | ||
|
||
// unmount script | ||
internal val CONTENT_UMOUNT_SCRIPT = | ||
""" | ||
#!/system/bin/sh | ||
while read line; do echo ${'$'}{line} | grep $PLACEHOLDER | awk '{print ${'$'}2}' | xargs umount -l; done< /proc/mounts | ||
""".trimIndent() | ||
|
||
// mount script | ||
internal val CONTENT_MOUNT_SCRIPT = | ||
""" | ||
base_path="$PATH_DATA/base.apk" | ||
#!/system/bin/sh | ||
while [ "${'$'}(getprop sys.boot_completed | tr -d '\r')" != "1" ]; do sleep 1; done | ||
base_path="$PATH_REVANCED_APP" | ||
stock_path=${'$'}{ pm path $PLACEHOLDER | grep base | sed 's/package://g' } | ||
umount -l ${'$'}stock_path | ||
rm ${'$'}base_path | ||
mv "$PATH_INIT_PUSH" ${'$'}base_path | ||
chmod 644 ${'$'}base_path | ||
chown system:system ${'$'}base_path | ||
chcon u:object_r:apk_data_file:s0 ${'$'}base_path | ||
mount -o bind ${'$'}base_path ${'$'}stock_path | ||
""".trimIndent() | ||
} |