NullPointerException occurs when converting a simple dex into a jar. The issue is 100% reproducible.
Steps to reproduce.
d2j-dex2jar.sh classes.dex
What is the exact smali/baksmali command that you ran?
Custom built. I downloaded the source code from the 2.x branch today (2015-04-13) and compiled it. The build was successful and all the tests were passed.
For your reference:
version: reader-2.1-SNAPSHOT, translator-2.1-SNAPSHOT, ir-2.1-SNAPSHOT
For the Java compiler, I am using OpenJDK 7.
$ javac -version
javac 1.7.0_65
$ java -version
java version "1.7.0_65"
OpenJDK Runtime Environment (IcedTea 2.5.3) (7u71-2.5.3-0ubuntu0.12.04.1)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
error log:
LTest;.compare(LTest;LTest;)I
java.lang.RuntimeException: fail exe return a4
at com.googlecode.dex2jar.ir.ts.an.BaseAnalyze.exec(BaseAnalyze.java:93)
at com.googlecode.dex2jar.ir.ts.an.BaseAnalyze.exec(BaseAnalyze.java:1)
at com.googlecode.dex2jar.ir.ts.Cfg.dfs(Cfg.java:255)
at com.googlecode.dex2jar.ir.ts.an.BaseAnalyze.analyze0(BaseAnalyze.java:75)
at com.googlecode.dex2jar.ir.ts.an.BaseAnalyze.analyze(BaseAnalyze.java:69)
at com.googlecode.dex2jar.ir.ts.UnSSATransformer.transform(UnSSATransformer.java:274)
at com.googlecode.d2j.dex.Dex2jar$2.optimize(Dex2jar.java:161)
at com.googlecode.d2j.dex.Dex2Asm.convertCode(Dex2Asm.java:433)
at com.googlecode.d2j.dex.ExDex2Asm.convertCode(ExDex2Asm.java:42)
at com.googlecode.d2j.dex.Dex2jar$2.convertCode(Dex2jar.java:128)
at com.googlecode.d2j.dex.Dex2Asm.convertMethod(Dex2Asm.java:528)
at com.googlecode.d2j.dex.Dex2Asm.convertClass(Dex2Asm.java:425)
at com.googlecode.d2j.dex.Dex2Asm.convertDex(Dex2Asm.java:441)
at com.googlecode.d2j.dex.Dex2jar.doTranslate(Dex2jar.java:170)
at com.googlecode.d2j.dex.Dex2jar.to(Dex2jar.java:270)
at com.googlecode.dex2jar.tools.Dex2jarCmd.doCommandLine(Dex2jarCmd.java:108)
at com.googlecode.dex2jar.tools.BaseCmd.doMain(BaseCmd.java:290)
at com.googlecode.dex2jar.tools.Dex2jarCmd.main(Dex2jarCmd.java:32)
Caused by: java.lang.NullPointerException
at com.googlecode.dex2jar.ir.ts.UnSSATransformer$LiveA.onUseLocal(UnSSATransformer.java:552)
at com.googlecode.dex2jar.ir.ts.UnSSATransformer$LiveA.onUseLocal(UnSSATransformer.java:1)
at com.googlecode.dex2jar.ir.ts.an.BaseAnalyze.onUse(BaseAnalyze.java:173)
at com.googlecode.dex2jar.ir.ts.an.BaseAnalyze.onUse(BaseAnalyze.java:1)
at com.googlecode.dex2jar.ir.ts.Cfg.travel(Cfg.java:331)
at com.googlecode.dex2jar.ir.ts.Cfg.travel(Cfg.java:382)
at com.googlecode.dex2jar.ir.ts.an.BaseAnalyze.exec(BaseAnalyze.java:90)
... 17 more
.method public compare(LTest;LTest;)I
.registers 7
const/4 v1, 1
const/4 v0, -1
iget v2, p1, LTest;->x:I
iget v3, p2, LTest;->x:I
if-ge v2, v3, :L1
:L0
return v0
:L1
iget v2, p1, LTest;->x:I
iget v3, p2, LTest;->y:I
if-le v2, v3, :L2
move v0, v1
goto :L0
:L2
iget v2, p1, LTest;->y:I
iget v3, p2, LTest;->y:I
if-lt v2, v3, :L0
iget v0, p1, LTest;->y:I
iget v2, p2, LTest;->y:I
if-le v0, v2, :L3
move v0, v1
goto :L0
:L3
const/4 v0, 0
goto :L0
.end method
This issue is fixed by rev 6fec94.
Please pull the last source and test again.
sorry for the inconvenient.
Thank you for the info. When I reset to the rev 6fec94, the problem does not occur.
However, 6fec94 is NOT the latest version. Three more commits were uploaded after 6fec94:
[90d851] (2.x, tip) by Bob Pan Bob Pan
extra indent for smali opcode
2015-04-13 13:48:37 Tree
[936811] by Bob Pan Bob Pan
implement dex weaver
2015-04-13 12:39:05 Tree
[74c27a] by Bob Pan Bob Pan
support 'invoke-x/range {}, ...'
2015-04-13 12:25:58 Tree
When I download the three more commits, the problem occurs again.
Furthermore, when I use the 6fec94 revision for converting dex file for the Android framework, following error occurred. I am attaching m-0.txt file.
Related
Commit: [74c27a]
Commit: [90d851]
Commit: [936811]
When I download the three more commits, the problem occurs again.
It is strange,I can not reproduce the problem. Please cleanup before actual build.
for the attachemnt m-0.txt,
the problem is caused by strict type calculation, because in java syntaxt, a boolean can not assign to an inteager. so dex2jar forbid merge type Z and I. It is simple to fix
A. modify the dex by hand and add the following code
B. modify the dex2jar code. return TypeClass.INT when merge int and boolean at com.googlecode.dex2jar.ir.TypeClass.merge(TypeClass.java:100)
Last edit: Bob Pan 2015-04-14
Ah, that was my mistake. As you suggested, building after cleaning up magically solved the problem. Thanks!
For the int/boolean merge issue, I do understand dex2jar forbids it, but don't understand why java compiler and dex converter allows it. Using dexdump, I analyzed classes.dex and found that it is giving boolean result to integer argument. Do you think this is a bug in javac or dx tool?
Anyway, I modified TypeClass.java as you suggested and it works. Thank you.