Unpackage APK file, modify and repackage Signature

Source: Internet
Author: User
Tags unpack admob

Players are not familiar with APK. Do you know about APK modification? For example, you can perform Chinese-English Version modification, modify functions, Modify text descriptions, and remove advertisements. This article describes the basic knowledge, structure, unpackage, package, and signature of the APK file, as well as regular modification to the APK file.

1. APK file Introduction

APK is the abbreviation of Android Package, that is, the Android application package file or the Android installation Package. Every application to be installed on the Android platform must be compiled into a single file with the suffix .apk. The APK file is a file package compiled and generated by the specialized software eclipse, which contains the binary code, resources, and configuration files of the application. You can install the SDK by directly uploading the APK file to your Android phone. The APK file is actually in zip format, but its extension is changed to apk, which can be opened directly with the decompress software. After unzipping through WinRAR or UnZip, you will see several files and folders. I
A typical APK file consists of the following content:

Global configuration file of AndroidManifest. xml Program
Classes. dex Dalvik bytecode
Resources. arsc compiled binary resource file
META-INF \ This directory stores signature information
Res \ This directory stores resource files
Assets \ This directory can store some configuration files

Below are some basic comments and introductions to these files and directories.
AndroidManifest. xml: this file is a file that every application must define and contain. It describes the name, version, permission, and referenced library file of the application. You must unpack the package before reading it.
Classes. dex: this file is a java bytecode file generated after java source code compilation. Dex is the full name of Dalvik VM executes, that is, the Android Dalvik execution program, not the Java ME bytecode but the Dalvik bytecode.
Resources. arsc: The compiled binary resource file.
META-INF Directory: The Directory stores signature information, used to ensure the integrity of the apk package and system security. When eclipse compiles an apk package, it will do a verification calculation for all the files to be packaged, and put the calculation result under the META-INF directory. 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 security of the system.
Res Directory: directory to store resource files. Including images and strings. [Note] After unpacking, almost all possible modifications and edits are here.
Assets Directory: The Directory can store some configuration files. The content of these files can be obtained through related APIs during the program running.

Ii. unpackage and package APK files

The APK file is a file package compiled by professional software eclipse. You can find a lot of software on the Internet to decompile the APK content. For example, you can use the AXMLPrinter2 tool and command: java-jar AXMLPrinter2.jar AndroidManifest. xml to unlock AndroidManifest. xml in the apk.

However, the more powerful package unpacking toolkit is apktool, which can be used in Windows to quickly unpack and package APK files, bringing a lot of convenience for modification and editing. The following describes how to use it.

1) APKtool Software Package
The APKtool package consists of two programs: apktool. jar and aapt.exe.
In addition, a batch file apktool. bat is provided with the following content:
Java-jar "% ~ Dp0 \ apktool. jar "% 1% 2% 3% 4% 5% 6% 7% 8% 9
Running apktools. jar requires a java environment (version 1.6.0 or later ).
Apktool.jaris used for unpackaging. apktool.jarand aapt.exe are combined for packaging.

2) Unpack the APK File
The following example shows how to open contacts.apk. First copy contacts.apk to the current working directory (for example, test ). Input commands in DOS
Apktool. Bat D mythroad.net.apk mythroad.net
"D" indicates decoding. Mythroad.net.apk is the APK file to be decompressed. Mythroad.net is the subdirectory name. All unwrapped files are placed in this subdirectory.

3) APK file Packaging
Input commands in DOS
New-mythroad.net.apk for apktool. Bat B mythroad.net
"B" indicates the package.
Mythroad.net is a subdirectory name generated during unpacking. It is used to store all unwrapped and modified files.
The New-mythroad.net.apk is the new APK file generated after packaging.

4) Framework File
When you open an APK file, the apktools' framework file (framework-res.apk) is decoded and packaged. Apktool already contains a standard framework. Therefore, you do not need to provide a framework file when uninstalling most APK files. However, some manufacturers use their own framework files. In order to unpack the files, they have to extract the framework file (Framework-res.apk) from their mobile phones and install it on their computers. The installation command is:
Apktool if framework-res.apk
After installation, you will get :~ \ Apktool \ framework \ 1.apk
5) unpacking, unpacking, and signature batch processing
The following are very convenient batch processing commands:

Command for batch unpacking:
For % I in (*. APK) do Java-jar apktool. jar d % I _ % I & move _ % I modifying_files & copy % I backuped_raw_files & @ ECHO file [% I] unpacking process is completed!

Packaging and signature batch processing commands:
For/d % I in (*) do CD .. & Java-jar apktool. jar B modifying_files \ % I & Java-jar signapk. jar testkey. x509.pem testkey. pk8 modifying_files \ % I \ Dist \*. APK % I & Ren % I new % I & move New % I modified_signed_files & @ echo % I complete repacking and signing!
& CD modifying_files

Command for signing a single APK:

Java-jar signapk. Jar platform. x509.pem platform. pk8 new-mythroad.net.apk new-mythroad.net-signed.apk

Signapk. Jar + platform. x509.pem + platform. pk8 download (120)

 

3. Application modification example: Edit and modify the APK after unpacking

Why is it necessary to unpack the APK file? Of course, make necessary modifications to the content. What should I modify? Generally, if you only replace the image, there is no need to unpack or package it. Use WinRAR to open the APK file and replace it directly. However, if you want to modify text and other non-image content, you can only decode it by unpackaging it. The following tasks need to unpack and package the APK. Here is only a rough introduction. Please go to the detailed operation methods and tutorials.

1) Chinese APK Software
In the res folder, we can see that there are many values-*** folders, which are language packs. Values is an English Language Pack, values-ZH is a Chinese Language Pack (including Hong Kong, Macao, Taiwan and the mainland), and values-ZH-RCN is a simplified Chinese Language Pack (only including the Mainland ), values-ZH-RTW is a Chinese Traditional Language Pack (Hong Kong, Macao and Taiwan ). In addition, language packs for other regions are simplified objects.
In the values folder, there are usually arrays. XML, strings. xml and other language files. To make Chinese files, you must modify these files. Sometimes you also need to modify other XML files and view them one by one.

2) modify the icon label
Each APK file has an "icon tag ". After installing the APK program on your mobile phone, the icon label text is displayed under the icon. The content of this icon label can be modified. Find strings. xml under \ res \ values and modify one line:
<String name = "app_name"> icon tag </string>
For example, <string name = "app_name"> mute startup </string>
Similarly, if the window plug-in is used, modify widget_name.
Note: The APK in system/APP cannot be modified because the corresponding odex file must be modified at the same time.

3) Remove the advertisement from the APK
Many APK applications carry advertisements. To remove the advertisement in the program, modify the content related to the advertisement in the main. xml file. Find the main. xml file in the \ res directory. It is usually stored in the \ Layout directory and is sometimes stored in other directories. Sometimes, the main. xml file does not exist, and the advertisement line is placed in other XML files. You can only search for files one by one. In either case, you can see a similar command as follows. This is the advertisement display.
<COM. adMob. android. ads. adview Android: Id = "@ ID/ad" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" admobsdk: backgroundcolor = "# ff000000" admobsdk: textcolor = "# ffffffff" admobsdk: KEYWORDS = "Android Application"/>
Change it:
<COM. adMob. android. ads. adview Android: Id = "@ ID/ad" Android: layout_width = "0.0dip" Android: layout_height = "0.0dip" admobsdk: backgroundcolor = "# ff000000" admobsdk: textcolor = "# ffffffff" admobsdk: KEYWORDS = "Android Application"/>
As you can see, the key is to change fill_parent to 0.0dip, and change wrap_content to 0.0dip. Keep the rest unchanged. In this way, the advertisement is not displayed. Of course, you will not be able to see the advertisement.

4) change the display battery to 1% precision
On xt502, only 7 files are displayed by default: 0%, 10%, 20%, 40%, 60%, 80%, and 100%. You can change the display precision by modifying framework-res.apk. However, in xt502, practice has proved that the best possible accuracy is only 10%. The modification is as follows:
(1) Unpack framework-res.apk
(2) modify and add the battery status icon
(3) modify the stat_sys_battery.xml file.
(4) modify the stat_sys_battery_charge.xml file.
(5) Packaging
(6) extract stat_sys_battery.xml, stat_sys_battery_charge.xml, resources. arsc, and a directory named drawable-mdpi.
(7) reassemble framework-res.apk

5) the status bar information notifies you to modify the text color
The color of the State column information notification text is controlled by the colors. xml file under res \ values in the framework-res.apk file, so we only need to modify the colors. xml file. In addition, this file also controls the text color in the drop-down bar, which can be modified.
Open the colors. xml file in the text editor and find
<Color name = "hw_statusbar_time"> # ff000000 </color>
Modify this sentence to: <color name = "hw_statusbar_time"> # ffffffff </color>
The text color of the status bar information is changed from black to white.

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.