一、前言:
大家好,今天給大家分享一下Android中的拿來主義,我們時常會碰到一個自己覺得很漂亮很帥氣的應用(apk),所以我們會嘗試用WinRAR等之類工具查看,而一般的應用程式打包後的目錄通常是這樣的如:
當然res裡的圖片是可以拿來就用的(筆者的好多應用的圖片都是從別人的apk裡扣出來的),而諸如layout裡的布局及許可權檔案(AndroidManifest.xml)已經是一堆亂碼了,完全看不懂,想看看別人是怎麼布局的都不容易。還有原始碼都被編譯成了classes.dex,完全看不出什麼線索。基於以上的困惑,筆者給大家分享一下Android中的拿來主義。
二、所需工具(點擊各自串連進入下載頁面):
1.AXMLPrinter2.jar
2.baksmali.jar
3.smali.jar
三、準備工作
為了方便起見,作者把AXMLPrinter2.jar,還有baksmali.jar,還有smali.jar(下下來為了方便重新命名),放在Android SDK tools檔案夾中如所示:
為了便於大家更容易程式比對,作者寫了一個簡單的應用(叫APKInstaller)目錄結構如所示:
四、開始拿來主義
1.用AXMLPrinter2.jar查看apk中的布局xml檔案:
將ApkInstaller應用產生的ApkInstaller.apk(為了方便起見放到tools目錄裡)用WinRAR等工具開啟,將res/layout/main.xml解壓出來(也還是放在tools目錄裡哦)
開啟main.xml檔案,內容如下(一堆天文):
這時候AXMLPrinter2.jar派上用場了,開啟cmd終端,一直進入到tools目錄下,輸入如下命令:
java -jar AXMLPrinter2.jar main.xml > main.txt. (如所示)
開啟main.txt代碼如下(是不是有個123了呵呵~):
view plaincopy to clipboardprint?
<?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>
<?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>
為了比對開啟來源程式中的main.xml代碼如下(大家比對一下吧):
view plaincopy to clipboardprint?
<?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>
本文來自CSDN部落格,轉載請標明出處:http://blog.csdn.net/Android_Tutor/archive/2010/07/06/5716970.aspx