From 8fd942a80820db7994ba0b2717c4189a90f02d74 Mon Sep 17 00:00:00 2001 From: Alberto Ponces Date: Sun, 14 Aug 2022 21:32:03 +0100 Subject: [PATCH] fix: root installation (still wip) --- assets/i18n/en.json | 2 +- lib/services/root_api.dart | 31 ++++++++++++------- .../views/installer/installer_viewmodel.dart | 11 ++++++- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/assets/i18n/en.json b/assets/i18n/en.json index 47182e67..82009c45 100644 --- a/assets/i18n/en.json +++ b/assets/i18n/en.json @@ -69,7 +69,7 @@ }, "rootCheckerView": { "widgetTitle": "Is your device rooted?", - "widgetDescription": "Don't know what's this or prefer to use non-root version? Just click button below!", + "widgetDescription": "Don't know what this means or prefer to use non-root version? Just click on the button below!", "grantPermission": "Grant Root Permission", "grantedPermission": "Magisk permission granted: {isRooted}" } diff --git a/lib/services/root_api.dart b/lib/services/root_api.dart index f187e74b..36a8bca7 100644 --- a/lib/services/root_api.dart +++ b/lib/services/root_api.dart @@ -26,8 +26,9 @@ class RootAPI { String patchedFilePath, ) async { try { - Directory managerDir = Directory(managerDirPath); - managerDir.createSync(); + await Root.exec( + cmd: 'mkdir "$managerDirPath"', + ); String newPatchedFilePath = '$managerDirPath/$packageName.apk'; installServiceDScript( packageName, @@ -39,15 +40,17 @@ class RootAPI { originalFilePath, newPatchedFilePath, ); - File(patchedFilePath).renameSync(newPatchedFilePath); await Root.exec( - cmd: 'chmod 644 $newPatchedFilePath', + cmd: 'cp $patchedFilePath $newPatchedFilePath', ); await Root.exec( - cmd: 'chown system:system $newPatchedFilePath', + cmd: 'chmod 644 "$newPatchedFilePath"', ); await Root.exec( - cmd: 'chcon u:object_r:apk_data_file:s0 $newPatchedFilePath', + cmd: 'chown system:system "$newPatchedFilePath"', + ); + await Root.exec( + cmd: 'chcon u:object_r:apk_data_file:s0 "$newPatchedFilePath"', ); return true; } on Exception { @@ -65,9 +68,11 @@ class RootAPI { 'sleep 1\n' 'chcon u:object_r:apk_data_file:s0 $patchedFilePath\n' 'mount -o bind $patchedFilePath $originalFilePath'; - File scriptFile = File('$serviceDDirPath/$packageName.sh'); - await scriptFile.writeAsString(content); - await Root.exec(cmd: 'chmod 744 ${scriptFile.path}'); + String scriptFilePath = '$serviceDDirPath/$packageName.sh'; + await Root.exec( + cmd: 'echo "$content" > "$scriptFilePath"', + ); + await Root.exec(cmd: 'chmod 744 "$scriptFilePath"'); } Future installPostFsDataScript( @@ -78,8 +83,10 @@ class RootAPI { String content = '#!/system/bin/sh\n' 'while read line; do echo \$line | grep $originalFilePath | ' 'awk \'{print \$2}\' | xargs umount -l; done< /proc/mounts'; - File scriptFile = File('$postFsDataDirPath/$packageName.sh'); - await scriptFile.writeAsString(content); - await Root.exec(cmd: 'chmod 744 ${scriptFile.path}'); + String scriptFilePath = '$postFsDataDirPath/$packageName.sh'; + await Root.exec( + cmd: 'echo "$content" > "$scriptFilePath"', + ); + await Root.exec(cmd: 'chmod 744 $scriptFilePath'); } } diff --git a/lib/ui/views/installer/installer_viewmodel.dart b/lib/ui/views/installer/installer_viewmodel.dart index 82a080c2..d2203988 100644 --- a/lib/ui/views/installer/installer_viewmodel.dart +++ b/lib/ui/views/installer/installer_viewmodel.dart @@ -115,7 +115,16 @@ class InstallerViewModel extends BaseViewModel { PatchedApplication? selectedApp = locator().selectedApp; if (selectedApp != null) { - await locator().installPatchedFile(selectedApp); + addLog(selectedApp.isRooted + ? 'Installing patched file using root method...' + : 'Installing patched file using nonroot method...'); + bool isSucess = + await locator().installPatchedFile(selectedApp); + if (isSucess) { + addLog('Done'); + } else { + addLog('An error occurred! Aborting...'); + } } }