Patching an Android application

As a note to myself in the future, to modify Android .apk behaviour, these are the main steps:

Initial setup of tools

  • Install Android studio
  • brew install jadx
  • brew install smali
  • brew install Apktool

Setup tools in the path

export PATH=~/Library/Android/sdk/platform-tools:~/Library/Android/sdk/build-tools/30.*:$PATH

Generate a signing key

keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000


Either pull original package from device with developer mode enabled

adb connect 192.168.x.x

adb -s 192.168.x.x:5555 shell pm list packages | grep com.example

adb -s 192.168.x.x:5555 shell pm path com.example.app

adb -s 192.168.x.x:5555 pull /data/app/com.example.app/base.apk

Or if you'd rather not enable developer mode

Decompile package and figure out changes needed

jadx base.apk -d .

emacs &  # left as an exercise to future self, obviously specific to the application and your goals

Disassemble package and apply your your changes to smali sources

apktool d base.apk  

patch -d base -p1 <com.example.app-foobar.patch

 Rebuild package

apktool b base -o patched.apk

zipalign -p 4 patched.apk aligned.apk     

apksigner sign -ks my-release-key.keystore --ks-key-alias alias_name aligned.apk


Uninstall package on device and push it back
 
adb -s 192.168.x.x:5555 install aligned.apk

Comments

Popular posts from this blog

iMovie event library on a network drive, NAS

Proxmox PCIe passthrough on HP gen8 - failed to set iommu for container

Backup and restore observium