diff --git a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/stmt/LabelStmt.java b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/stmt/LabelStmt.java index d641c121..2884eaad 100644 --- a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/stmt/LabelStmt.java +++ b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/stmt/LabelStmt.java @@ -33,6 +33,7 @@ public class LabelStmt extends E0Stmt { public String displayName; public Label label; + public int lineNumber = -1; public LabelStmt(Label label) { super(ST.LABEL); @@ -50,7 +51,11 @@ public class LabelStmt extends E0Stmt { @Override public String toString() { - return getDisplayName() + ":"; + if (lineNumber >= 0) { + return getDisplayName() + ": // line " + lineNumber; + } else { + return getDisplayName() + ":"; + } } } diff --git a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/stmt/LineNumStmt.java b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/stmt/LineNumStmt.java deleted file mode 100644 index 43bcdae2..00000000 --- a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/stmt/LineNumStmt.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.googlecode.dex2jar.ir.stmt; - -import java.util.Map; - -import com.googlecode.dex2jar.ir.stmt.Stmt.E0Stmt; - -public class LineNumStmt extends E0Stmt { - - public String displayName; - public LabelStmt label; - public int line; - - public LineNumStmt(int line, LabelStmt label) { - super(ST.LINENUMBER); - this.label = label; - this.line = line; - } - - @Override - public LineNumStmt clone(Map map) { - return new LineNumStmt(line, label.clone(map)); - } - - public String getDisplayName() { - return displayName == null ? label.toString() : displayName; - } - - @Override - public String toString() { - return label.getDisplayName() + " -> line " + line; - } - -} diff --git a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/stmt/Stmt.java b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/stmt/Stmt.java index 3490af60..c70b2322 100644 --- a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/stmt/Stmt.java +++ b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/stmt/Stmt.java @@ -100,8 +100,7 @@ public abstract class Stmt { public static enum ST { ASSIGN, GOTO, IDENTITY, IF, LABEL, LOCK, LOOKUP_SWITCH, // - NOP, RETURN, RETURN_VOID, TABLE_SWITCH, THROW, UNLOCK, - LINENUMBER, LOCALVARIABLE + NOP, RETURN, RETURN_VOID, TABLE_SWITCH, THROW, UNLOCK, LOCALVARIABLE } /** diff --git a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/stmt/Stmts.java b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/stmt/Stmts.java index 0033f22c..bd97e626 100644 --- a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/stmt/Stmts.java +++ b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/stmt/Stmts.java @@ -86,10 +86,6 @@ public final class Stmts { return new UnopStmt(ST.UNLOCK, box(op)); } - public static LineNumStmt nLineNum(int line, LabelStmt label) { - return new LineNumStmt(line, label); - } - public static LocVarStmt nLocVar(String name, String type, String signature, LabelStmt start, LabelStmt end, Value reg) { return new LocVarStmt(name, type, signature, start, end, box(reg)); diff --git a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/Cfg.java b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/Cfg.java index 7075eebc..7dbe136b 100644 --- a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/Cfg.java +++ b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/Cfg.java @@ -100,7 +100,6 @@ public class Cfg { public static boolean notThrow(Stmt s) { switch (s.st) { case LABEL: - case LINENUMBER: case LOCALVARIABLE: case RETURN: case RETURN_VOID: diff --git a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/EndRemover.java b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/EndRemover.java index 98282991..08d96f17 100644 --- a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/EndRemover.java +++ b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/EndRemover.java @@ -34,7 +34,6 @@ public class EndRemover implements Transformer { } break; case LABEL: - case LINENUMBER: case LOCALVARIABLE: case NOP: case UNLOCK: @@ -67,7 +66,6 @@ public class EndRemover implements Transformer { for (Stmt p = js.target.getNext(); !end; p = p.getNext()) { switch (p.st) { case LABEL: - case LINENUMBER: break; case GOTO: LabelStmt target = ((JumpStmt) p).target; diff --git a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/ExceptionHandlerCurrectTransformer.java b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/ExceptionHandlerCurrectTransformer.java index c4508169..e5f3c9a3 100644 --- a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/ExceptionHandlerCurrectTransformer.java +++ b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/ExceptionHandlerCurrectTransformer.java @@ -63,10 +63,10 @@ public class ExceptionHandlerCurrectTransformer implements Transformer { LabelStmt handler = t.handler; Stmt st = handler.getNext(); Stmt pre = handler.getPre(); - while (st.st == ST.LABEL || st.st == ST.LINENUMBER) { + while (st.st == ST.LABEL) { st = st.getNext(); } - while (pre.st == ST.LABEL || pre.st == ST.LINENUMBER) { + while (pre.st == ST.LABEL) { pre = pre.getPre(); } if (needInsertMoveExceptionRef(st) && needInsertGoto(pre)) { diff --git a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/InfoMove2Code.java b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/InfoMove2Code.java index d37a29ae..0552c7e7 100644 --- a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/InfoMove2Code.java +++ b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/InfoMove2Code.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.List; import com.googlecode.dex2jar.ir.IrMethod; -import com.googlecode.dex2jar.ir.stmt.LineNumStmt; import com.googlecode.dex2jar.ir.stmt.LocVarStmt; import com.googlecode.dex2jar.ir.stmt.Stmt; import com.googlecode.dex2jar.ir.stmt.Stmt.ST; @@ -19,7 +18,7 @@ public class InfoMove2Code implements Transformer { //Try to found all LOCALVARIABLE block and move them to the code before it's end label. //And all LINENUMBER block and move them after it's label for(Stmt st:stmts){ - if(st.st == ST.LOCALVARIABLE || st.st == ST.LINENUMBER){ + if(st.st == ST.LOCALVARIABLE){ lvs.add(st); } } @@ -43,7 +42,6 @@ public class InfoMove2Code implements Transformer { dist = dist.getPre(); break; case LABEL: - case LINENUMBER: if(skip){//SKIP EMPTY LINE dist = dist.getPre(); }else{ @@ -57,8 +55,6 @@ public class InfoMove2Code implements Transformer { break; } } - } else if(st.st == ST.LINENUMBER){ - dist = ((LineNumStmt)st).label; } if(dist != null){ stmts.move(st, st, dist); diff --git a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/LocalRemove.java b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/LocalRemove.java index 941a631d..4e823d76 100644 --- a/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/LocalRemove.java +++ b/dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/LocalRemove.java @@ -253,7 +253,6 @@ public class LocalRemove implements Transformer { switch (st.st) { case RETURN_VOID: case LABEL: - case LINENUMBER: case LOCALVARIABLE: case GOTO: case NOP: diff --git a/dex-translator/src/main/java/com/googlecode/dex2jar/v3/IrMethod2AsmMethod.java b/dex-translator/src/main/java/com/googlecode/dex2jar/v3/IrMethod2AsmMethod.java index 78d65acd..b82dd36b 100644 --- a/dex-translator/src/main/java/com/googlecode/dex2jar/v3/IrMethod2AsmMethod.java +++ b/dex-translator/src/main/java/com/googlecode/dex2jar/v3/IrMethod2AsmMethod.java @@ -33,14 +33,13 @@ import com.googlecode.dex2jar.ir.expr.TypeExpr; import com.googlecode.dex2jar.ir.stmt.AssignStmt; import com.googlecode.dex2jar.ir.stmt.JumpStmt; import com.googlecode.dex2jar.ir.stmt.LabelStmt; -import com.googlecode.dex2jar.ir.stmt.LineNumStmt; +import com.googlecode.dex2jar.ir.stmt.LocVarStmt; import com.googlecode.dex2jar.ir.stmt.LookupSwitchStmt; import com.googlecode.dex2jar.ir.stmt.Stmt; import com.googlecode.dex2jar.ir.stmt.Stmt.E2Stmt; import com.googlecode.dex2jar.ir.stmt.Stmt.ST; import com.googlecode.dex2jar.ir.stmt.TableSwitchStmt; import com.googlecode.dex2jar.ir.stmt.UnopStmt; -import com.googlecode.dex2jar.ir.stmt.LocVarStmt; import com.googlecode.dex2jar.ir.ts.Cfg; import com.googlecode.dex2jar.ir.ts.Cfg.StmtVisitor; import com.googlecode.dex2jar.ir.ts.LiveAnalyze; @@ -350,31 +349,33 @@ public class IrMethod2AsmMethod implements Opcodes { : trap.type.getInternalName()); } } + private void reIndexStmts(IrMethod ir) { int count = 0; for (Stmt st : ir.stmts) { st.id = count; - count ++; + count++; } } + private void reBuildInstructions(IrMethod ir, MethodVisitor asm) { for (Stmt st : ir.stmts) { switch (st.st) { case LABEL: - asm.visitLabel(((LabelStmt) st).label); - break; - case LINENUMBER: - LineNumStmt ls = (LineNumStmt) st; - asm.visitLineNumber(ls.line, ls.label.label); + LabelStmt labelStmt = (LabelStmt) st; + asm.visitLabel(labelStmt.label); + if (labelStmt.lineNumber >= 0) { + asm.visitLineNumber(labelStmt.lineNumber, labelStmt.label); + } break; case LOCALVARIABLE: LocVarStmt vs = (LocVarStmt) st; - if(vs.start.id <= vs.end.id){ - asm.visitLocalVariable(vs.name, vs.type, - vs.signature, vs.start.label, vs.end.label, ((Local)vs.op.value)._ls_index); - }else{ - asm.visitLocalVariable(vs.name, vs.type, - vs.signature, vs.end.label, vs.start.label, ((Local)vs.op.value)._ls_index); + if (vs.start.id <= vs.end.id) { + asm.visitLocalVariable(vs.name, vs.type, vs.signature, vs.start.label, vs.end.label, + ((Local) vs.op.value)._ls_index); + } else { + asm.visitLocalVariable(vs.name, vs.type, vs.signature, vs.end.label, vs.start.label, + ((Local) vs.op.value)._ls_index); } break; case ASSIGN: { 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 9c9bec49..57388610 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 @@ -64,6 +64,7 @@ import static com.googlecode.dex2jar.ir.stmt.Stmts.nAssign; import static com.googlecode.dex2jar.ir.stmt.Stmts.nGoto; import static com.googlecode.dex2jar.ir.stmt.Stmts.nIdentity; import static com.googlecode.dex2jar.ir.stmt.Stmts.nIf; +import static com.googlecode.dex2jar.ir.stmt.Stmts.nLocVar; import static com.googlecode.dex2jar.ir.stmt.Stmts.nLock; import static com.googlecode.dex2jar.ir.stmt.Stmts.nLookupSwitch; import static com.googlecode.dex2jar.ir.stmt.Stmts.nReturn; @@ -71,8 +72,6 @@ import static com.googlecode.dex2jar.ir.stmt.Stmts.nReturnVoid; import static com.googlecode.dex2jar.ir.stmt.Stmts.nTableSwitch; import static com.googlecode.dex2jar.ir.stmt.Stmts.nThrow; import static com.googlecode.dex2jar.ir.stmt.Stmts.nUnLock; -import static com.googlecode.dex2jar.ir.stmt.Stmts.nLocVar; -import static com.googlecode.dex2jar.ir.stmt.Stmts.nLineNum; import java.util.Arrays; @@ -645,7 +644,7 @@ public class V3CodeAdapter implements DexCodeVisitor, Opcodes, DexOpcodes { @Override public void visitLineNumber(int line, DexLabel label) { - list.add(nLineNum(line, toLabelStmt(label))); + toLabelStmt(label).lineNumber = line; } @Override diff --git a/dex-translator/src/test/java/com/googlecode/dex2jar/test/V3Test.java b/dex-translator/src/test/java/com/googlecode/dex2jar/test/V3Test.java index c0072403..33edee3b 100644 --- a/dex-translator/src/test/java/com/googlecode/dex2jar/test/V3Test.java +++ b/dex-translator/src/test/java/com/googlecode/dex2jar/test/V3Test.java @@ -97,7 +97,7 @@ public class V3Test { } }; } - }), DexFileReader.SKIP_DEBUG); + }), 0); System.out.flush(); System.out.println(); if (exes.size() > 0) {