I. Preface:
Hello everyone, today I will share with you the app master in Android
Yi, we often encounter an application (APK) that we think is very beautiful and handsome, so we will try to view it using tools such as WinRAR, the general application package directory is usually like this
For example:
-Sikaodelang blog "src =" http://hi.csdn.net/attachment/201007/6/0_127842027099yj.gif "alt =" ">
Of course, images in Res can be used for use (many of my application images are deducted from others' APK), and layout and permission files in Layout
(Androidmanifest. XML) is already a bunch of garbled characters, and it is not easy to understand. And the source code is compiled
Classes. Dex, no clue at all. 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
Iii. Preparations
For convenience, the author puts axmlprinter2.jar,
There are also baksmali. jar and smali. Jar (to facilitate renaming), as shown in the android SDK Tools Folder:
(Compile, decompile, axmlprinter2, smali, baksmali )! -Sikaodelang-
Sikaodelang's blog "src =" http://hi.csdn.net/attachment/201007/6/0_1278422814OtL8.gif "alt =" ">
To make it easier for you to compare programs, the author writes a simple application (called apkinstaller) directory structure, as shown in:
(Compile, decompile, axmlprinter2, smali, baksmali )! -Sikaodelang-
Sikaodelang's blog "src =" http://hi.csdn.net/attachment/201007/6/0_1278423065QDw8.gif "alt =" ">
4. Start to take things
1. Use
Axmlprinter2.jar:
Use WinRAR for apkinstaller.apk generated by apkinstaller.apk (put it in the tools directory for convenience)
Open the tool and decompress Res/layout/Main. XML (also in the tools directory)
Open the main. xml file with the following content (a pile of astronomy ):
(Compile, decompile, axmlprinter2, smali, baksmali )! -Sikaodelang-
Sikaodelang's blog "src =" http://hi.csdn.net/attachment/201007/6/0_12784234694nns.gif "alt =" ">
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.
(As shown in)
(Compile, decompile, axmlprinter2, smali, baksmali )! -Sikaodelang-
Sikaodelang's blog "src =" http://hi.csdn.net/attachment/201007/6/0_12784239040J8s.gif "alt =" ">
Open the main.txt Code as follows (Is There A 123 error ~) :
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout <br/> xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Orientation = "1" <br/> Android: layout_width = "-1" <br/> Android: layout_height = "-1" <br/> <webview <br/> Android: id = "@ 7f050000" <br/> Android: layout_width = "-1" <br/> Android: layout_height = "-2" <br/> </webview> <br/> </linearlayout> <br/>
To compare the main. XML code in the open source program as follows (check the code ):
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Orientation = "vertical" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> <webview <br/> Android: id = "@ + ID/apk_web" <br/> Android: layout_height = "wrap_content" <br/> Android: layout_width = "fill_parent" </P> <p>/> <br/> </linearlayout> <br/>
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
. (As shown in :)
You will find another classout folder in tools (the package directory structure of my code is clearly visible), as shown in:
From the above we can see that apart from the class R of Android resources, there is only one apkinstaller. Java in my source program, which is exactly the same. It's really tricky for TMD ~
Let's take a look at the content of apkinstaller. smali, as shown in the following code:
. Class public lcom/tutor/apkinstaller; <br/>. super landroid/APP/activity; <br/>. source "apkinstaller. java "<br/> # instance fields <br/>. field private apkweb: landroid/WebKit/webview; <br/> # direct methods <br/>. method public constructor <init> () v <br/>. registers 1 <br/>. prologue <br/>. line 8 <br/> invoke-Direct {P0}, landroid/APP/activity;-> <init> () v <br/> return-void <br/>. end method <br/> # Virtual Methods <br/>. method public oncreate (landroid/OS/bundle;) v <br/>. registers 5 <br/>. parameter "savedinstancestate" <br/>. prologue <br/>. line 13 <br/> invoke-Super {P0, P1}, landroid/APP/activity;-> oncreate (landroid/OS/bundle;) v <br/>. line 14 <br/> const/high16 V2, 0x7f03 <br/> invoke-virtual {P0, V2}, lcom/tutor/apkinstaller;-> setcontentview (I) v <br/>. line 15 <br/> const/high16 V2, 0x7f05 <br/> invoke-virtual {P0, V2}, lcom/tutor/apkinstaller;-> findviewbyid (I) landroid/View/view; <br/> move-result-object V2 <br/> check-cast V2, landroid/WebKit/webview; <br/> Iput-object V2, p0, lcom/tutor/apkinstaller;-> apkweb: landroid/WebKit/webview; <br/>. line 16 <br/> iget-object V2, P0, lcom/tutor/apkinstaller;-> apkweb: landroid/WebKit/webview; <br/> invoke-virtual {V2}, landroid/WebKit/webview;-> getsettings () landroid/WebKit/websettings; <br/> move-result-object V1 <br/>. line 17 <br/>. local V1, websettings: landroid/WebKit/websettings; <br/> const/4 V2, 0x1 <br/> invoke-virtual {V1, V2 }, landroid/WebKit/websettings;-> setjavascriptenabled (z) v <br/>. line 19 <br/> const-string v0, "http://frankiewei.net/apk/demos/main/index.html#home" <br/>. line 20 <br/>. local v0, apkurl: ljava/lang/string; <br/> iget-object V2, P0, lcom/tutor/apkinstaller;-> apkweb: landroid/WebKit/webview; <br/> invoke-virtual {V2, V0}, landroid/WebKit/webview;-> loadurl (ljava/lang/string;) v <br/>. line 21 <br/> return-void <br/>. end method <br/>
For comparison, let's take a look at the source code of apkinstaller. Java as follows:
Package com.tutor.apk installer; <br/> Import android. app. activity; <br/> Import android. OS. bundle; <br/> Import android. webKit. websettings; <br/> Import android. webKit. webview; <br/> public class apkinstaller extends activity {</P> <p> private webview apkweb; <br/> @ override <br/> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); <br/> apkweb = (webviewdomainfindviewbyid(r.id.apk _ Web); <br/> websettings = apkweb. getsettings (); <br/> websettings. setjavascriptenabled (true); </P> <p> string apkurl = "http://frankiewei.net/apk/demos/main/index.html#home"; <br/> apkweb. loadurl (apkurl); <br/>}< br/>}
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 in the first try,
Run the following command:Java-jar smali. Jar classout/-O classes. Dex.
As shown in:
We can insert the new classes.dexinto apkinstaller.apk to overwrite the original classes. Dex file, so that our APK can still be used ~
OK ~ Today, I am writing this article for the time being. It is really not easy to write this article. After writing this article for a long time, some people from Wuhan IP have deleted this article, I wrote it again. Hope you can make more progress! THX ~