Skip to content

Commit

Permalink
Support for apktool d --only-main-classes (#660)
Browse files Browse the repository at this point in the history
* Support for apktool d --only-main-classes
Fixes #659

* Minor fixes, working now.
  • Loading branch information
AltayAkkus authored May 23, 2024
1 parent d983234 commit bf4d010
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions objection/commands/mobile_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def patch_android_apk(source: str, architecture: str, pause: bool, skip_cleanup:
enable_debug: bool = True, gadget_version: str = None, skip_resources: bool = False,
network_security_config: bool = False, target_class: str = None,
use_aapt2: bool = False, gadget_config: str = None, script_source: str = None,
ignore_nativelibs: bool = True, manifest: str = None, skip_signing: bool = False) -> None:
ignore_nativelibs: bool = True, manifest: str = None, skip_signing: bool = False, only_main_classes: bool = False) -> None:
"""
Patches an Android APK by extracting, patching SMALI, repackaging
and signing a new APK.
Expand Down Expand Up @@ -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)
patcher = AndroidPatcher(skip_cleanup=skip_cleanup, skip_resources=skip_resources, manifest=manifest, only_main_classes=only_main_classes)

# ensure that we have all of the commandline requirements
if not patcher.are_requirements_met():
Expand Down
3 changes: 2 additions & 1 deletion objection/console/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,10 @@ def patchipa(source: str, gadget_version: str, codesign_signature: str, provisio
@click.option('--ignore-nativelibs', '-n', is_flag=True, default=False,
help='Do not change the extractNativeLibs flag in the AndroidManifest.xml.', show_default=False)
@click.option('--manifest', '-m', help='A decoded AndroidManifest.xml file to read.', default=None)
@click.option('--only-main-classes', help="Only patch classes that are in the main dex file.", is_flag=True, default=False)
def patchapk(source: str, architecture: str, gadget_version: str, pause: bool, skip_cleanup: bool,
enable_debug: bool, skip_resources: bool, network_security_config: bool, target_class: str,
use_aapt2: bool, gadget_config: str, script_source: str, ignore_nativelibs: bool, manifest: str, skip_signing: bool) -> None:
use_aapt2: bool, gadget_config: str, script_source: str, ignore_nativelibs: bool, manifest: str, skip_signing: bool, only_main_classes:bool = False) -> None:
"""
Patch an APK with the frida-gadget.so.
"""
Expand Down
6 changes: 4 additions & 2 deletions objection/utils/patchers/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class AndroidPatcher(BasePlatformPatcher):
}
}

def __init__(self, skip_cleanup: bool = False, skip_resources: bool = False, manifest: str = None):
def __init__(self, skip_cleanup: bool = False, skip_resources: bool = False, manifest: str = None, only_main_classes: bool = False):
super(AndroidPatcher, self).__init__()

self.apk_source = None
Expand All @@ -214,6 +214,7 @@ def __init__(self, skip_cleanup: bool = False, skip_resources: bool = False, man
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',
'network_security_config.xml')
self.only_main_classes = only_main_classes

def is_apktool_ready(self) -> bool:
"""
Expand Down Expand Up @@ -404,6 +405,7 @@ def unpack_apk(self):
'decode',
'-f',
'-r' if self.skip_resources else '',
'--only-main-classes' if self.only_main_classes else '',
'-o',
self.apk_temp_directory,
self.apk_source
Expand All @@ -412,7 +414,7 @@ def unpack_apk(self):
if len(o.err) > 0:
click.secho('An error may have occurred while extracting the APK.', fg='red')
click.secho(o.err, fg='red')

def inject_internet_permission(self):
"""
Checks the status of the source APK to see if it
Expand Down

0 comments on commit bf4d010

Please sign in to comment.