Today idle boring, gather up a word to write an article. Before for the purpose of learning (mainly for fun, can change the background, change the layout of what) decompilated several Apk, feel quite fun, but has not been on the Apk code are too bad, today on some day headlines decompilation and secondary packaging, mainly introduced tools and processes.
tool
There are many great GUI tools available on Windows, but not so lucky on MAC. Here are some of the tools used in this article:
1. apktool
This tool is a must for decompilation and packaging and is installed via Homebrew
2. dex2jar
Complete the dex to JAR package transformation, convenient to locate the code to be modified, through Homebrew installation
3. Jd – GUI
This is a MAC GUI tool, you can open the JAR package to view the source code, download the address JD-gui
The target
In fact, today’s goal is very simple, mainly to experience the process, the setting interface in the headlines of a day is as follows, click the feedback in the upper right corner to enter the feedback interface, the purpose of today is to modify the code to make it invalid.
Headline Settings screen
steps
Of course you need to download it before you can modify it
2. Find the path where the code resides
To find the corresponding code, of course, you need to find the corresponding interface. Here you use adb tools, dumpsys can check the system service information and status.
After connecting the mobile phone with USB, open the application of a certain day toutiao and switch to the system setting interface.
Open iTerm on a MAC and type adb shell dumpsys activity activities
View the task stack for a day’s headlines
Can see the interface name is BaseSettingActivity, name is specification, also can see its path is com. Ss. Android. Article. Base. Feature. Mime
3. Locate the code location
To find the interface, we need to locate the specific location of the code. If we decomcompile directly, we will see the smALI format code, which is difficult to locate. View the Java code using the JD-GUI tool, and then locate the code in SMALI.
Rename the APK package toutiao.apk to toutiao.zip. Save a copy of the APK package for later use. Decompression is as follows:
You can see that there are three dex files, and you can see that the amount of code in the headlines is quite large. Use the dex2jar tool to convert the dex file into a jar file, run the d2j-dex2jar classes.dex command to generate the classes-dex2jar. Use the JD-gui tool to open the file:
The headline code gets confused, but thankfully we found the path to the BaseSettingActivity interface.
In the decomcompiled code, we searched for “feedback” and found the above code. Despite the confusion, we can easily guess that this is where the feedback text and click event Settings are located. Method after the confusion is
4. Modify the smali
Use the apktool to decompile toutiao.apk, so make sure you save a copy of the apk file before changing it to a zip file.
The decompressed directory is similar to that of the decompressed zip package:
Use the text tool to open the smali directory, I use sublime, find the p_() method, and search for the location of the click event:
You can see the smali version of the three lines of Java code in the screenshot above. Remove the 426 lines and wait for the package to test the results.
5. Sign and pack
Of course, we do not know the signature of Toutiao, here you can use your own signature to sign it, but you need to uninstall the original installed one day toutiao legitimate version, before you can successfully install the modified pirated version.
The installation command is as follows:
First push apk package to mobile: adb push toutiao. The apk/data/local/TMP/com. Toutiao. Toutiao
To install the apk: adb shell PM install -r “/ data/local/TMP/com. Toutiao. Toutiao”
At this point the installation is complete, and tests have found that the feedback button has failed as expected.
conclusion
1. Tools matter.
2. Be patient, the function of this decompilation is very simple, if you want to achieve a slightly more complex function, you need to be very patient.