Pages

Thursday, July 24, 2014

Decompiling and Recompiling Android apps using apktool


Decompiling Android app:

1) Download latest version of apktool from Author's website site. Unzip this file at some location on your machine.  Rename it to apktool.jar file.

2) Download the installer files from code.google site and copy into the same folder. For Windows, it has aapt.exe and apktool.bat files.

3) Copy some.apk file into this folder.

4) Press shift and make right click (together) on this folder and click on 'Open command window here' .

For decompiling, type

> apktool.bat d some.apk

If it gets decompiled without any error. Even if it is failed, it creates a new folder within current working folder and stores the files there. This is how a success message should look like.

If it fails at all, try step-6 and run this command again.




Recompiling:

6) Install framework file on your machine. For this, you need to extract framework-res.apk file from your device or emulator wherever your want to install after recompiling (I am not sure about emulator though).

On my Nexus-5, framework-res.apk file is located at /system/framework/framework-res.apk location. (Run <sdkLocation>/tools/ddms.bat  and go to File Explorer option to extract this file)

On the command window, type

> apktool.bat if framework-ref.apk

to install framework.

7) Now you can modify any decompiled file. But for testing, don't modify anything for now. We will just recompile the decompiled folder and see if it works or not.


Type

> apktool.bat b some [newFileName.apk]

APK file name is optional but you have to provide source folder name. It creates a new apk file inside 'some/dist' folder.

Possible output would be like.





8) Now we have broken signature of the original app, we need to make it correct. Online forums say that copying 'resources.arsc' file AND any other modified file from new APK to original APK would fix this issues, but in my cases it did not.

To copy these files, first extract these files from new APK file. Use any unzip utility like 7-Zip to get these files. Now using 7-Zip, in my case, open the old APK file and drop 'resources.arsc' and other files into this opened file. Old files will be replaced.

Ideally, this app should be ready for installation now.


9) Just in case, if it does not get installed on the device, use Zipsigner . Create a signed APK with this app and install it. It should get installed now.



No comments:

Post a Comment