反编译android中的xml文件

来源:互联网 发布:视频噪声消除软件 编辑:程序博客网 时间:2024/05/19 00:41

一、前言:

大家好,今天给大家分享一下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了呵呵~):

[html] view plain copy
  1. view plaincopy to clipboardprint?  
  2. <?xml version="1.0" encoding="utf-8"?>     
  3. <LinearLayout     
  4.     xmlns:android="http://schemas.android.com/apk/res/android"    
  5.     android:orientation="1"    
  6.     android:layout_width="-1"    
  7.     android:layout_height="-1"    
  8.     >     
  9.     <WebView     
  10.         android:id="@7F050000"    
  11.         android:layout_width="-1"    
  12.         android:layout_height="-2"    
  13.         >     
  14.     </WebView>     
  15. </LinearLayout>    
  16. <?xml version="1.0" encoding="utf-8"?>  
  17. <LinearLayout  
  18.  xmlns:android="http://schemas.android.com/apk/res/android"  
  19.  android:orientation="1"  
  20.  android:layout_width="-1"  
  21.  android:layout_height="-1"  
  22.  >  
  23.  <WebView  
  24.   android:id="@7F050000"  
  25.   android:layout_width="-1"  
  26.   android:layout_height="-2"  
  27.   >  
  28.  </WebView>  
  29. </LinearLayout>  
为了比对打开源程序中的main.xml代码如下(大家比对一下吧):

[html] view plain copy
  1. view plaincopy to clipboardprint?  
  2. <?xml version="1.0" encoding="utf-8"?>     
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
  4.     android:orientation="vertical"    
  5.     android:layout_width="fill_parent"    
  6.     android:layout_height="fill_parent"    
  7.     >     
  8. <WebView     
  9.     android:id="@+id/apk_web"    
  10.     android:layout_height="wrap_content"    
  11.     android:layout_width="fill_parent"    
  12.          
  13. />     
  14. </LinearLayout>   

注意:本文是转载!

1 0
原创粉丝点击