From 7db4942bba7b27d1b8d1a73a0142a3c055aa4c2f Mon Sep 17 00:00:00 2001 From: brosssh Date: Thu, 29 May 2025 10:19:16 +0200 Subject: [PATCH] fix: Make ShellCommandRunner run without root Currently, every command run by a ShellCommandRunner will be run with su (root required). With this PR, root will only be required from a RootInstaller. Also remove latest \n from shell output --- .../library/installation/command/AdbShellCommandRunner.kt | 4 ++-- .../library/installation/command/ShellCommandRunner.kt | 2 +- .../revanced/library/installation/installer/RootInstaller.kt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commonMain/kotlin/app/revanced/library/installation/command/AdbShellCommandRunner.kt b/src/commonMain/kotlin/app/revanced/library/installation/command/AdbShellCommandRunner.kt index aec0aa7..19e9c83 100644 --- a/src/commonMain/kotlin/app/revanced/library/installation/command/AdbShellCommandRunner.kt +++ b/src/commonMain/kotlin/app/revanced/library/installation/command/AdbShellCommandRunner.kt @@ -35,7 +35,7 @@ class AdbShellCommandRunner : ShellCommandRunner { override fun runCommand(command: String) = device.shellProcessBuilder(command).start().let { process -> object : RunResult { override val exitCode by lazy { process.waitFor() } - override val output by lazy { process.inputStream.bufferedReader().readText() } + override val output by lazy { process.inputStream.bufferedReader().readText().removeSuffix("\n") } override val error by lazy { process.errorStream.bufferedReader().readText() } override fun waitFor() { @@ -44,7 +44,7 @@ class AdbShellCommandRunner : ShellCommandRunner { } } - override fun hasRootPermission(): Boolean = invoke("whoami").exitCode == 0 + override fun hasRootPermission(): Boolean = invoke("su -c whoami").exitCode == 0 override fun write(content: InputStream, targetFilePath: String) = device.push(content, System.currentTimeMillis(), 644, RemoteFile(targetFilePath)) diff --git a/src/commonMain/kotlin/app/revanced/library/installation/command/ShellCommandRunner.kt b/src/commonMain/kotlin/app/revanced/library/installation/command/ShellCommandRunner.kt index 554ac0d..974c2a4 100644 --- a/src/commonMain/kotlin/app/revanced/library/installation/command/ShellCommandRunner.kt +++ b/src/commonMain/kotlin/app/revanced/library/installation/command/ShellCommandRunner.kt @@ -55,5 +55,5 @@ abstract class ShellCommandRunner internal constructor() { */ internal operator fun invoke( command: String, - ) = runCommand("su -c \'$command\'") + ) = runCommand(command) } diff --git a/src/commonMain/kotlin/app/revanced/library/installation/installer/RootInstaller.kt b/src/commonMain/kotlin/app/revanced/library/installation/installer/RootInstaller.kt index 2a3514a..b53d9cc 100644 --- a/src/commonMain/kotlin/app/revanced/library/installation/installer/RootInstaller.kt +++ b/src/commonMain/kotlin/app/revanced/library/installation/installer/RootInstaller.kt @@ -100,7 +100,7 @@ abstract class RootInstaller internal constructor( /** * Runs a command on the device. */ - protected operator fun String.invoke() = shellCommandRunner(this) + protected operator fun String.invoke() = shellCommandRunner("su -c \'$this\'") /** * Moves the given file to the given [targetFilePath].