Showing posts with label Decompiler. Show all posts
Showing posts with label Decompiler. Show all posts

Monday, December 16, 2013

How to obfuscate an Android APK file using ProGuard in the Eclipse ADT

The classes in the Android APK can be obfuscated using the ProGuard tool in the Android Development Toolkit (ADT) in Eclipse. The following shows how to enable to source code obfuscation.
  1. In Eclipse, open up an Android project e.g. androidgames.
  2. Open up the file project.properties in the Eclipse text editor.


  3. Uncomment the following line by removing the # symbol in the first column.

    #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
  4. Optional. If there are any classes that you do not want to obfuscate, then the class must be added to the proguard-project.txt file, e.g. com.dom925.trains.manila.SvgInterface, as shown below.
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}
-keepclassmembers class com.dom925.trains.manila.SvgInterface {
public *;
}

An example of a decompiled obfuscated Android APK is shown below.

Monday, December 9, 2013

How to decompile an Android APK file

I was wondering how easy it is to decompile my Android APK files into source code files. So I did some searching using Google Search and found a few decompilers, some free and some commercial stuff. It seems that the process can be done in two steps: (1) convert the APK file to a JAR file, and (2) convert the JAR file to JAVA files.

The first step can be done using open source program dex2jar from https://code.google.com/p/dex2jar/downloads/list. The second part can be done using a Java decompiler from http://jd-gui.softpedia.com/. The Java decompiler will decompile the JAR file into the Java source code files. Using these two programs, it was very easy to reverse engineer the Android APK file as shown below:
  1. Open up a Command Prompt.
  2. Type in the d2j-dex2jar.bat command (assuming it is in the system path, otherwise you need to type in the whole command path) to convert an apk file e.g. androidgames.apk.

    C:\> d2j-dex2jar.bat androidgames.apk

    The apk file is converted to a jar file androidgames-dex2jar.jar.

    Note: the suffix "-dex2jar.jar" is appended to the file name.
  3. Now run the Java decompiler jd-gui.exe by double clicking the executable from the Windows Explorer.

    The Java Decompiler application appears.

  4. Click File | Open File. Browse and select the jar file created previously.


  5. Click Open.

    The classes and source code files are displayed in the application.