Android反编译apk

本文详细介绍如何使用aapt.exe、apktool.bat及dex2jar.bat等工具进行Android APK文件的反编译流程,包括清单文件和类文件的反编译步骤,并分析了反编译结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Android反编译apk

一:反编译清单文件:
aapt.exe和apktool.bat和apktool.jar以及要反编译的apk文件放在同一个文件夹下。
进入cmd,进入到存放这些文件的路径下,执行命令apktool空格d空格"apk的名字(带后缀)"。
反编译成功,将出现类似于一下的这些内容:
I: Baksmaling...
I: Loading resource table...
I: Loaded.
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: C:\Documents and Settings\Administrator\apk
tool\framework\1.apk
I: Loaded.
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Done.
I: Copying assets and libs...
这时将在与此apk文件所在的目录下生成以apk的名字(不带apk的后缀)命名的文件夹。
这个文件夹下的目录为:res(资源文件,可以在里面看到布局文件,string.xml等文件的内容。);
smail(是以.smail为后缀的类文件,可以在里面找到类的名字,类里面的字段,方法的名字以及方法的参数。);
AndroidMainfest.xml(清单文件);
apktool.yml(还不知此文件的作用)。共五个文件(或文件夹)。
二:反编译类文件(classes.dex):
第一步:从cmd进入dex2jar.bat所在的路径,输入命令:dex2jar.bat空格apk文件的全路径。
(可能会提示dex2jar.bat命令已经不推荐使用了,建议使用命令:d2j-dex2jar空格apk文件的全路径)
此时会在dex2jar.bat所在的路径生成以apk的名字加上"-dex2jar.jar"命名的文件(或者生成classes-dex2jar.jar文件,使用d2j-dex2jar.bat或者d2j-dex2jar命令时)。
第二步:双击打开jd-gui.exe文件,将上一步生成的文件拖到这里来,就可以看到java类文件了,可以将此文件保存成zip格式的存起来。
三:结果分析:
例子中只有一个MainActivity.java文件,反编译后,可以看到生成的zip 文件里有两个文件夹,一个是名为android的文件夹,一个是以工程名命名的文件夹。在工程文件夹里就是我们需要的类。我在这里只写了一个MainActivity.java类,在生成的文件夹里共有三个类,分别是BuildConfig.java,MainActivity.java,R.java文件。在MainActivity.java中的id值都换成了R.java中的常数了。


反编译淘宝的Android客户端时出现了以下的提示,反编译失败!原因不明!



G:\fanbianyi\反编译工具>apktool d 600120_taobao_android_3.9.2_UC.apk
I: Baksmaling...
Exception in thread "main" org.jf.dexlib.Util.ExceptionWithContext: Index: 28641
7133, Size: 7909
        at org.jf.dexlib.Util.ExceptionWithContext.withContext(ExceptionWithCont
ext.java:54)
        at org.jf.dexlib.IndexedSection.getItemByIndex(IndexedSection.java:77)
        at org.jf.dexlib.Code.InstructionWithReference.lookupReferencedItem(Inst
ructionWithReference.java:85)
        at org.jf.dexlib.Code.InstructionWithReference.<init>(InstructionWithRef
erence.java:57)
        at org.jf.dexlib.Code.Format.InstructionWithJumboReference.<init>(Instru
ctionWithJumboReference.java:51)
        at org.jf.dexlib.Code.Format.Instruction52c.<init>(Instruction52c.java:6
3)
        at org.jf.dexlib.Code.Format.Instruction52c.<init>(Instruction52c.java:4
2)
        at org.jf.dexlib.Code.Format.Instruction52c$Factory.makeInstruction(Inst
ruction52c.java:91)
        at org.jf.dexlib.Code.InstructionIterator.IterateInstructions(Instructio
nIterator.java:82)
        at org.jf.dexlib.CodeItem.readItem(CodeItem.java:154)
        at org.jf.dexlib.Item.readFrom(Item.java:77)
        at org.jf.dexlib.OffsettedSection.readItems(OffsettedSection.java:48)
        at org.jf.dexlib.Section.readFrom(Section.java:143)
        at org.jf.dexlib.DexFile.<init>(DexFile.java:431)
        at org.jf.dexlib.DexFile.<init>(DexFile.java:267)
        at brut.androlib.src.SmaliDecoder.decode(SmaliDecoder.java:49)
        at brut.androlib.src.SmaliDecoder.decode(SmaliDecoder.java:34)
        at brut.androlib.Androlib.decodeSourcesSmali(Androlib.java:74)
        at brut.androlib.ApkDecoder.decode(ApkDecoder.java:89)
        at brut.apktool.Main.cmdDecode(Main.java:146)
        at brut.apktool.Main.main(Main.java:77)
Caused by: java.lang.IndexOutOfBoundsException: Index: 286417133, Size: 7909
        at java.util.ArrayList.rangeCheck(ArrayList.java:604)
        at java.util.ArrayList.get(ArrayList.java:382)
        at org.jf.dexlib.IndexedSection.getItemByIndex(IndexedSection.java:75)
         ... 19 more
Error occured while retrieving the type_id_item item at index 286417133
Error occured at code address 0
code_item @0x13aae0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值