Android逆向分析之dex2jar异常处理

分析一个APK,发现APK反编译正常,能得到所有smali代码和xml文件,

接着使用dex2jar想把dex转抱成jar包,使逆向分析看起来更加方便,但是却出现了如下异常:

<span style="color:#ff0000;">com.googlecode.dex2jar.DexException: while accept method:[La/a/a;.bc()Ljava/lang/String;]</span>
	at com.googlecode.dex2jar.reader.DexFileReader.acceptMethod(DexFileReader.java:694)
	at com.googlecode.dex2jar.reader.DexFileReader.acceptClass(DexFileReader.java:441)
	at com.googlecode.dex2jar.reader.DexFileReader.accept(DexFileReader.java:323)
	at com.googlecode.dex2jar.v3.Dex2jar.doTranslate(Dex2jar.java:85)
	at com.googlecode.dex2jar.v3.Dex2jar.to(Dex2jar.java:261)
	at com.googlecode.dex2jar.v3.Dex2jar.to(Dex2jar.java:252)
	at com.googlecode.dex2jar.v3.Main.doData(Main.java:43)
	at com.googlecode.dex2jar.v3.Main.doData(Main.java:35)
	at com.googlecode.dex2jar.v3.Main.doFile(Main.java:63)
	at com.googlecode.dex2jar.v3.Main.main(Main.java:86)
Caused by: com.googlecode.dex2jar.DexException: while accept code in method:[La/a/a;.bc()Ljava/lang/String;]
	at com.googlecode.dex2jar.reader.DexFileReader.acceptMethod(DexFileReader.java:684)
	... 9 more
Caused by: java.lang.IllegalArgumentException: Id out of bound
	at com.googlecode.dex2jar.reader.DexFileReader.getType(DexFileReader.java:556)
	at com.googlecode.dex2jar.reader.DexOpcodeAdapter.x2c(DexOpcodeAdapter.java:356)
	at com.googlecode.dex2jar.reader.DexCodeReader.acceptInsn(DexCodeReader.java:656)
	at com.googlecode.dex2jar.reader.DexCodeReader.accept(DexCodeReader.java:337)
	at com.googlecode.dex2jar.reader.DexFileReader.acceptMethod(DexFileReader.java:682)
	... 9 more

看起来都是google.code.dex2jar工具代码异常,但是我们仔细看第一行提示信息:

com.googlecode.dex2jar.DexException: while accept method:[La/a/a;.bc()Ljava/lang/String;]
这下大家清楚了,dex2jar在处理a.a.a.bc这个函数时,出错了,既然smali语言可以看到,那么我们打开smali的a.bc

# virtual methods
.method public bc()Ljava/lang/String;
    .locals 6

    .prologue
    .line 5
   #unknown opcode: 0xff
    nop

    :cond_0
    if-le v1, v4, :cond_0

    .line 6
    .local v2, "cca":Ljava/lang/String;
    const/4 v1, 0x1

    .line 7
    .local v1, "ba":Z
    if-eqz v1, :cond_1

    .line 8
    const/4 v0, 0x0

    .line 10
    .local v0, "ace":[B
    :try_start_0
    const-string/jumbo v4, "CaDNmeeag"

    invoke-virtual {v4}, Ljava/lang/String;->getBytes()[B
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v0

    .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代码了,

逆向分析有了更加直接的参考代码。大家如果遇到此类解析出错了,不防尝试此方法。


你可能感兴趣的:(Android逆向分析之dex2jar异常处理)