See good technical tutorials just want to reprint, do not like to spray! Thanks for the cooperation, only for rookie study study, do not do bad oh \ (^o^)/~
about the Android APP two times packaging phenomenon is not uncommon, why the "packaging party" daylight the Android platform, two times the process of packaging how simple?
This article will be from the structure of Android APK, two packaging tools, steps and so on to explain to the mobile developers two times the simplicity of packaging operations, resulting in the developer's attention to the security of the app, and timely code to confuse the app or reinforcement protection and other security measures.
file structure of Android APK First Look at Android apk the internal file structure.
Download a phone for free APP , you can use the Unzip tool to view its internal file structure, 1 as shown:
The main file contents in the APK are:
1.androidmanifest.xml: Android master configuration file, which is converted from text format to binary axml file format during compilation.
2.classes.dex: A bytecode-like file generated after Java code is compiled.
3.res/ folder : A resource file in which the. xml file is converted from text format to binary axml file format during compilation.
4.META-inf/ folder: Signature file.
5.Lib: Native code compiled so.
6. Other folders : Files added by the developer themselves
The core logic of Android apk is mainly in Classes.dex, usually the cracker will operate on the Classes.dex and Androidmanifest.xml files when they are cracked and packaged two times. So protecting these two files is especially important. Knowing the meaning and purpose of each of the Android apk files, you can have a targeted two-time packaging operation.
Two,apk Two packaging steps
Typically, the two-pack steps of the Android apk include:
1. Anti-compilation
(1) decompile java:classes.dex decompile into intermediate files (Smali, jar).
(2) decompile the layout file: The Axml file is deserialized into an XML file.
2. Modifications
(1) Modify the Smali file.
(2) Modify the XML file.
3. recompile
(1) the modified Smali compiled into Classes.dex.
(2) the modified XML is compiled into Axml.
4. re-signing
to re-sign the new APK, a new app will be created.
third, the Anti-compilation tool
1. decompile Java code tools:
(1)apktool
(2)Smali/baksmali
(3)Dex2jar + Jd-gui
(4) Integrated Image window Tools: Change manager, JEB
2. decompile The layout file (XML) tool:
(1)AXMLPrinter2
(2)Apktool
(3) Open source project for parsing axml files on Github
Four, anti-compilation apk
anti-compilation Java refers to the process of using the Classes.dex file to generate an intermediate language. samli file or jar file, the common means are:
(1)java–jar apktool.jard–r–f input.apk output directory.
(2)java-jar baksmali-1.4.1.jar-o output directory classes.dex.
(3)dex2jar.bat classes.dex.
(4) Image window Tool: Change the manager or Jeb.
(5)Android SDK comes with dexdump tool.
where the Dex2jar.bat tool outputs a. jar file that is read-only and non-modifiable. If you need to modify and package two times, you cannot use the tool. All other tools generate Smali files.
v. Modify the. samli file
some tips for modifying the. Samli Language:
(1) Information Feedback method (popup message does not break the breakthrough).
(2) feature function method (Toast, Log, Getpublickey, etc.).
(3) Code injection method (log output with Logcat view state data).
(4) Stack Tracking method
Doubtful insert the following code to get the function call Order: New Exception ("Print Trace"). Printstacktrace ();
Vi. Anti-compilation layout file (XML) tool
Anti-compile layout file refers to: The APK, binary Axml file is restored to a text format XML file. Common means:
java–jar Axmlprinter2.jar androidmanifest.xml > Out.xml
Java–jar apktool.jar d input.apk output directory
where Axmlprinter2.jar is just one-way, unable to recompile the text file into Axml. In addition, if there are more advanced requirements, the above 2 tools can not be satisfied. The reader can implement a Axml file parser on its own. There are already many similar open source projects on the web.
vii. Modify the layout file:
by Axml file to get the text format of the XML file, you can according to demand, arbitrarily modify the Androidmanifest.xml file. For example:
<meta-data
android:name= "baidumobad_app_id"
android:value= "10035477"/>
This is a Baidu advertising logo field. Where Android:value is the developer's certification value, directly linked to advertising revenue. As long as you modify the field, you can steal the income of someone else's ad.
Eight, recompile apk
in order for the changes to take effect, you need to recompile the file to generate a new apk.
recompile Java code: Regenerate the Classes.dex file with the modified. Smali file.
(1)java–jar apktool.jar b–f input directory new.apk
(2)java-jar smali-1.4.1.jar classout/-oclasses.dex
(3) image window tools: Change manager or Jeb
(4) recompile the XML file:
(5)java–jar apktool.jar b–f input directory new.apk
(6) Implement Axml file parser on GitHub open source project.
Note: apk decompile and recompile use the tool to match, for example: Use Apktool to decompile, then recompile also use Apktool.
Nine, re-signing
1. After compiling the APK, after the new apk is created, it must be re-signed because it has changed the contents of the file.
2. Install and run the new apk. You can see that the changes are in effect.
The above is the two-time packaging steps, the operation is really simple.
in order to avoid their own hard to develop the app was cracked and two times packaging, there are a number of third-party reinforcement protection products.
PS: The Internet is a search for everything.
Reprint share: Android app two times packaging operation steps introduced