apk decompilation, smali file modification, repackaging, practical application of java to samli plug-in in the project

1. Tool introduction:

1. apktool: aapt.exe, apktool.bat, apktool.jar; the three are used together in the same directory to decompile apk and repackage apk;

2.dex2jar: The function of this tool is to decompile the classes.dex file to the source code (if the apk is not reinforced), decompile the file, and use the jd-gui tool to view it;

3. Auto-Sign: An automatic signature tool that will sign the repackaged apk. If it is not signed, it cannot be installed and used.

Tool download address: http://download.csdn.net/detail/wxk105/9782180

Usage scenario: The project source code is lost, there is only an online apk, and there is no reinforcement. It is required to modify the apk interface address, repackage it, and then publish it.

2. Tool usage:

The toolkit after decompression is as shown below:

Write picture description here

1. Idea: Use the tool dex2jar to decompile, and use the jd-gui tool to view the project structure, view the source code, find the interface address class, and modify the interface address;

Step 1: Download the tool, change the suffix name of the APK that needs to be decompiled to .rar or .zip, and unzip it, as shown in the figure:

Write picture description here

Get the classes.dex file (it is compiled from a java file and then packaged with the dx tool), and get the

Copy classes.dex to the unzipped tool dex2jar-0.0.9.15 folder,

From the command line, go to the directory where dex2jar.bat is located and enter the command:

dex2jar.bat classes.dex

The effect is as follows:

Write picture description here

Step 2: After the operation is completed, a classes_dex2jar.jar file will be generated in this directory, as shown in the figure:

Write picture description here

Then open jd-gui.exe in the tool jd-gui folder, use this tool to open the generated classes_dex2jar.jar file, and you can see the source code

, the effect is as follows:

Write picture description here

2. Idea: apktool, decompile and modify the smali file, repackage it, and use the jd-gui tool to find the interface address class, and then use it with the corresponding

Compare the smali files and modify the interface address;

Download apktool among the above tools and unzip it to get 3 files: aapt.exe, apktool.bat, apktool.jar, which need to be decompiled

The APK file is placed in this directory, as shown in the figure:

Write picture description here

Open the command line interface (Run-CMD), navigate to the apktool folder, and enter the following command:

apktool.bat d -f test.apk -o test
apktool -f [apk to be decompiled] -o [folder to store after decompilation]

As shown in the picture:

Write picture description here

After decompilation, you will get the test folder. Open the test folder, which contains various decompiled resource files.

Write picture description here

Use jd-gui to view the source code to find the address class, then find the smali file of the address in the smali file, and change the interface address in the smali file.
As shown in the picture:

Write picture description here

Find the corresponding address smali file in the smali file

Write picture description here

Write picture description here

Modify the address in the interface smali file and replace the IP with the domain name as shown:

Write picture description here

After modification, save.

3. Repackage. Execute packaging command

apktool.bat b test

There will be two more files in the test file as shown below:

Write picture description here

The dist file contains the apk we need.

4. Signed apk, republished.

Next, we need to use the signing tool. If it is not signed, it will not run correctly. Tool: auto-sign.zip

Copy the packaged test.apk to the decompressed auto-sign folder, and rename it to test.zip. Execute the command:

java -jar signapk.jar testkey.x509.pem testkey.pk8 test.zip test_signed.zip

Next, enter test_signed.zip and change it to a file with the suffix apk, and that’s it:

Write picture description here

5. After running, it is found that running on 5.0 will directly crash. Android Studio captures the error:

Write picture description here

Here is the source code location viewed on jd-gui

wrong reason:

 Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent {<!-- --> act=com.sun3d.culturejingan.communication.link }

As shown in the error message, after Android 5.0, service intent must be explicitly pointed out.

Then you need to modify the smali file related classes. Here we use the java2smali file

6.java2smali plug-in, address: https://plugins.jetbrains.com/plugin/7385-java2smali

For plug-in installation, choose local installation. If you don’t know how to install the plug-in, please download it from Baidu.

Find the smali file code location of the corresponding problem:

Write picture description here

Since we don’t know much about writing smali syntax, we directly convert the written java code into smali syntax using a plug-in, copy it in, and replace the original smali code.
This is the java code
Write picture description here

Convert to smali code

Write picture description here

The corresponding code will be displayed directly to find the corresponding conversion result:

Write picture description here

Replace the corresponding code in the decompiled corresponding smali file, then execute the repackaging command, the signing command, and perform step 3.

The whole process is not complicated, and as long as you have patience, you can make the change successfully.

Reprint: https://blog.csdn.net/wxk105/article/details/62231068