Thursday, 29 December 2011

Decompiling and displaying the source of an Android APK

This is a Windows-centric post, but it should be fairly straight-forward to make this work in Linux/MacOS by porting the script file and downloading the platform-correct version of JD-GUI.

Why do it
  1. You are curious to see how an application does what it does by reading its code.
  2.  You want to make sure that your application is properly obfuscated before making it public (i.e. you don't want people doing #1 and/or ProGuard is giving you grief).
You will need
What to do
  • Create a directory and name it something appropriate (for example apk-decompile).
  • Download and extract dex2jar and JD-GUI in the directory you created.
  • Make sure you rename the folders to match the file structure below:
  • Create a new text file in the root directory (apk-decompile in our example) and name it "go.bat".
  • Open it in notepad and paste the following:
echo off

REM Make sure we are working off the local directory.
set _=%~dp0
chdir /d "%_%"
echo Working directory is: "%_%"

IF "%~1"=="" GOTO BAD_SYNTAX

echo Converting dex to jar:
call dex2jar\dex2jar %1
echo.

echo Opening Class Viewer:
start "" jd-gui\jd-gui.exe %1.dex2jar.jar
echo.

echo DONT CLOSE THIS DIALOGUE UNTIL YOU'VE FINSHED CHECKING THE FILE AS IT WILL AUTOMATICALLY BE DELETED.
pause

del %1.dex2jar.jar

exit 0

:BAD_SYNTAX
echo Error! Incorrect syntax.
echo The correct syntax is:
echo  %0 ^<path_to_apk^>;
pause
exit 1

How to use this
  • You can either use the command line and type the following: go.bat <path_to_apk>
  • You can drag and drop an apk file onto go.bat.
Notes
 I'm certain that there are other, probably more efficient ways to do this but this suits my purposes (for now).

1 comment:

  1. Did you hear there's a 12 word phrase you can tell your crush... that will induce deep emotions of love and impulsive attraction for you buried within his heart?

    Because hidden in these 12 words is a "secret signal" that fuels a man's impulse to love, idolize and care for you with all his heart...

    ====> 12 Words That Trigger A Man's Desire Response

    This impulse is so built-in to a man's mind that it will drive him to try better than before to take care of you.

    Matter-of-fact, fueling this powerful impulse is absolutely essential to achieving the best possible relationship with your man that the moment you send your man a "Secret Signal"...

    ...You will immediately find him open his mind and soul to you in such a way he never experienced before and he'll distinguish you as the one and only woman in the world who has ever truly appealed to him.

    ReplyDelete