private VBStyleCollection<Exprent, String> dynamicFieldInitializers = new VBStyleCollection<Exprent, String>();
private VBStyleCollection<MethodWrapper, String> methods = new VBStyleCollection<MethodWrapper, String>();
-
public ClassWrapper(StructClass classStruct) {
this.classStruct = classStruct;
}
public void init() throws IOException {
-
DecompilerContext.setProperty(DecompilerContext.CURRENT_CLASS, classStruct);
-
DecompilerContext.getLogger().startClass(classStruct.qualifiedName);
// collect field names
- HashSet<String> setFieldNames = new HashSet<String>();
+ Set<String> setFieldNames = new HashSet<String>();
for (StructField fd : classStruct.getFields()) {
setFieldNames.add(fd.getName());
}
- int maxsec = Integer.parseInt(DecompilerContext.getProperty(IFernflowerPreferences.MAX_PROCESSING_METHOD).toString());
+ int maxSec = Integer.parseInt(DecompilerContext.getProperty(IFernflowerPreferences.MAX_PROCESSING_METHOD).toString());
for (StructMethod mt : classStruct.getMethods()) {
-
DecompilerContext.getLogger().startMethod(mt.getName() + " " + mt.getDescriptor());
VarNamesCollector vc = new VarNamesCollector();
DecompilerContext.setProperty(DecompilerContext.CURRENT_METHOD, mt);
DecompilerContext.setProperty(DecompilerContext.CURRENT_METHOD_DESCRIPTOR, MethodDescriptor.parseDescriptor(mt.getDescriptor()));
- VarProcessor varproc = new VarProcessor();
- DecompilerContext.setProperty(DecompilerContext.CURRENT_VAR_PROCESSOR, varproc);
+ VarProcessor varProc = new VarProcessor();
+ DecompilerContext.setProperty(DecompilerContext.CURRENT_VAR_PROCESSOR, varProc);
RootStatement root = null;
try {
if (mt.containsCode()) {
-
- if (maxsec == 0) { // blocking wait
- root = MethodProcessorThread.codeToJava(mt, varproc);
+ if (maxSec == 0) {
+ root = MethodProcessorRunnable.codeToJava(mt, varProc);
}
else {
- MethodProcessorThread mtproc = new MethodProcessorThread(mt, varproc, DecompilerContext.getCurrentContext());
- Thread mtthread = new Thread(mtproc);
- long stopAt = System.currentTimeMillis() + maxsec * 1000;
+ MethodProcessorRunnable mtProc = new MethodProcessorRunnable(mt, varProc, DecompilerContext.getCurrentContext());
- mtthread.start();
+ Thread mtThread = new Thread(mtProc);
+ long stopAt = System.currentTimeMillis() + maxSec * 1000;
- while (mtthread.isAlive()) {
+ mtThread.start();
- synchronized (mtproc.lock) {
- mtproc.lock.wait(100);
+ while (mtThread.isAlive()) {
+ synchronized (mtProc.lock) {
+ mtProc.lock.wait(100);
}
if (System.currentTimeMillis() >= stopAt) {
String message = "Processing time limit exceeded for method " + mt.getName() + ", execution interrupted.";
DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.ERROR);
- killThread(mtthread);
+ killThread(mtThread);
isError = true;
break;
}
}
if (!isError) {
- root = mtproc.getResult();
+ root = mtProc.getResult();
}
}
}
else {
- boolean thisvar = !mt.hasModifier(CodeConstants.ACC_STATIC);
+ boolean thisVar = !mt.hasModifier(CodeConstants.ACC_STATIC);
MethodDescriptor md = MethodDescriptor.parseDescriptor(mt.getDescriptor());
- int paramcount = 0;
- if (thisvar) {
- varproc.getThisVars().put(new VarVersionPair(0, 0), classStruct.qualifiedName);
- paramcount = 1;
+ int paramCount = 0;
+ if (thisVar) {
+ varProc.getThisVars().put(new VarVersionPair(0, 0), classStruct.qualifiedName);
+ paramCount = 1;
}
- paramcount += md.params.length;
+ paramCount += md.params.length;
- int varindex = 0;
- for (int i = 0; i < paramcount; i++) {
- varproc.setVarName(new VarVersionPair(varindex, 0), vc.getFreeName(varindex));
+ int varIndex = 0;
+ for (int i = 0; i < paramCount; i++) {
+ varProc.setVarName(new VarVersionPair(varIndex, 0), vc.getFreeName(varIndex));
- if (thisvar) {
+ if (thisVar) {
if (i == 0) {
- varindex++;
+ varIndex++;
}
else {
- varindex += md.params[i - 1].stackSize;
+ varIndex += md.params[i - 1].stackSize;
}
}
else {
- varindex += md.params[i].stackSize;
+ varIndex += md.params[i].stackSize;
}
}
}
isError = true;
}
- MethodWrapper meth = new MethodWrapper(root, varproc, mt, counter);
- meth.decompiledWithErrors = isError;
+ MethodWrapper methodWrapper = new MethodWrapper(root, varProc, mt, counter);
+ methodWrapper.decompiledWithErrors = isError;
- methods.addWithKey(meth, InterpreterUtil.makeUniqueKey(mt.getName(), mt.getDescriptor()));
+ methods.addWithKey(methodWrapper, InterpreterUtil.makeUniqueKey(mt.getName(), mt.getDescriptor()));
// rename vars so that no one has the same name as a field
- varproc.refreshVarNames(new VarNamesCollector(setFieldNames));
+ varProc.refreshVarNames(new VarNamesCollector(setFieldNames));
// if debug information present and should be used
if (DecompilerContext.getOption(IFernflowerPreferences.USE_DEBUG_VAR_NAMES)) {
StructGeneralAttribute.ATTRIBUTE_LOCAL_VARIABLE_TABLE);
if (attr != null) {
- varproc.setDebugVarNames(attr.getMapVarNames());
+ varProc.setDebugVarNames(attr.getMapVarNames());
}
}
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();
}
}
- 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
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);
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);
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);
}
// 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);
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;
}
while (true) {
-
LabelHelper.cleanUpEdges(root);
while (true) {
-
MergeHelper.enhanceLoops(root);
if (LoopExtractHelper.extractLoops(root)) {
}
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;
}
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
mt.releaseResources();
- // System.out.println("++++++++++++++++++++++/// \r\n"+root.toJava());
-
return root;
}