Android 反编译
一、需要准备三个软件包
1. apktool
用于反编译解析资源文件
2. dex2jar
用于反编译出JAVA代码
3. jd-gui
用于查看JAVA代码
二、使用apktool反编译出资源文件
C:\>apktool d hupan.apk
I: Using Apktool 2.0.2 on hupan.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: C:\Users\hp\apktool\framework\1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
此时会在当前目录下生成与apk文件名称一样的文件夹,文件夹内就是反编译出的资源文件
三、将apk文件后缀名改为 .zip ,使用压缩软件,解压出classes.dex。将解压的classes.dex文件拷贝到dex2jar文件夹内,使用dex2jar反编译出jar文件。
C:\> d2j-apk-sign.bat classes.dex
this cmd is deprecated, use the d2j-dex2jar if possible
dex2jar version: translator-0.0.9.15
dex2jar classes.dex -> classes_dex2jar.jar
Done.
此时该文件夹下会生成classes_dex2jar.jar
文件,然后就可以使用jd-gui
来查看该jar文件的java文件了。
所遇到的错误:
- 使用apktool时出现brut.androlib.err.UndefinedResObject错误提示:
I: Using Apktool 2.0.2 on hupan.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: C:\Users\hp\apktool\framework\1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
Exception in thread "main" brut.androlib.err.UndefinedResObject: resource spec: 0x01010462
at brut.androlib.res.data.ResPackage.getResSpec(ResPackage.java:59)
at brut.androlib.res.data.ResTable.getResSpec(ResTable.java:65)
at brut.androlib.res.data.ResTable.getResSpec(ResTable.java:61)
at brut.androlib.res.data.value.ResReferenceValue.getReferent(ResReferenceValue.java:57)
at brut.androlib.res.data.value.ResStyleValue.serializeToResValuesXml(ResStyleValue.java:54)
at brut.androlib.res.AndrolibResources.generateValuesFile(AndrolibResources.java:502)
at brut.androlib.res.AndrolibResources.decode(AndrolibResources.java:252)
at brut.androlib.Androlib.decodeResourcesFull(Androlib.java:135)
at brut.androlib.ApkDecoder.decode(ApkDecoder.java:102)
at brut.apktool.Main.cmdDecode(Main.java:165)
at brut.apktool.Main.main(Main.java:81)
解决方法:
从手机中导出framework-res.apk
文件(/system/framework目录下),拷贝到apktool目录下,执行以下语句:
C:\> apktool if framework-res.apk