From 76e6138d77c910712e23d7c6189c262ffa32cb82 Mon Sep 17 00:00:00 2001 From: Nex Date: Thu, 5 Aug 2021 08:49:34 +0200 Subject: [PATCH] Catching check if root exception more grafully (closes: #5) --- mvt/android/modules/adb/base.py | 6 ++++-- mvt/common/module.py | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mvt/android/modules/adb/base.py b/mvt/android/modules/adb/base.py index 622d509..74c13dc 100644 --- a/mvt/android/modules/adb/base.py +++ b/mvt/android/modules/adb/base.py @@ -17,7 +17,7 @@ from adb_shell.auth.sign_pythonrsa import PythonRSASigner from adb_shell.exceptions import AdbCommandFailureException, DeviceAuthError from usb1 import USBErrorAccess, USBErrorBusy -from mvt.common.module import MVTModule +from mvt.common.module import MVTModule, InsufficientPrivileges log = logging.getLogger(__name__) @@ -105,7 +105,7 @@ class AndroidExtraction(MVTModule): """Check if we have a `su` binary, otherwise raise an Exception. """ if not self._adb_check_if_root(): - raise Exception("The Android device does not seem to have a `su` binary. Cannot run this module.") + raise InsufficientPrivileges("The Android device does not seem to have a `su` binary. Cannot run this module.") def _adb_command_as_root(self, command): """Execute an adb shell command. @@ -120,6 +120,8 @@ class AndroidExtraction(MVTModule): :returns: Boolean indicating whether the file exists or not """ + # TODO: Need to support checking files without root privileges as well. + # Connect to the device over adb. self._adb_connect() # Check if we have root, if not raise an Exception. diff --git a/mvt/common/module.py b/mvt/common/module.py index 1989bcb..4a37850 100644 --- a/mvt/common/module.py +++ b/mvt/common/module.py @@ -21,6 +21,9 @@ class DatabaseNotFoundError(Exception): class DatabaseCorruptedError(Exception): pass +class InsufficientPrivileges(Exception): + pass + class MVTModule(object): """This class provides a base for all extraction modules.""" @@ -150,6 +153,8 @@ def run_module(module): except NotImplementedError: module.log.exception("The run() procedure of module %s was not implemented yet!", module.__class__.__name__) + except InsufficientPrivileges as e: + module.log.info("Insufficient privileges for module %s: %s", module.__class.__name__, e) except DatabaseNotFoundError as e: module.log.info("There might be no data to extract by module %s: %s", module.__class__.__name__, e)