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
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
- Extract package using ML Manager: APK Extractor
- Copy package over to e.g. SMB network drive using File Commander Manager
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
adb -s 192.168.x.x:5555 install aligned.apk
Comments
Post a Comment