The previous article introduced the process of decompilating and repackaging APK, which disables its feedback button. This article creates a new interface on this basis. Click feedback to enter a customized air conditioning control interface created by myself, which is of more reference significance in the code modification level. Here is just a demonstration effect, not to discuss the interface function, which is the custom air conditioning interface is guo Lin public number in an article about the actual combat of custom View: air conditioning remote control, the learning of custom View is very helpful, another amway about Guo Lin public number, every day there are dry goods.
Demo APK Download address ApK download address
tool
Decompilation and secondary packaging of headline APK are not covered here. This article mainly uses the Android Studio plug-in: Java2smali, which can be found in Android Studio. Its function is to directly compile Java code into SMALI, which is convenient for secondary packaging.
The target
Insert an interface code in the APK of a day headline, click Feedback in its Settings interface to enter the interface we created. The effect is as follows: Click Feedback to enter a new air conditioning control interface:
steps
1. Transition from Java to SmALI
After writing the code in Android Studio, github code address has the code, using Java2smali to generate the smALI version of the code:
This includes smALI versions of AirMoveView and DrawActivity Java files
Because of anonymous inner classes, two SMALI files are generated per Java file.
2. Modify the Smali file
The syntax of smali is introduced in this article. Each variable in SMali uses the path plus the class name, so we need to modify the related path. In this article the smali files placed on the com/ss/android/article/base/feature/mine/directory, and BaseSettingActivity on the same path. Change the variables in the four smali files to the correct path, as shown below: Github address has the complete code, you can download to learn.
3. Resource files and ids
Interfaces typically require XML files for layout, so place the corresponding XML layout file in the RES/Layout path. Note that custom controls in the XML file here also want to change the path of com/ss/android/article/base/feature/mine /
If you think you can pack it up and run it, you’re too young. Android R R files in the Android are introduced in the construction of files generated rules, we need to according to according to the rules of the XML file id write R, specific path is com/ss/Android/article/news/R $id. Be sure to follow the rules mentioned in Android R file generation to write correctly. The following quotes are from the article:
Author: Hi Big head ghost Hi
Link: https://www.zhihu.com/question/19730414/answer/67288581
The resource ID is a 4-byte unsigned integer, where the highest byte represents the Package ID, the second-highest byte represents the Type ID, and the lowest two-byte represents the Entry ID.
The Package ID is like a namespace that restricts the source of the resource. The Android system currently defines two resource command Spaces, one system resource command space with a Package ID equal to 0x01 and the other application resource command space with a Package ID equal to 0x7f. All Package ids between [0x01, 0x7f] are valid, and any Package ids outside this range are invalid. The package ID of the system resource package package-export.apk mentioned earlier is equal to 0x01, and the package ID of the resources defined in our application is equal to 0x7f, which can be verified by the generated R.java file.
Type ID indicates the Type ID of the resource. The resource types are animator, Anim, Color, Drawable, Layout, Menu, RAW, String, and XML, each of which is assigned an ID.
Entry ID indicates the order in which each resource appears in the resource type to which it belongs. Note that Entry ids for different types of resources may be the same, but because they are of different types, we can still distinguish them by their resource ids.
Therefore, the ID in the file cannot be written randomly. The first few digits should be the same, and the following Entry ids should be written in sequence. The new ID in this paper is shown as follows:
Layout XML layout file also to the com/ss/android/article/news/R $layout; In writing:
Also pay attention to the rules.
4. The tip
Generally speaking, we can’t intercept the log data of the release version of APK, but the part of the code we wrote can see the log at runtime, which can help us debug the program.
In addition, we must compile the signature installation of several commands to write as a script, convenient installation and debugging, or every time to knock several commands is very troublesome, even if there is command record when the need for multiple debugging is also very troublesome.
conclusion
In this paper, it is important to master the generation rules of R files and the basic syntax of SMali. Only by mastering the basic knowledge can we quickly locate and solve problems when encountering problems.