Android confuses packaging and decompilation under mac osx

   The android code has always had a security problem. The obfuscation and packaging of proguard after android2.2 can solve this problem more conveniently, so let's talk about the way of obfuscation and packaging first.

system environment

mac os x 10.9.4

android sdk version   

android4.2.2


1. Confused packaging

1. Confuse the concept of packaging

The Java code is compiled into a binary class file, and this class file can be decompiled into source code. The proguard obfuscation tool is to change the names of java elements such as methods, fields, packages, and classes into meaningless names, so that the code structure does not change. It works, but it's hard to understand the structure of the code. It also has two other functions, delete invalid code (Shrinking contraction), and code optimization (Optimization Options).

You can see the proguard-project.txt document in the android project, which can be configured for confusion.

2. Confused packaging steps

(1) Modify the project.properties file in the project and add it in a new line

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

The old version can be changed to add proguard.config=proguard.cfg

 (2) Export the apk according to the normal process

Two, decompile

1. Tool download

(1) Download the latest version of apktool1.5.2.tar.bz2 and apktool-install-macosx-r05-ibot.tar.bz2 from apktool. The main purpose of apktool is to obtain AndroidManifest.xml and res, but directly change the suffix name of the jar package It is also available for zip decompression.

(2) dex2jar decompiles the dex file into a jar package to obtain the class code bytecode.

(3) jd-gui is a visual tool that can decompile bytecode and view source code.

2. Steps

(1) Open the mac command line and enter the command

echo $PATH

This address is similar to the path path in the Windows system variable, check whether there is /usr/local/bin, if not, create one, and then decompress the two tar.bz2 downloaded by apktool, you can see that there are 3 files inside apktool. jar, aapt, apktool, all copied to the /usr/local/bin path, need to use sudo, at this time you can use them without filling in the path;

(2) Start to decompile apk below

a. Command line cd to the directory of the desired decompiled apk file,

b. Call command

apktool d xxx.apk

Among them, xxx.apk is the name of your apk file. At this time, you will get the folder xxx, which contains the required AndroidManifest.xml and res;

c. Change the apk suffix name to zip and unzip it

d. Enter the decompression folder, you can see the class.dex file, enter the command line

sh The path of dex2jar-0.0.9.15 you downloaded/dex2jar.sh classes.dex

At this time, you can see that the directory where class.dex is located generates a new file classes_dex2jar.jar file, which is the code bytecode jar package we need;

e. Open jd-gui, use it to open classes_dex2jar.jar and you can see the corresponding source code.

3. The effect of confusing packaging and conventional packaging decompilation

After regular packaging and decompilation, you can see the source code with comments deleted. The parameters of the findViewById function are replaced by values, but it is relatively easy to read; after confusing packaging, most of the class names and package names become special characters such as a, b, c, etc. Difficult to interpret. Therefore, it is good to improve the security of confusing packaging.


Guess you like

Origin blog.csdn.net/rsp19801226/article/details/44803545