[Android] decompile apk + debug smali in eclipse

Source: Internet
Author: User
Tags netbeans

I have never thought that decompiling apk is so convenient, and it can be modified and re-compiled and run. This is much easier than modifying pe in win, thanks to the authors of apktool and smali for providing such a good tool.

 

The common practice of tracking apk is to insert the log output in the decompiled smali code and re-compile and run the code to view the output log. This method is time-consuming and labor-consuming. It is best to debug the SDK in real time. After searching, the better method is to use NetBeans + DDMS. I have tried debugging, but I don't know much about NetBeans operations. eclipse is probably a lot of people. In fact, the setting is similar to NetBeans.

Debugging steps:

1. decompile debugable smali code to the out folder using apktool for apk. The latest apktool version is 2.0.0b7.

java -jar apktool_2..0b7.jar d -d test.apk -o out

The-d parameter must be used here. In this way, the suffix of the decompiled code is java, because only java files can be recognized and debugged By eclipse/netbeans.

2. Set the debugging tag and find the main class

In the output out folder, use the text editing tool to open AndroidManifest. xml and set the property android: debuggable = "true" on the application node ".

Search for the following keywords in AndroidManifest. xml:

        

                                                                                

Use the text editing tool to open the main class file and find the onCreate method. Remember to add a = 0; // prefix to keep the upper and lower consistency. The result is as follows:

a=0;a=0;a=0;a=0; a=0;a=0;a=0; a=0;a=0;a=0;

java -jar apktool_2..0b7.jar b -d out -o debug.apk

Bytes

java -jar .\signapk\signapk.jar .\signapk\testkey.x509.pem .\signapk\testkey.pk8 .\debug.apk .\debug.sign.apk

6.upload debug.sign.apk to your mobile phone or simulator, and then install and run it. At this time, you will see that the program is running and stuck on the white screen interface. Do not touch the device or exit the program, because the program is now running to the added waitForDebugger code here, this line of code means that it is always suspended and waiting for the debugger.

 

Set up the real-time debugging environment.

7. Go to the out folder generated in step 1 and delete the build and dist folders. This is generated when apktool compiles the apk.

8. Start eclipse and build a java Project

1) File-> New-> Project-> Java Project-> Next

2) The Project Name can be started as needed. Remove the Use default location option, select the out folder for Location, and then click

3) set the smali Folder to Source Folder, and then Finish

9. In eclipse, open the main class found in step 1, find the onCreate method, and add a breakpoint in the first method after waitForDebugger. For example

10. open DDMS (Path: % android-sdks % \ tools \ ddms. bat). If the modified program is run in step 1, the program that can be debugged is displayed in the device list of DDMS.

The last column of the corresponding program is 8600/8700, of which 8600 is the port for debugging the program.

11. Now we need to associate the Code with the debugging program. Go back to eclipse and configure remote debugging

1) choose Run> Debug Configurations.

2) double-click Remote Java Application. Set "localhost" to "10th" in "Port" and then "Apply-> Debug.

12. At this time, eclipse automatically switches to the debug view, and you can see that the program is running and the code that can be executed in the next line is interrupted. You can directly view the relevant variables.

 

You can use eclipse to debug smali. The above example is to start debugging from the beginning of the program, but it is really troublesome to debug the code in the place you care about. We recommend that you use software such as jd-gui to directly view the decompiled java code. After determining the debugging location, you can go to smali to locate the breakpoint and debug it in real time.

You can download related tools here.

Apktool: https://code.google.com/p/android-apktool/

Dex2jar: https://code.google.com/p/dex2jar/

Jd-gui: http://jd.benow.ca/

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.