Skip to content

Commit

Permalink
Merge remote-tracking branch 'Kyson/feature/line_number' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ThexXTURBOXx committed Dec 13, 2021
2 parents e99e3ad + dc542ea commit f989473
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
34 changes: 22 additions & 12 deletions dex-ir/src/main/java/com/googlecode/dex2jar/ir/ts/CleanLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,32 @@ public class CleanLabel implements Transformer {

@Override
public void transform(IrMethod irMethod) {
Set<LabelStmt> uselabels = new HashSet<>();
addTrap(irMethod.traps, uselabels);
addVars(irMethod.vars, uselabels);
addStmt(irMethod.stmts, uselabels);
Set<LabelStmt> useLabels = new HashSet<>();
addTrap(irMethod.traps, useLabels);
addVars(irMethod.vars, useLabels);
addStmt(irMethod.stmts, useLabels);
if (irMethod.phiLabels != null) {
uselabels.addAll(irMethod.phiLabels);
useLabels.addAll(irMethod.phiLabels);
}
rmUnused(irMethod.stmts, uselabels);
addLineNumber(irMethod.stmts, useLabels);
rmUnused(irMethod.stmts, useLabels);
}

private void addVars(List<LocalVar> vars, Set<LabelStmt> uselabels) {
private void addVars(List<LocalVar> vars, Set<LabelStmt> useLabels) {
if (vars != null) {
for (LocalVar var : vars) {
uselabels.add(var.start);
uselabels.add(var.end);
useLabels.add(var.start);
useLabels.add(var.end);
}
}

}

private void rmUnused(StmtList stmts, Set<LabelStmt> uselabels) {
private void rmUnused(StmtList stmts, Set<LabelStmt> useLabels) {
Stmt p = stmts.getFirst();
while (p != null) {
if (p.st == ST.LABEL) {
if (!uselabels.contains(p)) {
if (p instanceof LabelStmt && p.st == ST.LABEL) {
if (!useLabels.contains(p)) {
Stmt q = p.getNext();
stmts.remove(p);
p = q;
Expand Down Expand Up @@ -80,4 +81,13 @@ private void addTrap(List<Trap> traps, Set<LabelStmt> labels) {
}
}

// fix https://github.com/pxb1988/dex2jar/issues/165
private void addLineNumber(StmtList stmts, Set<LabelStmt> useLabels) {
for (Stmt p = stmts.getFirst(); p != null; p = p.getNext()) {
if (p instanceof LabelStmt && ((LabelStmt) p).lineNumber != -1) {
useLabels.add((LabelStmt) p);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.googlecode.d2j.Field;
import com.googlecode.d2j.Method;
import com.googlecode.d2j.node.DexCodeNode;
import com.googlecode.d2j.node.DexDebugNode;
import com.googlecode.d2j.node.TryCatchNode;
import com.googlecode.d2j.node.analysis.DvmFrame;
import com.googlecode.d2j.node.analysis.DvmInterpreter;
Expand Down Expand Up @@ -188,7 +189,6 @@ public IrMethod convert(boolean isStatic, Method method, DexCodeNode dexCodeNode

dfs(exBranch, handlers, access, interpreter);


StmtList stmts = target.stmts;
stmts.addAll(preEmit);
for (int i = 0; i < insnList.size(); i++) {
Expand Down Expand Up @@ -260,9 +260,30 @@ public IrMethod convert(boolean isStatic, Method method, DexCodeNode dexCodeNode
target.phiLabels = phiLabels;
}

supplementLineNumber(dexCodeNode);

return target;
}

// fix https://github.com/pxb1988/dex2jar/issues/165
private void supplementLineNumber(DexCodeNode dexCodeNode) {
if (dexCodeNode == null || dexCodeNode.debugNode == null || dexCodeNode.debugNode.debugNodes == null) {
return;
}
Map<DexLabel, Integer> lineNumber = new HashMap<>();
for (DexDebugNode.DexDebugOpNode debugNode : dexCodeNode.debugNode.debugNodes) {
if (debugNode instanceof DexDebugNode.DexDebugOpNode.LineNumber) {
lineNumber.put(debugNode.label, ((DexDebugNode.DexDebugOpNode.LineNumber) debugNode).line);
}
}
for (Map.Entry<DexLabel, LabelStmt> entry : map.entrySet()) {
Integer line = lineNumber.get(entry.getKey());
if (line != null) {
entry.getValue().lineNumber = line;
}
}
}

/**
* issue 63
* <pre>
Expand Down

0 comments on commit f989473

Please sign in to comment.