APK Tool Guide


APKTool – Guide and Functions

APKTool is a powerful reverse-engineering tool for Android apps. Here are the key methods:


1. Decompiling an APK

Use the following command to extract an APK:

apktool d app.apk -o output_folder

2. Modifying Resources

Strings and other values can be edited in the res/values/strings.xml file.

nano res/values/strings.xml

3. Editing the Manifest File

The AndroidManifest.xml can be modified:

nano AndroidManifest.xml

4. Removing Security Checks

Search for root detection and debugging checks:

grep -ir "root" smali/

5. Replacing a String with sed

To replace a hardcoded string in the Smali code, use the following command:

sed -i 's/old_string/new_string/g' smali/com/example/app/MainActivity.smali

6. Rebuilding the Modified APK

After making changes, the APK can be rebuilt:

apktool b output_folder -o modified.apk

7. Generating a Keystore

Before signing an APK, a keystore must be generated:

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

8. Signing the APK

The APK must be signed after modifications:

apksigner sign --ks my-release-key.keystore --out signed_app.apk modified.apk

9. Alternative Signing with Jarsigner

If needed, the APK can also be signed using Jarsigner:

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore modified.apk my-key-alias

10. Automated Script

A Bash script for automation:

#!/bin/bash 
apktool d $1 -o extracted nano extracted/smali/com/example/app/MainActivity.smali apktool b extracted -o modified.apk apksigner sign --ks my-release-key.keystore --out final_app.apk modified.apk