Skip to content

Commit

Permalink
fix: Prevent crash by escaping string correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Dec 23, 2023
1 parent 2ae8d49 commit 8a1ab47
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/services/root_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class RootAPI {
await Root.exec(
cmd: 'mkdir -p "$_serviceDDirPath"',
);
final String content = '''
final String mountScript = '''
#!/system/bin/sh
MAGISKTMP="\$(magisk --path)" || MAGISKTMP=/sbin
MIRROR="\$MAGISKTMP/.magisk/mirror"
Expand All @@ -160,18 +160,18 @@ class RootAPI {
until [ -d "/sdcard/Android" ]; do sleep 1; done
base_path=$_revancedDirPath/$packageName/base.apk
stock_path=\$(pm path $packageName | grep base | sed 's/package://g' )
stock_path=\$(pm path $packageName | grep base | sed "s/package://g" )
chcon u:object_r:apk_data_file:s0 \$base_path
mount -o bind \$MIRROR\$base_path \$stock_path
# Kill the app to force it to restart the mounted APK in case it's already running
# Kill the app to force it to restart the mounted APK in case it is already running
am force-stop $packageName
'''
.trim();
.trimMultilineString();
final String scriptFilePath = '$_serviceDDirPath/$packageName.sh';
await Root.exec(
cmd: 'echo \'$content\' > "$scriptFilePath"',
cmd: 'echo \'$mountScript\' > "$scriptFilePath"',
);
await setPermissions('0744', '', '', scriptFilePath);
}
Expand Down Expand Up @@ -215,3 +215,10 @@ class RootAPI {
}
}
}

// Remove leading spaces manually until
// https://github.com/dart-lang/language/issues/559 is closed
extension StringExtension on String {
String trimMultilineString() =>
split('\n').map((line) => line.trim()).join('\n').trim();
}

0 comments on commit 8a1ab47

Please sign in to comment.