Android decompilation Program

Source: Internet
Author: User
Tags uncompress

APK File Format
Android Application packagefile. Every application to be installed on the Android platform must be compiled and packaged into a single file with a suffix of. APK, which contains the application's binary code, resources, configuration files, and so on.
The APK file is actually a zip package. You can use the decompression tool to uncompress it. You can use zip to uncompress the *. APK file. The following is a helloword APK sample file.

Java code:

  1. |-Androidmanifest. xml
  2. |-META-INF
  3. |-Cert. RSA
  4. |-Cert. SF
  5. | '-Manifest. MF
  6. |-Classes. Dex
  7. |-Res
  8. |-Drawable
  9. | '-Icon.png
  10. | '-Layout
  11. | '-Main. xml
  12. '-Resources. ARSC

Copy code

Manifest file: androidmanifest. XML is defined and contained by each application. It describes the application name, version, permission, referenced library file, and other information. [,], to upload the APK to the Google market, you also need to configure the XML. note: The XML file in the APK is compressed and cannot be opened directly.
Res file: All resource files in the res folder.
Resources. ARSC file: it is a compiled binary resource file. Many Chinese software developers modify the resources in the file to implement software localization.
META-INF Directory: The META-INF directory stores the signature information, used to ensure the integrity of the APK package and system security. when eclipse compiles an API package, it will do a verification calculation for all the files to be packaged, and put the calculation result under the META-INF directory. when the APK package is installed on the ophone platform, the Application Manager checks the file in the package according to the same algorithm. If the verification result is inconsistent with the content in the META-INF, the system will not install this APK. this ensures that the files in the APK package cannot be replaced at will. for example, after obtaining an APK package, if you want to replace an image, a piece of code, or a piece of copyright information, it is basically impossible to directly decompress, replace, and re-package the package. this increases the difficulty of virus infection and malicious modification, and helps protect the system.
Security.
Classes. dex is a Java bytecode file generated after Java source code compilation. however, because the Dalvik Virtual Machine Used by Android is incompatible with the standard Java virtual machine, the DEX file and the class file are different in both the file structure and opcode.
Decompilation of XML files
The XML file in the APK is compressed. You can use the axmlprinter2 tool to unbind it. The specific command is:
Java-jar axmlprinter2.jar androidmanifest. xml
Example of the manifest file in the helloandroid program:

Java code:

  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <Manifest
  3. Xmlns: Android = "http://schemas.android.com/apk/res/android"
  4. Android: versioncode = "1"
  5. Android: versionname = "1.0"
  6. Package = "name. feisky. Android. test"
  7. >
  8. <Application
  9. Android: Label = "@ 7f040001"
  10. Android: icon = "@ 7f020000"
  11. >
  12. <Activity
  13. Android: Label = "@ 7f040001"
  14. Android: Name = ". helloandroid">
  15. <Intent-filter>
  16. <Action Android: Name = "android. Intent. Action. Main">
  17. </Action>
  18. <Category Android: Name = "android. Intent. Category. launcher">
  19. </Category>
  20. </Intent-filter>
  21. </Activity>
  22. </Application>
  23. <Uses-SDK Android: minsdkversion = "6">
  24. </Uses-SDK>
  25. </Manifest>

Copy code

The original file is:

Java code:

  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <Manifest xmlns: Android = "http://schemas.android.com/apk/res/android"
  3. Package = "name. feisky. Android. test"
  4. Android: versioncode = "1"
  5. Android: versionname = "1.0" type = "codeph" text = "/codeph">
  6. <Application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name">
  7. <Activity Android: Name = ". helloandroid"
  8. Android: Label = "@ string/app_name">
  9. <Intent-filter>
  10. <Action Android: Name = "android. Intent. Action. Main"/>
  11. <Category Android: Name = "android. Intent. Category. launcher"/>
  12. </Intent-filter>
  13. </Activity>
  14. </Application>
  15. <Uses-SDK Android: minsdkversion = "6"/>
  16. </Manifest>

Copy code

Classes. Dex file Decompilation

Classes. dex is a Java bytecode file generated after Java source code compilation. however, because the Dalvik Virtual Machine Used by Android is incompatible with the standard Java virtual machine, the DEX file and the class file are different in both the file structure and opcode. currently, common Java decompilers cannot process Dex files.
The android simulator provides a decompilation tool for Dex files, dexdump. the usage is to first start the android simulator, and use the ADB push upload simulator to view the DEX file. Then, log on to the simulator through the ADB shell, find the DEX file to be viewed, and execute dexdump XXX. dex. however, the readability of the result is very poor. the following describes a readable tool.
Tool preparation:
1. decompile the DEX file into a jar file. (dex2jar)
2. decompile the jar into a Java tool. (JD-GUI)
Decompilation steps
1. Extract classes from APK. dex file. decompress the APK file. put it in the dex2jar directory, open cmd, and run dex2jar. bat classes. dex to generate classes. dex. dex2jar. jar.
2, run the JD-GUI tool, open the jar file above, you can see the source code.

Helloandroid instance:

Java code:

  1. Package name. feisky. Android. test;
  2. Import Android. App. activity;
  3. Import Android. OS. Bundle;
  4. Public class helloandroid extends activity {
  5. Public void oncreate (bundle parambundle ){
  6. Super. oncreate (parambundle );
  7. Setcontentview (2130903040 );
  8. }
  9. }

Copy code

The original program is:

Java code:

  1. Package name. feisky. Android. test;
  2. Import Android. App. activity;
  3. Import Android. OS. Bundle;
  4. Public class helloandroid extends activity {
  5. /** Called when the activity is first created .*/
  6. @ Override
  7. Public void oncreate (bundle savedinstancestate ){
  8. Super. oncreate (savedinstancestate );
  9. Setcontentview (R. layout. Main );
  10. }
  11. }

Copy code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.