Use axmlprinter2, smali, and baksmali for Android compilation and anti-Encoding

Source: Internet
Author: User

 

I. Preface:
For example, layout and permission files (androidmanifest. XML) are a bunch of garbled characters and cannot be understood completely. It is not easy to see how other people layout them. The source code has been compiled into classes. Dex, which does not show any clue. Based on the above confusions, I would like to share with you the latencies in Android.

2. required tools (click their respective links to enter the download page ):

1. axmlprinter2.jar

2. baksmali. Jar

3. smali. Jar

Http://code.google.com/p/android4me/downloads/list Resources

Iii. Preparations

For convenience, the authors put axmlprinter2.jar, baksmali. jar, and smali. Jar (to facilitate renaming) in the android SDK Tools Folder, as shown in:

4. Get started with the Principles 1. Use axmlprinter2.jar to view the layout XML file in the APK:Open apkinstaller.apk generated by apkinstaller.apk (put it in the tools directory for convenience) with tools such as WinRAR, and open res/layout/main. decompress XML (or put it in the tools directory) to open main. XML file with the following content (a bunch of astronomy ):

At this time, axmlprinter2.jar came in handy. Open the CMD terminal and go to the tools directory. Enter the following command:Java-jar axmlprinter2.jar main. xml> main.txt. 

Open the main.txt Code as follows:

<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Orientation = "1"
Android: layout_width = "-1"
Android: layout_height = "-1"
>
<Webview
Android: Id = "@ 7f050000"
Android: layout_width = "-1"
Android: layout_height = "-2"
>
</Webview>
</Linearlayout>

To compare the main. XML code in the open source program as follows (check the code ):

<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<Webview
Android: Id = "@ + ID/apk_web"
Android: layout_height = "wrap_content"
Android: layout_width = "fill_parent"

/>
</Linearlayout>

2. decompile classes. Dex with baksmali. jar:Decompress classes. Dex in apkinstaller.apk to the tools directory, and then baksmali. jar will be used. Enter the following command in the CMD command line: JAva
-Jar baksmali. jar-O classout/classes. Dex
.

Let's take a look at the content of apkinstaller. smali, as shown in the following code:

. Class public lcom/tutor/apkinstaller;
. Super landroid/APP/activity;
. Source "apkinstaller. Java"
# Instance fields
. Field private apkweb: landroid/WebKit/webview;
# Direct methods
. Method public constructor <init> () V
. Registers 1
. Prologue
. Line 8
Invoke-Direct {P0}, landroid/APP/activity;-> <init> () V
Return-void
. End Method
# Virtual Methods
. Method public oncreate (landroid/OS/bundle;) V
. Registers 5
. Parameter "savedinstancestate"
. Prologue
. Line 13
Invoke-Super {P0, P1}, landroid/APP/activity;-> oncreate (landroid/OS/bundle;) V
. Line 14
Const/high16 V2, 0x7f03
Invoke-virtual {P0, V2}, lcom/tutor/apkinstaller;-> setcontentview (I) V
. Line 15
Const/high16 V2, 0x7f05
Invoke-virtual {P0, V2}, lcom/tutor/apkinstaller;-> findviewbyid (I) landroid/View/view;
Move-result-object v2
Check-cast V2, landroid/WebKit/webview;
Iput-object V2, P0, lcom/tutor/apkinstaller;-> apkweb: landroid/WebKit/webview;
. Line 16
Iget-object V2, P0, lcom/tutor/apkinstaller;-> apkweb: landroid/WebKit/webview;
Invoke-virtual {V2}, landroid/WebKit/webview;-> getsettings () landroid/WebKit/websettings;
Move-result-object V1
. Line 17
. Local V1, websettings: landroid/WebKit/websettings;
Const/4 V2, 0x1
Invoke-virtual {V1, V2}, landroid/WebKit/websettings;-> setjavascriptenabled (z) V
. Line 19
Const-string v0, "http://frankiewei.net/apk/demos/main/index.html#home"
. Line 20
. Local v0, apkurl: ljava/lang/string;
Iget-object V2, P0, lcom/tutor/apkinstaller;-> apkweb: landroid/WebKit/webview;
Invoke-virtual {V2, V0}, landroid/WebKit/webview;-> loadurl (ljava/lang/string;) V
. Line 21
Return-void
. End Method

For comparison, let's take a look at the source code of apkinstaller. Java as follows:

Package com.tutor.apk installer;
Import Android. App. activity;
Import Android. OS. Bundle;
Import Android. WebKit. websettings;
Import Android. WebKit. webview;
Public class apkinstaller extends activity {

Private webview apkweb;
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
Apkweb = (webviewdomainfindviewbyid(r.id.apk _ Web );
Websettings = apkweb. getsettings ();
Websettings. setjavascriptenabled (true );

String apkurl = "http://frankiewei.net/apk/demos/main/index.html#home ";
Apkweb. loadurl (apkurl );
}
}

I believe everyone can see the way it is, Hoho ~3. Use smali. jar to compile classout into classes. DEX:We have decompiled classes. Dex into the. smali file in the previous step. Now, let's take a look at the smali file. compile it into classes. Dex as a try. Run the following command:Java
-Jar smali. Jar classout/-o

We can insert the new classes.dexinto apkinstaller.apk to overwrite the original classes. Dex file, so that our APK can still be used.

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.