I've been studying the development of Android applications for some time, and I'm thinking that since it's developed in Java, I should decompile it to get the source code. Google did it, and it was really simple. The following is my practice process.
I solemnly declare that the purpose of posting is not to crack other people's software, but a learning attitude, but it seems that some foreign software can also be localized in this way.
Note: This Android decompilation tutorial has passed the Windows7-Ultimate-64bit operating system test!
Download the required decompilation toolkit as shown below.
First, decompile Apk to get Java source code.
First download two tools: dex2jar and JD-GUI.
The former is to convert classes.dex in apk into Jar files, while JD-GUI is a decompilation tool, which can directly view the source code of Jar packages. The following is the download address:
dex2jar:
JD-GUI:
Specific steps:
First, the apk file is changed to zip, and the classes.dex is extracted, compiled by java file and packaged by dx tool.
Unzip the downloaded dex2jar and copy classes.dex to the directory where dex2jar.bat is located. Navigate to the directory where dex2jar.bat is located on the command line (CD directory under DOS command).
run quickly
Dex2jar.bat class
produce
class . dex . dex 2 jar . jar
The screenshot of the generated jar file is as follows:
Run JD-GUI (jd-gui.exe), open the jar package generated above, and you can see the source code.
HelloAndroid source code (apk source code comparison before compilation) is as follows:
Second, decompile the source code, pictures, XML configuration, language resources and other files of apk generator.
This will be especially useful if it is a Chinese software. First, download the tool, this time using apktool.
Download address:
Download: apktool1.4.1.tar.bz2 and apktool-install-Windows-R04-Bruce1.tar.bz2 (both packages are downloaded).
Specific steps:
Decompress the downloaded two packages into the same folder, and there should be three files: aapt.exe, apktool.bat, apktool.jar
Navigate to the apktool.bat folder on the command line and enter the following command: apktool d C:\*. Apk C:\* folder, as shown in the following figure:
Command line explanation: apktool d [apk file] [output folder]
The decompiled file is as follows (take AndroidManifest.xml as an example):
Special note: the file you want to decompile must be placed in the root directory of drive C (in fact, it is not necessary to put it in the root directory of drive C).
For example, in the directory D of disk D: \apktool 1.4. 1.
CD/D D: \ apktool1.4.1/Switch to the directory of disk D, which contains three files: HelloAndroid.apk and aapt.exe, apktool.bat and apktool.jar
Apktool。 Bat d-f, hello, Andrew. Apkhhello Android//apktool decompilation command, pay attention to d and.
How to write -f
It is very simple to repackage the decompiled file into apk. Just go to the apktool b c:\*** folder (the folder you compiled). The command is as follows: this idea is where your file is.
The files packaged by apk are in the directory C:\HelloAndroid, and two folders are generated:
build
distance
The packaged HelloAndroid.apk is in the dist folder above, Ok.
Finally, a newly released decompilation tool Androidfby is introduced, which is a graphical interface tool that encapsulates the above steps. Download address.
However, it is impossible to decompile the partially signed apk, but this blog method can still decompile successfully! for reference only
In addition, as an application developer, you certainly don't want your code to be decompiled. The next blog will talk about how to avoid being decompiled by others by confusing the code.
How Android prevents apk programs from being decompiled
As an Android application developer, I have to face an embarrassing situation, that is, the application I worked so hard to develop is easily decompiled by others.
Google seems to have found this problem. Starting from SDK2.3, we can see android-sdk-windows\tools\
Proguard is a tool to confuse java code. Through proguard, even if others decompile your apk package, they will only see some incomprehensible code, thus protecting the code.
Let's talk about how to make proguard.cfg file work under SDK2.3. Let's take a look at the contents of Android-SDK-Windows \ tools \ lib \ proguard.cfg:
[html] view
plaincopyprint?
1.- Optimization passed 5 times.
2.-dontusemixedcaseclassnames
3.-dontskipnoppubliclibraryclasses
4.- Don't pre-validate
5.- verbose
6.- optimize! Code/Simplification/Arithmetic! field/*,! Category/Merge/*
7.
8.- Keep public classes * Extend android.app.Activity
9.- Keep public classes * Extend android.app.Application
10.- Keep public classes * Extend android.app.Service
1 1.- keep the public class * extend android.content.broadcastreceiver.
12.- Keep public classes * Extend android.content.contentprovider.
13.-keep public class * extend android.app.backup.backupagenthelper.
14.- Keep public classes * Extend android.preference.Preference
15.- Keep the public class com.android.vending.licensing.ilicensingservice.
16.
17.-keep classes with membernames class * {
18. Primary;
19.}
20.
2 1.-keep classes with membernames class * {
22.public (android.content.Context,Android . util . attributeset);
23.}
24.
25.-keep classes with membernames class * {
26.public (android.content.Context,android.util.AttributeSet,int);
27.}
28.
29.-keepclassmembers enumeration * {
30. Public static * * [] values ();
3 1.public static * * value of(Java . lang . string);
32.}
33.
34.-keep class * Implement android.os.Parcelable {
35.public static final Android . OS . parcelable $ Creator *;
36.}
As you can see from the script, confusion preserves the differences between activities, services,
Basic components such as applications, broadcast receivers, and content providers.
com . Android . vending . licensing . ilicensingservice,
And keep all the native variable names and class names. Some classes are constructors with fixed parameter formats and enumerations. (See examples and notes in /examples for details. )
The way to make proguard.cfg work is simple, that is, add a sentence "proguard.config=proguard.cfg" to the default.properties file generated automatically by eclipse.
The complete default.properties file should look like this:
[html] view
plaincopyprint?
1.# This file is automatically generated by the Android tool.
2.# Do not modify this file-your changes will be deleted!
3.#
4.# This file must be checked in the version control system.
5.#
6.# To customize the properties used by the Ant build system,
7.# "build.properties ",and override the value to make the script fit your.
8.# Project structure.
9.
10.# Project objective.
1 1.target=android-9
12.proguard.config=proguard.cfg
You're finished. After normal compilation and signing, the code can be prevented from being decompiled. The code decompiled by apk with chaotic code should be similar to the following effect, which is difficult to understand:
It doesn't matter if you use the SDK version before 2.3, just copy the proguard.cfg file above and put it into the project, and then do the same operation.
/