Dienstag, 28. August 2018

Decompiling an Android APK file

I recently needed to look into another Android app to see how they implemented some strange UI behaviour. There are a few steps neccessary to get the source code of an app.


  1. Download the APK from the device.
  2. Convert the APK file to a JAR
  3. Decompile the JAR

Download the APK from the device


This can be done using the Android SDK platform tools. Go to your SDK directory and find platform-tools/adb.

If you don't know where your application is installed on your device follow these instructions:

Type 

adb shell

This gives you a Linux shell on your device. Now type:

pm list packages -f

This will give you a list of all your installed applications and the paths where they are located in the filesystem.

Exit the shell and download the APK via:

adb pull <Path to the APK file on the device>

Now you can find the APK file in your current directory.

Convert the APK file to a JAR


Now we use the dex2jar tool to convert the Dalvik executable files into class files inside a JAR. Download the tool from the github repository and run

sh d2j-dex2jar.sh -f ~/path/to/apk_to_decompile.apk

This creates the JAR archive in the current directory.

Decompile the JAR


Now we can use the Java Decompiler to view the contents of the JAR archive. Just open the JAR archive in the Decompiler and browse the classes.


Montag, 4. Juni 2018

Create an icon for an Eclipse e4 RCP application (Windows).

Trying to give your new Eclipse e4 application a new Windows icon is more complex than one might think.

The solution I am presenting here works for my application that is build with Tycho 1.0.0. I don't know if you run into the same problems when doing an export from Eclipse as I have never tried that.

When I tried to change the icon I ran into two different problems:

  1. Creating an Windows ICO file that contains all images in the correct formats.
  2. Adding the icon to the product definition.

Creating the Window ICO file

The Windows ICO file has to contain 7 images in different resolutions and depths:
  • 48x48, 8 bits
  • 32x32, 8 bits
  • 16x16, 8 bits
  • 48x48, 32 bits
  • 32x32, 32 bits
  • 16x16, 32 bits
  • 256x256, 32 bits
You can find many tools to create an ICO file for you. But you always have to export all your files in the right format and add them to the ICO file. I tried that with several tools and never got it working right.

So I went to Linux and just used ImageMagick convert to convert all my images into the format Eclipse needs and than use icoutils to create the ICO file.

Using GIMP I created four versions of the image I wanted to use as my icon: 256x256, 48x48, 32x32 and 16x16.

Then I just ran these commands and got my ICO file.

convert -colors 256 myicon_16x16.png tmp.gif
convert -colors 256 tmp.gif icon_16x16_8.png
convert -colors 256 myicon_32x32.png tmp.gif
convert -colors 256 tmp.gif icon_32x32_8.png
convert -colors 256 myicon_48x48.png tmp.gif
convert -colors 256 tmp.gif icon_48x48_8.png
icotool -c icon_16x16_8.png myicon_16x16.png icon_32x32_8.png myicon_32x32.png icon_48x48_8.png myicon_48x48.png myicon_256x256.png > icon.ico

Adding the icon to the product information

In the product definition of your Eclipse e4 application you can select an ICO file that should be used for the generated executable. When I clicked browse and selected the icon file I had previously generated I got this:



The IconExe tool that is used for replacing the icons during the Tycho buiold was not able to find the ICO file. I had to change that to a local path for it to work.