From 8a1ab478a353f43de97ce0d5f990d4b9f61d6389 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sat, 23 Dec 2023 19:01:26 +0100 Subject: [PATCH] fix: Prevent crash by escaping string correctly --- lib/services/root_api.dart | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/services/root_api.dart b/lib/services/root_api.dart index 41691d3098..83d02e4b6e 100644 --- a/lib/services/root_api.dart +++ b/lib/services/root_api.dart @@ -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" @@ -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); } @@ -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(); +}