How To Use Apk Tool to Decompile and Recompile Apk’s?
In here you will learn
how to decompile and recompile an apk file using the APKTool for cheating or modding apk’s.
APKTool is an application for reverse engineering Android apps. It can decode resources (decompile) and rebuild them (recompile) after making some modifications.
The tool can be used to analyze apps and even add features.
If you want to cheat Android games and mod apk’s by yourself you need to know how to edit apk, smaling and backsmaling. APKTool can help you do this.
What is Smaling / Baksmaling?
The names “smali” and “baksmali” are Icelandic words which mean “assembler” and “disassembler” respectively. In short, smaling is running an assembler and baksmaling is running a disassembler for the dex format used by dalvik. Dalvik is the Android’s JAVA VM implementation. Both are Icelandic words, as dalvik was named after an Icelandic fishing village.
You can reverse engineer Android applications or mod apks by using APKTool as it can extract an APK and generate class files of an apk in smali format.
Let’s start with the requirements.
Requirements:
Note: I am using Windows 8 as my operating system, so all screenshots and some command formats are in Windows. Still, APKTool supports Linux and Mac OSX. So if you are using either Mac or Linux, you can follow the procedures, except that some commands are for Windows.
Initial Setup
Download and install JDK/JRE.
Download and install Android SDK.
Download APKTool plus its dependencies/helper script.
Setting up ApkTool
1. Extract both files.
2. Create a folder (i.e. APKTool).
3. Copy the files: apktool.jar, aapt.exe and apktool.exe, then paste it inside the newly created folder.
4. Copy/paste your apk file inside the folder.
Installing the Framework
Now to continue, we need to install the device’s framework. This is important as it is needed for the apk to be compiled correctly. For this tutorial, I am using filename.apk as my apk file.
Open cmd (command prompt), and then change its directory to the folder. An easy way to do this is by opening the folder, then right click any file (e.g. apktool.bat). Select “Properties”, then copy the “Location”. Now go back to the cmd, then type in cd. Now, right click > select Paste to the cmd > hit Enter.
Type the command: apktool if filename.apk
filename.apk refers to the apk file. In your case, type in the filename of you apk, followed by .apk extension.
Doing this will install the devices framework in your system.
Decompiling the Apk File
You can now decompile the apk using the APKTool.
Type the command: apktool d filename.apk
If done correctly, the output looks something like this:
I: Baksmaling…
I: Loading resource table…
I: Loaded.
I: Decoding AndroidManifest.xml with resources…
I: Loading resource table from file: (with the location of the framework resource table)
I: Loaded.
I: Regular manifest package…
I: Decoding file-resources…
I: Decoding values */* XMLs…
I: Done.
I: Copying assets and libs…
After that, there should be a new directory with the name of the APK. The new folder includes all folders and files that are cointained in the apk file. This includes res folder, smali folder, AndroidManifest.xml and the apktool.yml.
From there you can make your edits. This is where modding apk’s come into place. You can analyze what’s inside the apk and create mods for it. These edits might include create hacks and cheats for the apk.
Recompiling the Apk File (Creating a Finished Product)
After you have done your edits, it is now time to compile your new apk.
1. Go back to cmd (command prompt), then navigate/change directory to the apktool folder.
2. Type the command: apktool b filename
filename is the folder with your edited files.
If done correctly, it should have an output like this:
I: Checking whether sources has changed…
I: Smaling…
I: Checking whether resources has changed…
I: Building resources…
I: Building apk file…
After that, it will generate a final modded apk which will be inside a folder named “dist”. The “dist” folder is located inside the original app folder.
Signing the Apk File
Now that we have our modded apk, it is still not complete yet. We have to add it back to the original apk file in order to keep its proper signature.
2. Extract the SignApk.zip. SignApk includes the files: certificate.pem, key.pk8 andsignapk.jar.
3. Copy the “modded apk” from the “dist” folder to the SignApk folder.
4. Open cmd then change directory to the SignApk directory.
5. Type in: java –jar signapk.jar certificate.pem key.pk8 filename.apk newfilename.apk
The filename.apk refers to the modded apk file and the newfilename.apk refers to the new final modified recompiled apk file. You can change the “newfilename” to any file name that you want.
Once compiled, the resulting signed apk will be generated on the same folder. This is theFINAL APK. Just rename it, and push it in your Android device.
You just learned how to decompile and recompile apk’s properly using the APKTool. If you encounter any problems kindly post it here