APKTool Cheatsheet

Quick references I learnt throughout my journey using apktool in CTF


๐Ÿ“ฆ Install APKTool

sudo apt install apktool

Or.. just download the latest JAR + wrapper script from the official site.


๐Ÿ”ง Decode / Decompile APK

Full decode

apktool d app.apk

Creates a folder app/ with smali, resources, manifest.

I use this one the most and use find + grep to get hardcoded flag lol

Decode with original resources

apktool d app.apk -r

Skips decoding resources like XML โ†’ keeps them in binary form.

Specify output directory

apktool d app.apk -o output_folder

๐Ÿ›  Rebuild / Recompile APK

apktool b app_folder

Outputs to: app_folder/dist/app_folder.apk

Rebuild with custom output

apktool b app_folder -o newapp.apk

Do this after patching apk file, dont forget to sign! (sign instruction below)


๐Ÿ”‘ Signing the Rebuilt APK (Required!)

Android requires signing before installation.

Generate keystore (first time only)

keytool -genkey -v -keystore mykey.keystore -alias myalias -keyalg RSA -keysize 2048 -validity 10000

Sign APK

jarsigner -keystore mykey.keystore newapp.apk myalias

Verify signature

jarsigner -verify newapp.apk
apksigner sign --ks mykey.keystore --out signed.apk newapp.apk

๐Ÿ” Common Edits

1. Modify resources (res/)

Change layouts, strings, images, etc.

2. Edit AndroidManifest.xml

Example: allow debug

android:debuggable="true"

3. Edit smali code

Smali is inside smali/ folder.
Example smali search:

grep -R "key" -n smali/

Challenge creators looooveeeeeeeeees hiding flags in smali and res. So go check there first!


๐Ÿงน Clean Build Directory

If a build cache causes errors i usually just delete everything:

rm -rf app_folder/build

๐Ÿงช Useful Tools (Optional)

Zipalign example

zipalign -v 4 signed.apk aligned.apk

โœ” Quick Reference

Action Command
Decode apktool d app.apk
Decode (raw resources) apktool d app.apk -r
Build apktool b folder
Install framework apktool if framework.apk
Sign APK apksigner sign --ks key.keystore
Zipalign zipalign -v 4 in.apk out.apk

Feel free to contact me if I made a mistake here and there hehe