经验:当apktool失败时,可以采用dextojar看下具体的情况。
分析某款Android软件时,dextojar(V0.0.9.15)出错,总结下:
1.无效语句
错误情况:
#unknown opcode: 0xff
com.googlecode.dex2jar.DexException: while accept method:[La/a/a;.bc()Ljava/lang/String;]
at com.googlecode.dex2jar.reader.DexFileReader.acceptMethod(DexFileReader.java:694)
解决方法:
删除掉无效语句
2.p83索引过大,造成的错误。
错误情况:
if-ltz p83, :cond_1
com.googlecode.dex2jar.DexException: while accept method:[La/a/a;.bc()Ljava/lang/String;]
at com.googlecode.dex2jar.reader.DexFileReader.acceptMethod(DexFileReader.java:694)
解决方法:
修正语句 if-ltz p0, :cond_1
3.返回值传的是.local变量
错误情况:
.local v1, "ba":Z
return-object v1
Error:La/a/a;.bc()Ljava/lang/String;->null
解决方法:
const-string v1,"ba"
return-object v1
4.未识别的参数说明
错误情况:
.param p0, "context" # Landroid/content/Context;
.annotation runtime Ljava/lang/Deprecated;
.end annotation
.end param
解决方法:
删除掉参数说明
.annotation runtime Ljava/lang/Deprecated;
.end annotation
.end param
转:http://blog.csdn.net/zhuobattle/article/details/38982891
分析一个APK,发现APK反编译正常,能得到所有smali代码和xml文件,
接着使用dex2jar想把dex转抱成jar包,使逆向分析看起来更加方便,但是却出现了如下异常:
01.com.googlecode.dex2jar.DexException: while accept method:[La/a/a;.bc()Ljava/lang/String;]
02. at com.googlecode.dex2jar.reader.DexFileReader.acceptMethod(DexFileReader.java:694)
03. at com.googlecode.dex2jar.reader.DexFileReader.acceptClass(DexFileReader.java:441)
04. at com.googlecode.dex2jar.reader.DexFileReader.accept(DexFileReader.java:323)
05. at com.googlecode.dex2jar.v3.Dex2jar.doTranslate(Dex2jar.java:85)
06. at com.googlecode.dex2jar.v3.Dex2jar.to(Dex2jar.java:261)
07. at com.googlecode.dex2jar.v3.Dex2jar.to(Dex2jar.java:252)
08. at com.googlecode.dex2jar.v3.Main.doData(Main.java:43)
09. at com.googlecode.dex2jar.v3.Main.doData(Main.java:35)
10. at com.googlecode.dex2jar.v3.Main.doFile(Main.java:63)
11. at com.googlecode.dex2jar.v3.Main.main(Main.java:86)
12.Caused by: com.googlecode.dex2jar.DexException: while accept code in method:[La/a/a;.bc()Ljava/lang/String;]
13. at com.googlecode.dex2jar.reader.DexFileReader.acceptMethod(DexFileReader.java:684)
14. ... 9 more
15.Caused by: java.lang.IllegalArgumentException: Id out of bound
16. at com.googlecode.dex2jar.reader.DexFileReader.getType(DexFileReader.java:556)
17. at com.googlecode.dex2jar.reader.DexOpcodeAdapter.x2c(DexOpcodeAdapter.java:356)
18. at com.googlecode.dex2jar.reader.DexCodeReader.acceptInsn(DexCodeReader.java:656)
19. at com.googlecode.dex2jar.reader.DexCodeReader.accept(DexCodeReader.java:337)
20. at com.googlecode.dex2jar.reader.DexFileReader.acceptMethod(DexFileReader.java:682)
21. ... 9 more
看起来都是google.code.dex2jar工具代码异常,但是我们仔细看第一行提示信息:
01.com.googlecode.dex2jar.DexException: while accept method:[La/a/a;.bc()Ljava/lang/String;]
这下大家清楚了,dex2jar在处理a.a.a.bc这个函数时,出错了,既然smali语言可以看到,那么我们打开smali的a.bc
01.# virtual methods
02..method public bc()Ljava/lang/String;
03. .locals 6
04.
05. .prologue
06. .line 5
07. #unknown opcode: 0xff
08. nop
09.
10. :cond_0
11. if-le v1, v4, :cond_0
12.
13. .line 6
14. .local v2, "cca":Ljava/lang/String;
15. const/4 v1, 0x1
16.
17. .line 7
18. .local v1, "ba":Z
19. if-eqz v1, :cond_1
20.
21. .line 8
22. const/4 v0, 0x0
23.
24. .line 10
25. .local v0, "ace":[B
26. :try_start_0
27. const-string/jumbo v4, "CaDNmeeag"
28.
29. invoke-virtual {v4}, Ljava/lang/String;->getBytes()[B
30. :try_end_0
31. .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0
32.
33. move-result-object v0
34.
35. .line 15
发现 第一行:
#unknown opcode: 0xff
哦,看来就是看雪上那个保护APK的方法,http://bbs.pediy.com/showthread.php?t=177114
插入了相应的无效代码,导致了dex2jar工具解析出错了,
1.接下来我把这句直接删除,
2.再把smali回编译成dex
3.再用dex2jar工具重新尝试,果然这下出来了正常的jar包,用jd-gui或者luten可以正常查看java代码了,
逆向分析有了更加直接的参考代码。大家如果遇到此类解析出错了,不防尝试此方法。
apktool.bat d "****.apk" -o "outdirpath"
1.删除无效代码,
2.再把smali回编译成dex
3.再用apktool.bat d -d "****.apk" -o "outdirpath"尝试。