From 602e9426cfcedc555a2f99e8fcb9692e23ebf87f Mon Sep 17 00:00:00 2001 From: Mitch Capper Date: Fri, 4 Oct 2024 23:03:32 -0700 Subject: [PATCH] Expand use_aapt2 cli arg for which aapt version we use for badge dumping Fixes newer apk patching that aapt cannot handle --- objection/commands/mobile_packages.py | 2 +- objection/console/cli.py | 2 +- objection/utils/patchers/android.py | 14 +++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/objection/commands/mobile_packages.py b/objection/commands/mobile_packages.py index 59efd6d5..b7db8de1 100644 --- a/objection/commands/mobile_packages.py +++ b/objection/commands/mobile_packages.py @@ -176,7 +176,7 @@ def patch_android_apk(source: str, architecture: str, pause: bool, skip_cleanup: click.secho('Patcher will be using Gadget version: {0}'.format(github_version), fg='green') - patcher = AndroidPatcher(skip_cleanup=skip_cleanup, skip_resources=skip_resources, manifest=manifest, only_main_classes=only_main_classes) + patcher = AndroidPatcher(skip_cleanup=skip_cleanup, skip_resources=skip_resources, manifest=manifest, only_main_classes=only_main_classes, use_aapt2=use_aapt2) # ensure that we have all of the commandline requirements if not patcher.are_requirements_met(): diff --git a/objection/console/cli.py b/objection/console/cli.py index 14e6c701..eb5b0439 100644 --- a/objection/console/cli.py +++ b/objection/console/cli.py @@ -268,7 +268,7 @@ def patchipa(source: str, gadget_version: str, codesign_signature: str, provisio help='Skip signing the apk file.', show_default=False) @click.option('--target-class', '-t', help='The target class to patch.', default=None) @click.option('--use-aapt2', '-2', is_flag=True, default=False, - help='Use the aapt2 binary instead of aapt as part of the apktool processing.', show_default=False) + help='Use the aapt2 binary instead of aapt as part of the apktool processing and for badge dumping.', show_default=False) @click.option('--gadget-config', '-c', default=None, help=( 'The gadget configuration file to use. ' 'Refer to https://frida.re/docs/gadget/ for more information.'), show_default=False) diff --git a/objection/utils/patchers/android.py b/objection/utils/patchers/android.py index a843a9d3..b096741e 100644 --- a/objection/utils/patchers/android.py +++ b/objection/utils/patchers/android.py @@ -199,7 +199,9 @@ class AndroidPatcher(BasePlatformPatcher): } } - def __init__(self, skip_cleanup: bool = False, skip_resources: bool = False, manifest: str = None, only_main_classes: bool = False): + def __init__(self, skip_cleanup: bool = False, skip_resources: bool = False, manifest: str = None, only_main_classes: bool = False, use_aapt2: bool = False): + if use_aapt2: + self.required_commands['aapt2'] = {'installation': 'apt install aapt2 (Kali Linux)'} super(AndroidPatcher, self).__init__() self.apk_source = None @@ -210,6 +212,7 @@ def __init__(self, skip_cleanup: bool = False, skip_resources: bool = False, man self.skip_cleanup = skip_cleanup self.skip_resources = skip_resources self.manifest = manifest + self.use_aapt2 = use_aapt2 self.keystore = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../assets', 'objection.jks') self.netsec_config = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../assets', @@ -304,15 +307,16 @@ def _get_appt_output(self): """ if not self.aapt: - o = delegator.run(self.list2cmdline([ - self.required_commands['aapt']['location'], + cmd = self.list2cmdline([ + self.required_commands['aapt2' if self.use_aapt2 else 'aapt']['location'], 'dump', 'badging', self.apk_source - ]), timeout=self.command_run_timeout) + ]) + o = delegator.run(cmd, timeout=self.command_run_timeout) if len(o.err) > 0: - click.secho('An error may have occurred while running aapt.', fg='red') + click.secho(f'An error may have occurred while running aapt cmd: {cmd}.', fg='red') click.secho(o.err, fg='red') self.aapt = o.out