From 9317586851434973f1d5d4bb41b70b83cfe535ad Mon Sep 17 00:00:00 2001 From: Adam Lawson Date: Tue, 20 Jul 2021 12:52:14 +0100 Subject: [PATCH 1/2] Better check for if device has root "which su" will return the path of the su binary, or it will return nothing. The python boolean of a string with something in it (such as the path of the su binary), will be True. An empty string (where there is no su binary) will be False. --- mvt/android/modules/adb/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mvt/android/modules/adb/base.py b/mvt/android/modules/adb/base.py index 31aa931..3deacf7 100644 --- a/mvt/android/modules/adb/base.py +++ b/mvt/android/modules/adb/base.py @@ -96,7 +96,7 @@ class AndroidExtraction(MVTModule): """Check if we have a `su` binary on the Android device. :returns: Boolean indicating whether a `su` binary is present or not """ - return bool(self._adb_command("[ ! -f /sbin/su ] || echo 1")) + return bool(self._adb_command("which su")) def _adb_root_or_die(self): """Check if we have a `su` binary, otherwise raise an Exception. From ad3faa186bd54d7f487d3b262900213c9e72b2fa Mon Sep 17 00:00:00 2001 From: goshawk22 Date: Fri, 23 Jul 2021 15:35:56 +0100 Subject: [PATCH 2/2] Use command -v instead of which to check for root `command` is built in, unlike `which`, and is more reliable. https://github.com/mvt-project/mvt/pull/19#issuecomment-885650430 https://stackoverflow.com/questions/592620/how-can-i-check-if-a-program-exists-from-a-bash-script/677212#677212 --- mvt/android/modules/adb/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mvt/android/modules/adb/base.py b/mvt/android/modules/adb/base.py index 3deacf7..8b173f5 100644 --- a/mvt/android/modules/adb/base.py +++ b/mvt/android/modules/adb/base.py @@ -96,7 +96,7 @@ class AndroidExtraction(MVTModule): """Check if we have a `su` binary on the Android device. :returns: Boolean indicating whether a `su` binary is present or not """ - return bool(self._adb_command("which su")) + return bool(self._adb_command("command -v su")) def _adb_root_or_die(self): """Check if we have a `su` binary, otherwise raise an Exception.