diff --git a/dex-translator/src/main/java/com/googlecode/dex2jar/v3/V3CodeAdapter.java b/dex-translator/src/main/java/com/googlecode/dex2jar/v3/V3CodeAdapter.java index cf05a065..b82355f6 100644 --- a/dex-translator/src/main/java/com/googlecode/dex2jar/v3/V3CodeAdapter.java +++ b/dex-translator/src/main/java/com/googlecode/dex2jar/v3/V3CodeAdapter.java @@ -75,6 +75,7 @@ import static com.googlecode.dex2jar.ir.stmt.Stmts.nUnLock; import java.util.Arrays; +import com.googlecode.dex2jar.ir.stmt.Stmts; import org.objectweb.asm.Label; import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; @@ -148,7 +149,10 @@ public class V3CodeAdapter implements DexCodeVisitor, Opcodes, DexOpcodes { } for (int i = 0; i < locals.length; i++) { if (locals[i] == null) { - locals[i] = nLocal("a" + i); + Local local = nLocal("a" + i); + locals[i] = local; + // simple fix for issue 219, init all tmp register to 0 at the start of insn. + list.add(Stmts.nAssign(local, nInt(0))); } } } diff --git a/dex-translator/src/test/java/com/googlecode/dex2jar/test/UnInitRegisterTest.java b/dex-translator/src/test/java/com/googlecode/dex2jar/test/UnInitRegisterTest.java new file mode 100644 index 00000000..e530f057 --- /dev/null +++ b/dex-translator/src/test/java/com/googlecode/dex2jar/test/UnInitRegisterTest.java @@ -0,0 +1,51 @@ +package com.googlecode.dex2jar.test; + +import com.googlecode.dex2jar.DexLabel; +import com.googlecode.dex2jar.Method; +import com.googlecode.dex2jar.visitors.DexClassVisitor; +import com.googlecode.dex2jar.visitors.DexCodeVisitor; +import com.googlecode.dex2jar.visitors.DexMethodVisitor; +import org.junit.Test; + +import static com.googlecode.dex2jar.DexOpcodes.*; + +public class UnInitRegisterTest { + public static void i219(DexClassVisitor cv) { + DexMethodVisitor mv = cv.visitMethod(ACC_PUBLIC | ACC_STATIC, new Method("La;", "a", + new String[] { "Ljava/lang/String;" }, "I")); + DexCodeVisitor code = mv.visitCode(); + + int v0 = 0; + int v1 = 1; + + code.visitArguments(2, new int[] { v1 }); + code.visitReturnStmt(OP_RETURN, v0, TYPE_INT); + code.visitEnd(); + mv.visitEnd(); + } + + public static void i220(DexClassVisitor cv) { + DexMethodVisitor mv = cv.visitMethod(ACC_PUBLIC, new Method("La;", "a", new String[] {}, "Ljava/lang/String;")); + DexCodeVisitor code = mv.visitCode(); + + int v0 = 0; + int v1 = 1; + int v2 = 2; + int v6 = 6; + + DexLabel L6 = new DexLabel(); + code.visitArguments(7, new int[] { v6 }); + code.visitJumpStmt(OP_IF_EQZ, v1, L6); + code.visitMoveStmt(OP_MOVE, v0, v6); + code.visitLabel(L6); + code.visitReturnStmt(OP_RETURN, v2, TYPE_OBJECT); + code.visitEnd(); + mv.visitEnd(); + } + + @Test + public void test() throws Exception { + TestUtils.testDexASMifier(getClass(), "i219"); + TestUtils.testDexASMifier(getClass(), "i220"); + } +}