Skip to content

Commit

Permalink
Add comments to decompiled code and remove logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskarth committed Aug 20, 2024
1 parent c80be61 commit af7f656
Show file tree
Hide file tree
Showing 5 changed files with 259 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public interface IFernflowerPreferences {
String VERIFY_VARIABLE_MERGES = "verify-merges";

@Name("[Experimental] Use old try deduplication")
@Description("Uses the older try deduplication algorithm for methods with obfuscated exceptions, which prefers ")
@Description("Use the old try deduplication algorithm for methods with obfuscated exceptions, which inserts dummy exception handlers instead of duplicating blocks")
@Type(DecompilerOption.Type.BOOLEAN)
String OLD_TRY_DEDUP = "old-try-dedup";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ public static RootStatement codeToJava(StructClass cl, StructMethod mt, MethodDe
DecompilerContext.getCounterContainer().setCounter(CounterContainer.VAR_COUNTER, mt.getLocalVariables());

if (ExceptionDeobfuscator.hasObfuscatedExceptions(graph)) {
DecompilerContext.getLogger().writeMessage("Heavily obfuscated exception ranges found!", IFernflowerLogger.Severity.WARN);
DotExporter.toDotFile(graph, mt, "cfgExceptionsPre", true);

if (!ExceptionDeobfuscator.handleMultipleEntryExceptionRanges(graph)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.jetbrains.java.decompiler.modules.decompiler.decompose.GenericDominatorEngine;
import org.jetbrains.java.decompiler.modules.decompiler.decompose.IGraph;
import org.jetbrains.java.decompiler.modules.decompiler.decompose.IGraphNode;
import org.jetbrains.java.decompiler.struct.StructClass;
import org.jetbrains.java.decompiler.util.InterpreterUtil;

import java.util.*;
Expand Down Expand Up @@ -441,7 +442,9 @@ public static void insertDummyExceptionHandlerBlocks(ControlFlowGraph graph, Byt
}
}

// TODO: write comment if not matchexception
if (!isMatchException(handler)) {
graph.addComment("$VF: Duplicated exception handlers to handle obfuscated exceptions");
}

} else {
for (ExceptionRangeCFG range : ranges) {
Expand Down Expand Up @@ -487,4 +490,20 @@ public static void insertDummyExceptionHandlerBlocks(ControlFlowGraph graph, Byt
}
}
}
}

private static boolean isMatchException(BasicBlock block) {
StructClass cl = DecompilerContext.getContextProperty(DecompilerContext.CURRENT_CLASS);

// Check if block has any "new MatchException;"
for (Instruction instr : block.getSeq()) {
if (instr.opcode == CodeConstants.opc_new) {
if ("java/lang/MatchException".equals(cl.getPool().getPrimitiveConstant(instr.operand(0)).getString())) {
return true;

}
}
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ public boolean equals(Object o) {
this.isArray == cn.isArray &&
this.value.equals(cn.value);
}
}
}
Loading

0 comments on commit af7f656

Please sign in to comment.