[app decompilation and reverse packaging]

One: decompile

1: Decompile the code

JADX (recommended)

For specific installation and use, it is recommended to read this article. Click here

dex2jar and jd-gui

Key commands:

d2j-dex2jar classes.dex

ps: Put the obtained classes.dex into the [dex2jar-2.0] folder of the previously decompressed tool, and execute this command. After getting the classes-dex2jar.jar file, use the [jd-gui] tool to decompile the class file into java source code.

2: Anti-compiling resource files

First visit the ApkTool official documentation and install the apktool tool:
Note that the documentation is in English, and the screenshot below is translated:
insert image description here

ps: The window system can be configured according to the first method. In the first step, we download the script language, create a new txt text, copy the script into it, and save the text as apktool.bat file. The second step is to download the latest apktool jar package. The third step is to put these two files in the Windowsw directory of the C drive or configure them in the environment variables.
The purpose of this configuration is: we can use the apktool command directly.

After everything is in place, the key command:

apktool d 考勤_1.1.5.apk

If you don't do the above apktool configuration, this command also works:

java -jar apktool_2.5.0.jar d -f E:\Android反编译工具包\测试apk\考勤_1.1.5.apk -o MMTS

Among them, d means decode, which means we want to decode the attendance_1.1.5.apk file. In addition to this basic usage, we can also add some additional parameters to control more behaviors of decode:

  • -f If the target folder already exists, force delete the existing folder (by default, if the target folder already exists, the decoding fails).
  • -o specifies the name of the decoding target folder (by default, the name of the APK file is used to name the target folder).
  • -s Do not decompile the dex file, that is to say, the classes.dex file will be preserved (by default, the dex file will be decoded into a smali file).
  • -r does not decompile resource files, that is to say, the resources.arsc file will be preserved (by default, resources.arsc will be decoded into a specific resource file).

Two: reverse packaging

At this point we can already decompile resource files and java code. After we have modified the resource file and the corresponding code logic, let's re-code and sign the apk.
There may be friends here who want to ask, how to modify the code logic. If you are proficient in smali grammar, congratulations, you are awesome. It doesn't matter if you don't know anything.

What is worth mentioning here is the smali folder. If you enter this folder, you will find that its directory structure is almost the same as that of src in our source code. The main difference is that all java files have become smali file. The smali file is actually the real source code, but its syntax is completely different from java. It is somewhat similar to the syntax of assembly, which is the register language used by the Android virtual machine.

Here is an idea:
(1) We need to decompile the java code obtained, after viewing the code logic, it will be better to read the corresponding smali file.
(2) You can write a simple project by yourself, find the smail folder after decompiling , and compare the relationship between the actual java code and the smail code. For example, java defines a boolean variable like this:

private boolean isIn=true

And the smail code is this:
insert image description here

Key commands:

apktool b 考勤_1.1.5

If you don't do the above apktool configuration, this command also works:

java -jar apktool_2.5.0.jar b 

ps: Note that attendance_1.1.5 is the name of the decompiled folder at that time. Under the path of the current file, after executing this command successfully, there will be multiple dist folders under the attendance_1.1.5 folder, which contains Attendance_1.1.5.apk after repackaging
insert image description here

This apk also needs to be signed again before it can be used . If you have already obtained the signature file and signature key of this app, then congratulations, the apk after repackaging can completely replace the apk before decompilation. But generally this file is not available to us. Then we can only regenerate a signature file by ourselves, and then use this signature file to re-sign the app.

After entering the dist folder, put the signature file in this directory, and execute the key command:

jarsigner -verbose -keystore 密钥库名称 -signedjar 考勤_1.1.5_signed.apk  考勤_1.1.5.apk  别名

Description:
-verbose Output signature details
-keystore watson.keystore uses the absolute path of the key, which is the key generated in the first step
-signedjar Decompile_signed.apk Decompile.apk watson.keystore Official signature, the three parameters are the signature in turn The generated file Decompile_signed, the file Decompile.apk to be signed and the alias of the keystore

For example:
jarsigner -verbose -keystore watson.keystore -signedjar attendance_1.1.5_signed.apk attendance_1.1.5.apk fangke

ps: After entering this command and pressing Enter, you will be prompted to enter the secret key of the signature file. After entering the secret key correctly, the signature will be successful again, and the "attendance_1.1.5_signed.apk" file will be generated. Congratulations here, you have been completely successful.

When installing the signed apk, if the installation fails and the following error message appears:

Failure [INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2]

At this point, check whether there is the following configuration under the application tag in the source code list file: android:extractNativeLibs="false" If there is, delete it and sign it again to package it!

Three: APKDB (automated)

You can search for apkdb keywords, or you can visit this website: Click here to download this tool.
This tool realizes fool-proof decompilation and reverse packaging. However, I found that the latest update was also 18 years old, which is relatively old. Interested friends can also find out.
Attach a screenshot here:
insert image description here

Reference article:

Apktool tool official documentation

APK decompilation

Decompilation and repackaging of Android APKs

Android APK decompilation tool JADX

Another apktool tool download link

Guess you like

Origin blog.csdn.net/da_caoyuan/article/details/118298198