|
|
|
@ -31,32 +31,32 @@ import org.jetbrains.java.decompiler.struct.StructMethod; |
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
|
|
public class MethodProcessorThread implements Runnable { |
|
|
|
|
public class MethodProcessorRunnable implements Runnable { |
|
|
|
|
|
|
|
|
|
public final Object lock = new Object(); |
|
|
|
|
|
|
|
|
|
private final StructMethod method; |
|
|
|
|
private final VarProcessor varproc; |
|
|
|
|
private final VarProcessor varProc; |
|
|
|
|
private final DecompilerContext parentContext; |
|
|
|
|
|
|
|
|
|
private volatile RootStatement root; |
|
|
|
|
private volatile Throwable error; |
|
|
|
|
|
|
|
|
|
public MethodProcessorThread(StructMethod method, VarProcessor varproc, DecompilerContext parentContext) { |
|
|
|
|
public MethodProcessorRunnable(StructMethod method, VarProcessor varProc, DecompilerContext parentContext) { |
|
|
|
|
this.method = method; |
|
|
|
|
this.varproc = varproc; |
|
|
|
|
this.varProc = varProc; |
|
|
|
|
this.parentContext = parentContext; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void run() { |
|
|
|
|
|
|
|
|
|
DecompilerContext.setCurrentContext(parentContext); |
|
|
|
|
|
|
|
|
|
error = null; |
|
|
|
|
root = null; |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
root = codeToJava(method, varproc); |
|
|
|
|
root = codeToJava(method, varProc); |
|
|
|
|
|
|
|
|
|
synchronized (lock) { |
|
|
|
|
lock.notifyAll(); |
|
|
|
@ -70,8 +70,7 @@ public class MethodProcessorThread implements Runnable { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static RootStatement codeToJava(StructMethod mt, VarProcessor varproc) throws IOException { |
|
|
|
|
|
|
|
|
|
public static RootStatement codeToJava(StructMethod mt, VarProcessor varProc) throws IOException { |
|
|
|
|
StructClass cl = mt.getClassStruct(); |
|
|
|
|
|
|
|
|
|
boolean isInitializer = "<clinit>".equals(mt.getName()); // for now static initializer only
|
|
|
|
@ -80,29 +79,15 @@ public class MethodProcessorThread implements Runnable { |
|
|
|
|
InstructionSequence seq = mt.getInstructionSequence(); |
|
|
|
|
ControlFlowGraph graph = new ControlFlowGraph(seq); |
|
|
|
|
|
|
|
|
|
// System.out.println(graph.toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if(mt.getName().endsWith("_getActiveServers")) {
|
|
|
|
|
// System.out.println();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
//DotExporter.toDotFile(graph, new File("c:\\Temp\\fern1.dot"), true);
|
|
|
|
|
|
|
|
|
|
DeadCodeHelper.removeDeadBlocks(graph); |
|
|
|
|
graph.inlineJsr(mt); |
|
|
|
|
|
|
|
|
|
// DotExporter.toDotFile(graph, new File("c:\\Temp\\fern4.dot"), true);
|
|
|
|
|
|
|
|
|
|
// TODO: move to the start, before jsr inlining
|
|
|
|
|
DeadCodeHelper.connectDummyExitBlock(graph); |
|
|
|
|
|
|
|
|
|
DeadCodeHelper.removeGotos(graph); |
|
|
|
|
ExceptionDeobfuscator.removeCircularRanges(graph); |
|
|
|
|
//DeadCodeHelper.removeCircularRanges(graph);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// DotExporter.toDotFile(graph, new File("c:\\Temp\\fern3.dot"), true);
|
|
|
|
|
ExceptionDeobfuscator.removeCircularRanges(graph); |
|
|
|
|
|
|
|
|
|
ExceptionDeobfuscator.restorePopRanges(graph); |
|
|
|
|
|
|
|
|
@ -110,15 +95,11 @@ public class MethodProcessorThread implements Runnable { |
|
|
|
|
ExceptionDeobfuscator.removeEmptyRanges(graph); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// DotExporter.toDotFile(graph, new File("c:\\Temp\\fern3.dot"), true);
|
|
|
|
|
|
|
|
|
|
if (DecompilerContext.getOption(IFernflowerPreferences.NO_EXCEPTIONS_RETURN)) { |
|
|
|
|
// special case: single return instruction outside of a protected range
|
|
|
|
|
DeadCodeHelper.incorporateValueReturns(graph); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// DotExporter.toDotFile(graph, new File("c:\\Temp\\fern5.dot"), true);
|
|
|
|
|
|
|
|
|
|
// ExceptionDeobfuscator.restorePopRanges(graph);
|
|
|
|
|
ExceptionDeobfuscator.insertEmptyExceptionHandlerBlocks(graph); |
|
|
|
|
|
|
|
|
@ -126,22 +107,14 @@ public class MethodProcessorThread implements Runnable { |
|
|
|
|
|
|
|
|
|
DecompilerContext.getCounterContainer().setCounter(CounterContainer.VAR_COUNTER, mt.getLocalVariables()); |
|
|
|
|
|
|
|
|
|
//DotExporter.toDotFile(graph, new File("c:\\Temp\\fern3.dot"), true);
|
|
|
|
|
//System.out.println(graph.toString());
|
|
|
|
|
|
|
|
|
|
if (ExceptionDeobfuscator.hasObfuscatedExceptions(graph)) { |
|
|
|
|
DecompilerContext.getLogger().writeMessage("Heavily obfuscated exception ranges found!", IFernflowerLogger.Severity.WARN); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
RootStatement root = DomHelper.parseGraph(graph); |
|
|
|
|
|
|
|
|
|
FinallyProcessor fproc = new FinallyProcessor(varproc); |
|
|
|
|
while (fproc.iterateGraph(mt, root, graph)) { |
|
|
|
|
|
|
|
|
|
//DotExporter.toDotFile(graph, new File("c:\\Temp\\fern2.dot"), true);
|
|
|
|
|
//System.out.println(graph.toString());
|
|
|
|
|
//System.out.println("~~~~~~~~~~~~~~~~~~~~~~ \r\n"+root.toJava());
|
|
|
|
|
|
|
|
|
|
FinallyProcessor fProc = new FinallyProcessor(varProc); |
|
|
|
|
while (fProc.iterateGraph(mt, root, graph)) { |
|
|
|
|
root = DomHelper.parseGraph(graph); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -149,9 +122,6 @@ public class MethodProcessorThread implements Runnable { |
|
|
|
|
// not until now because of comparison between synchronized statements in the finally cycle
|
|
|
|
|
DomHelper.removeSynchronizedHandler(root); |
|
|
|
|
|
|
|
|
|
// DotExporter.toDotFile(graph, new File("c:\\Temp\\fern3.dot"), true);
|
|
|
|
|
// System.out.println(graph.toString());
|
|
|
|
|
|
|
|
|
|
// LabelHelper.lowContinueLabels(root, new HashSet<StatEdge>());
|
|
|
|
|
|
|
|
|
|
SequenceHelper.condenseSequences(root); |
|
|
|
@ -161,20 +131,11 @@ public class MethodProcessorThread implements Runnable { |
|
|
|
|
ExprProcessor proc = new ExprProcessor(); |
|
|
|
|
proc.processStatement(root, cl); |
|
|
|
|
|
|
|
|
|
// DotExporter.toDotFile(graph, new File("c:\\Temp\\fern3.dot"), true);
|
|
|
|
|
// System.out.println(graph.toString());
|
|
|
|
|
|
|
|
|
|
//System.out.println("~~~~~~~~~~~~~~~~~~~~~~ \r\n"+root.toJava());
|
|
|
|
|
|
|
|
|
|
while (true) { |
|
|
|
|
StackVarsProcessor stackproc = new StackVarsProcessor(); |
|
|
|
|
stackproc.simplifyStackVars(root, mt, cl); |
|
|
|
|
|
|
|
|
|
//System.out.println("~~~~~~~~~~~~~~~~~~~~~~ \r\n"+root.toJava());
|
|
|
|
|
|
|
|
|
|
varproc.setVarVersions(root); |
|
|
|
|
StackVarsProcessor stackProc = new StackVarsProcessor(); |
|
|
|
|
stackProc.simplifyStackVars(root, mt, cl); |
|
|
|
|
|
|
|
|
|
// System.out.println("~~~~~~~~~~~~~~~~~~~~~~ \r\n"+root.toJava());
|
|
|
|
|
varProc.setVarVersions(root); |
|
|
|
|
|
|
|
|
|
if (!new PPandMMHelper().findPPandMM(root)) { |
|
|
|
|
break; |
|
|
|
@ -182,11 +143,9 @@ public class MethodProcessorThread implements Runnable { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
while (true) { |
|
|
|
|
|
|
|
|
|
LabelHelper.cleanUpEdges(root); |
|
|
|
|
|
|
|
|
|
while (true) { |
|
|
|
|
|
|
|
|
|
MergeHelper.enhanceLoops(root); |
|
|
|
|
|
|
|
|
|
if (LoopExtractHelper.extractLoops(root)) { |
|
|
|
@ -199,22 +158,18 @@ public class MethodProcessorThread implements Runnable { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (DecompilerContext.getOption(IFernflowerPreferences.IDEA_NOT_NULL_ANNOTATION)) { |
|
|
|
|
|
|
|
|
|
if (IdeaNotNullHelper.removeHardcodedChecks(root, mt)) { |
|
|
|
|
|
|
|
|
|
SequenceHelper.condenseSequences(root); |
|
|
|
|
|
|
|
|
|
StackVarsProcessor stackproc = new StackVarsProcessor(); |
|
|
|
|
stackproc.simplifyStackVars(root, mt, cl); |
|
|
|
|
StackVarsProcessor stackProc = new StackVarsProcessor(); |
|
|
|
|
stackProc.simplifyStackVars(root, mt, cl); |
|
|
|
|
|
|
|
|
|
varproc.setVarVersions(root); |
|
|
|
|
varProc.setVarVersions(root); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
LabelHelper.identifyLabels(root); |
|
|
|
|
|
|
|
|
|
// System.out.println("~~~~~~~~~~~~~~~~~~~~~~ \r\n"+root.toJava());
|
|
|
|
|
|
|
|
|
|
if (InlineSingleBlockHelper.inlineSingleBlocks(root)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
@ -234,7 +189,7 @@ public class MethodProcessorThread implements Runnable { |
|
|
|
|
|
|
|
|
|
SecondaryFunctionsHelper.identifySecondaryFunctions(root); |
|
|
|
|
|
|
|
|
|
varproc.setVarDefinitions(root); |
|
|
|
|
varProc.setVarDefinitions(root); |
|
|
|
|
|
|
|
|
|
// must be the last invocation, because it makes the statement structure inconsistent
|
|
|
|
|
// FIXME: new edge type needed
|
|
|
|
@ -242,8 +197,6 @@ public class MethodProcessorThread implements Runnable { |
|
|
|
|
|
|
|
|
|
mt.releaseResources(); |
|
|
|
|
|
|
|
|
|
// System.out.println("++++++++++++++++++++++/// \r\n"+root.toJava());
|
|
|
|
|
|
|
|
|
|
return root; |
|
|
|
|
} |
|
|
|
|
|