Android APK source code Changes--anti-compilation + source code changes + another package + signature "with HelloWorld change instance"

Source: Internet
Author: User

recently encountered the need to change the APK source code problems, and then surf the Internet to check the relevant information. Written HelloWorld to make changes to see the feasibility of the program proved feasible, and later successfully used this method to change the target apk, just need to change the part is more complex than HelloWorld, but only to understand the next Smali can also make relevant changes, the following detailed steps, the resources used in the text will be given at the end of the article, interested in the ability to download the test.


First introduce the following tools:

JDK: No more talking about this.

Baksmali: Tools to convert Classes.dex to Smali files
Dex2jar:classes.dex tools for converting to jar packages
Jdgui: Tools for reading jar files (Linux and Windows version numbers). Resources)
Smali: Tools to compile Smali files into Classes.dex

baksmali and Smali can look at Google's introduction http://code.google.com/p/smali/ (Need FQ now)

dex2jar and jdgui not necessary. Just to view the source code, as it looks directly smali Span style= "font-family: ' Microsoft Yahei '; font-size:18px; Line-height:25.200000762939453px "> file difficult


The following are the resources used in the article:

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvbhvjagvycg==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">


No changes can be made to the Dex file and to the jar package after it has been deserialized. Simply convert the Dex file into a Smali file for changes. Then compile the package as a Dex file and replace the Dex file in the original apk. Then the APK is signed, so that the APK source code changes, the detailed process such as the following: (The following is done under Linux.) Windows may be slightly different)

1. Unzip the apk file to get Classes.dex and copy to the resource root folder (you can use zip or other decompression tools)


2. Use the Baksmali tool to convert classes.dex to Smali file. On the command line, navigate to the resource root folder and run:

Java-jar baksmali-2.0.3.jar-x Classes.dex

After running , the Out folder is generated under the current folder. The folder structure is the same as the source code. Locate the appropriate Smali file under the appropriate folder


3. Use the Dex2jar tool to convert Dex to a jar file. Copy Classes.dex to the dex2jar-0.0.9.15 folder under the Resources folder , locate the command line to the folder and run :

./dex2jar.sh classes.dex (windows:dex2jar.bat classes.dex)

after running, the Classes_dex2jar.jar file is generated under the current folder and can be viewed through Jdgui


4. Use the Jdgui tool to view the source code of the HelloWorld. Open the corresponding Jdgui tool under the resource folder according to different system , then drag the Classes_dex2jar.jar file generated by the 3rd step into the tool, such as the following:

5. Change the corresponding Smali file, and look at the corresponding Smali file section below:

Where the fluorescent strokes are part of the need to change the place, in this example changed to "Hello world!modify success", Save the file


6. Use the Smali-2.0.3.jar tool to convert the Smali file to a Dex file. Locate the command line to the resource root folder and run:

Java-jar smali-2.0.3.jar-o Classes.dex out

after running , the Classes.dex file under the root folder will be generated and replaced, so the change is successful.


7. Replace the newly generated classes.dex file with the original APK file (using the compression tool)


8. Sign the APK with the signature tool. Copy the APK to the Sign_tool folder under the Resource root folder and locate the command line to the folder and run:

Java-jar signapk.jar platform.x509.pem platform.pk8 helloworld.apk signed.apk

The signed.apk file is generated under this folder when it finishes running. This file is the last file.


9. Uninstall the original HelloWorld, install the signed.apk file generated in step 8th, perform effects such as:

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvbhvjagvycg==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">



Finally, tell me a little bit about my actual changes: I want to add a log to the target apk, choose a toast, but it's too hard to write directly, so I'm going to add a toast to the HelloWorld and see the generated code in the corresponding Smali file. Then copy to the target apk corresponding file to test. Including the subsequent switch statements are also analyzed, the following look at the print Toast Smali statement (in the actual case may need to change the variable name, because it may be followed by the variable name conflict)

Const-string V0, "This is a test"    const/16 v1, 0x3e8    invoke-static {p0, V0, v1}, Landroid/widget/toast;->maket Ext (landroid/content/context; Ljava/lang/charsequence;i) Landroid/widget/toast;    Move-result-object v0    invoke-virtual {v0}, Landroid/widget/toast;->show () V



Resource Download point here ^ ^


Android APK source code Changes--anti-compilation + source code changes + another package + signature "with HelloWorld change instance"

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.