Annotate variables in catch statements with @Pc

master
Graham 4 years ago
parent d2718bd7b0
commit 1526cea2a5
  1. 4
      src/org/jetbrains/java/decompiler/code/cfg/ControlFlowGraph.java
  2. 8
      src/org/jetbrains/java/decompiler/code/cfg/ExceptionRangeCFG.java
  3. 2
      src/org/jetbrains/java/decompiler/modules/decompiler/DomHelper.java
  4. 8
      src/org/jetbrains/java/decompiler/modules/decompiler/StatEdge.java
  5. 2
      src/org/jetbrains/java/decompiler/modules/decompiler/deobfuscator/ExceptionDeobfuscator.java
  6. 13
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchAllStatement.java
  7. 4
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/CatchStatement.java
  8. 2
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/Statement.java

@ -358,7 +358,7 @@ public class ControlFlowGraph implements CodeConstants {
block.addSuccessorException(handle);
}
ExceptionRangeCFG range = new ExceptionRangeCFG(protectedRange, handle, handler.exceptionClass == null
ExceptionRangeCFG range = new ExceptionRangeCFG(protectedRange, handle, handler.handler, handler.exceptionClass == null
? null
: Collections.singletonList(handler.exceptionClass));
mapRanges.put(key, range);
@ -654,7 +654,7 @@ public class ControlFlowGraph implements CodeConstants {
if (setBoth.size() == lstRange.size()) {
lstNewRange = new ArrayList<>();
ExceptionRangeCFG newRange = new ExceptionRangeCFG(lstNewRange,
mapNewNodes.get(range.getHandler().id), range.getExceptionTypes());
mapNewNodes.get(range.getHandler().id), range.getHandlerBytecodeOffset(), range.getExceptionTypes());
exceptions.add(newRange);
}
else {

@ -10,11 +10,13 @@ import java.util.stream.Collectors;
public class ExceptionRangeCFG {
private final List<BasicBlock> protectedRange; // FIXME: replace with set
private BasicBlock handler;
private int handlerBytecodeOffset;
private List<String> exceptionTypes;
public ExceptionRangeCFG(List<BasicBlock> protectedRange, BasicBlock handler, List<String> exceptionType) {
public ExceptionRangeCFG(List<BasicBlock> protectedRange, BasicBlock handler, int handlerBytecodeOffset, List<String> exceptionType) {
this.protectedRange = protectedRange;
this.handler = handler;
this.handlerBytecodeOffset = handlerBytecodeOffset;
if (exceptionType != null) {
this.exceptionTypes = new ArrayList<>(exceptionType);
@ -54,6 +56,10 @@ public class ExceptionRangeCFG {
this.handler = handler;
}
public int getHandlerBytecodeOffset() {
return handlerBytecodeOffset;
}
public List<BasicBlock> getProtectedRange() {
return protectedRange;
}

@ -77,7 +77,7 @@ public class DomHelper {
ExceptionRangeCFG range = graph.getExceptionRange(succex, block);
if (!range.isCircular()) {
stat.addSuccessor(new StatEdge(stat, stsuccex, range.getExceptionTypes()));
stat.addSuccessor(new StatEdge(stat, stsuccex, range.getHandlerBytecodeOffset(), range.getExceptionTypes()));
}
}
}

@ -26,6 +26,7 @@ public class StatEdge {
private Statement source;
private Statement destination;
private int destinationBytecodeOffset = -1;
private List<String> exceptions;
@ -46,8 +47,9 @@ public class StatEdge {
this.destination = destination;
}
public StatEdge(Statement source, Statement destination, List<String> exceptions) {
public StatEdge(Statement source, Statement destination, int destinationBytecodeOffset, List<String> exceptions) {
this(TYPE_EXCEPTION, source, destination);
this.destinationBytecodeOffset = destinationBytecodeOffset;
if (exceptions != null) {
this.exceptions = new ArrayList<>(exceptions);
}
@ -77,6 +79,10 @@ public class StatEdge {
this.destination = destination;
}
public int getDestinationBytecodeOffset() {
return destinationBytecodeOffset;
}
public List<String> getExceptions() {
return this.exceptions;
}

@ -376,7 +376,7 @@ public class ExceptionDeobfuscator {
List<BasicBlock> lstSubrangeBlocks = getReachableBlocksRestricted(entry, range, engine);
if (!lstSubrangeBlocks.isEmpty() && lstSubrangeBlocks.size() < range.getProtectedRange().size()) {
// add new range
ExceptionRangeCFG subRange = new ExceptionRangeCFG(lstSubrangeBlocks, range.getHandler(), range.getExceptionTypes());
ExceptionRangeCFG subRange = new ExceptionRangeCFG(lstSubrangeBlocks, range.getHandler(), range.getHandlerBytecodeOffset(), range.getExceptionTypes());
graph.getExceptions().add(subRange);
// shrink the original range
range.getProtectedRange().removeAll(lstSubrangeBlocks);

@ -53,9 +53,16 @@ public class CatchAllStatement extends Statement {
}
}
int bytecodeOffset = -1;
for (StatEdge edge : head.getSuccessorEdges(StatEdge.TYPE_EXCEPTION)) {
if (edge.getDestination() == handler) {
bytecodeOffset = edge.getDestinationBytecodeOffset();
}
}
vars.add(new VarExprent(DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.VAR_COUNTER),
new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/Throwable"),
DecompilerContext.getVarProcessor()));
DecompilerContext.getVarProcessor(), -1, bytecodeOffset));
}
@ -165,13 +172,13 @@ public class CatchAllStatement extends Statement {
if (this.monitor != null) {
cas.monitor = new VarExprent(DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.VAR_COUNTER),
VarType.VARTYPE_INT,
DecompilerContext.getVarProcessor());
DecompilerContext.getVarProcessor(), -1, -1);
}
if (!this.vars.isEmpty()) {
cas.vars.add(new VarExprent(DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.VAR_COUNTER),
new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/Throwable"),
DecompilerContext.getVarProcessor()));
DecompilerContext.getVarProcessor(), -1, this.vars.get(0).getBytecodeOffset()));
}
return cas;

@ -45,7 +45,7 @@ public class CatchStatement extends Statement {
vars.add(new VarExprent(DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.VAR_COUNTER),
new VarType(CodeConstants.TYPE_OBJECT, 0, edge.getExceptions().get(0)),
// FIXME: for now simply the first type. Should get the first common superclass when possible.
DecompilerContext.getVarProcessor()));
DecompilerContext.getVarProcessor(), -1, edge.getDestinationBytecodeOffset()));
}
}
@ -187,7 +187,7 @@ public class CatchStatement extends Statement {
cs.exctstrings.add(new ArrayList<>(exc));
cs.vars.add(new VarExprent(DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.VAR_COUNTER),
new VarType(CodeConstants.TYPE_OBJECT, 0, exc.get(0)),
DecompilerContext.getVarProcessor()));
DecompilerContext.getVarProcessor(), -1, this.vars.get(0).getBytecodeOffset()));
}
return cs;

@ -184,7 +184,7 @@ public class Statement implements IMatchable {
if (setHandlers.contains(handler)) {
if (!setNodes.containsKey(handler.id)) {
stat.addSuccessor(new StatEdge(stat, handler, edge.getExceptions()));
stat.addSuccessor(new StatEdge(stat, handler, edge.getDestinationBytecodeOffset(), edge.getExceptions()));
}
}
}

Loading…
Cancel
Save