Skip to content

Instantly share code, notes, and snippets.

@rigwild
Last active March 7, 2025 23:21
Show Gist options
  • Save rigwild/02729a128b878186ffe8b1982d31b4f4 to your computer and use it in GitHub Desktop.
Save rigwild/02729a128b878186ffe8b1982d31b4f4 to your computer and use it in GitHub Desktop.
Full tutorial to patch APKs on Android using apk-mitm and APKLab. Support for bundle APKs.

Patch APK

Full tutorial to patch APKs on Android using apk-mitm and APKLab. Support for bundle APKs.

Pull APK

adb shell pm list packages
adb shell pm path <package_name>

If the app contains a single APK:

adb pull /data/app/~~SzA2evEyrPV2ucUpwPzYYQ==/some_path==/base.apk base.apk

If it's a bundle APK (multiple APK files):

  • Install Split APKs Installer (SAI)
  • Backup the app to a .apks file
  • Load the file to your computer
  • Extract the .apks file (it's an archive!)
  • Create a copy of the .apks file, we will need it later when rebuilding the app

Patch APK

Open base.apk with APKLab with options:

  • Only main classes
  • Decompile Java

Inspect the Java code in the java_src directory, find the function you want to edit.

When found, go to its .smali file equivalent in the smali directory, do your edit and save.

Right-click on the apktool.yml file: APKLab: Rebuild the APK.

The APK file is generated at dist/base.apk.

If you are working on a single APK, you can install it to your phone:

adb install dist/base.apk

Build bundle APK

  • Open your copy of the .apks file as an archive
  • Delete the base.apk file from the archive
  • Add your dist/base.apk patch APK file to the archive

Using apk-mitm

apk-mitm my_app-edited.apks

  ╭ apk-mitm v1.2.1
  ├ apktool v2.6.1
  ╰ uber-apk-signer v1.2.1

  Using temporary directory:
  /tmp/apk-mitm-ab640ef99e9eacd6b96f033651301328

  ✔ Extracting APKs
  ✔ Patching base APK
  ✔ Signing APKs
  ✔ Compressing APKs

   Done!  Patched file: ./my_app-edited-patched.apks

Quick SSL/HTTPS MITM patch

Use the --certificate parameter your proxy SSL certificate

apk-mitm --certificate charles_proxy_certificate.pem my_app-edited.apks

Install bundle APK

Enjoy! 💕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment