diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/flowgraph/Graph.java b/trunk/src/com/jpexs/asdec/abc/avm2/flowgraph/Graph.java index 255e9eaf8..ef3825361 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/flowgraph/Graph.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/flowgraph/Graph.java @@ -139,13 +139,13 @@ public class Graph { } } - public static List translateViaGraph(String path,AVM2Code code, ABC abc, MethodBody body) { + public static List translateViaGraph(String path, AVM2Code code, ABC abc, MethodBody body) { Graph g = new Graph(code, abc, body); List allParts = new ArrayList(); for (GraphPart head : g.heads) { populateParts(head, allParts); } - return g.printGraph(path,new Stack(), new Stack(), allParts, new ArrayList(), new ArrayList(), 0, null, g.heads.get(0), null, new ArrayList(), new HashMap(), body, new ArrayList()); + return g.printGraph(path, new Stack(), new Stack(), allParts, new ArrayList(), new ArrayList(), 0, null, g.heads.get(0), null, new ArrayList(), new HashMap(), body, new ArrayList()); } private static void populateParts(GraphPart part, List allParts) { @@ -196,621 +196,628 @@ public class Graph { } private boolean doDecompile = true; - private List printGraph(String methodPath,Stack stack, Stack scopeStack, List allParts, List parsedExceptions, List finallyJumps, int level, GraphPart parent, GraphPart part, GraphPart stopPart, List loops, HashMap localRegs, MethodBody body, List ignoredSwitches) { + private List printGraph(String methodPath, Stack stack, Stack scopeStack, List allParts, List parsedExceptions, List finallyJumps, int level, GraphPart parent, GraphPart part, GraphPart stopPart, List loops, HashMap localRegs, MethodBody body, List ignoredSwitches) { List ret = new ArrayList(); - boolean debugMode = false; - - try{ - if (!doDecompile) { - ret.add(new CommentTreeItem(null, "not decompiled")); - return ret; - } + boolean debugMode = false; - if (debugMode) { - System.err.println("PART " + part); - } - - if (part == stopPart) { - return ret; - } - if (part.ignored) { - return ret; - } - List fqn = new ArrayList(); - HashMap lrn = new HashMap(); - List output = new ArrayList(); - boolean isSwitch = false; try { - code.initToSource(); - List parts = new ArrayList(); - if (part instanceof GraphPartMulti) { - parts = ((GraphPartMulti) part).parts; - } else { - parts.add(part); + if (!doDecompile) { + ret.add(new CommentTreeItem(null, "not decompiled")); + return ret; } - boolean isIf = false; - int end = part.end; - for (GraphPart p : parts) { - end = p.end; - int start = p.start; - isIf = false; - if (code.code.get(end).definition instanceof JumpIns) { - end--; - } else if (code.code.get(end).definition instanceof IfTypeIns) { - end--; - isIf = true; - } else if (code.code.get(end).definition instanceof LookupSwitchIns) { - isSwitch = true; - end--; - } - ConvertOutput co = code.toSourceOutput(false,false, 0, localRegs, stack, scopeStack, abc, abc.constants, abc.method_info, body, start, end, lrn, fqn, new boolean[code.code.size()]); - output.addAll(co.output); - + + if (debugMode) { + System.err.println("PART " + part); } - if (isIf) { - AVM2Instruction ins = code.code.get(end + 1); - if ((stack.size() >= 2) && (ins.definition instanceof IfFalseIns) && (stack.get(stack.size() - 1) == stack.get(stack.size() - 2))) { - printGraph(methodPath,stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, parent, part.nextParts.get(1), part.nextParts.get(0), loops, localRegs, body, ignoredSwitches); - TreeItem second = stack.pop(); - TreeItem first = stack.pop(); - stack.push(new AndTreeItem(ins, first, second)); - ret.addAll(printGraph(methodPath,stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, parent, part.nextParts.get(0), stopPart, loops, localRegs, body, ignoredSwitches)); - return ret; - } else if ((stack.size() >= 2) && (ins.definition instanceof IfTrueIns) && (stack.get(stack.size() - 1) == stack.get(stack.size() - 2))) { - printGraph(methodPath,stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, parent, part.nextParts.get(1), part.nextParts.get(0), loops, localRegs, body, ignoredSwitches); - TreeItem second = stack.pop(); - TreeItem first = stack.pop(); - stack.push(new OrTreeItem(ins, first, second)); - ret.addAll(printGraph(methodPath,stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, parent, part.nextParts.get(0), stopPart, loops, localRegs, body, ignoredSwitches)); - return ret; - } else if (((ins.definition instanceof IfStrictNeIns)) && ((part.nextParts.get(1).getHeight() == 2) && (code.code.get(part.nextParts.get(1).start).definition instanceof PushByteIns) && (code.code.get(part.nextParts.get(1).nextParts.get(0).end).definition instanceof LookupSwitchIns))) { - TreeItem switchedObject = null; - if (!output.isEmpty()) { - if (output.get(output.size() - 1) instanceof SetLocalTreeItem) { - switchedObject = ((SetLocalTreeItem) output.get(output.size() - 1)).value; - } + if (part == stopPart) { + return ret; + } + if (part.ignored) { + return ret; + } + List fqn = new ArrayList(); + HashMap lrn = new HashMap(); + List output = new ArrayList(); + boolean isSwitch = false; + try { + code.initToSource(); + List parts = new ArrayList(); + if (part instanceof GraphPartMulti) { + parts = ((GraphPartMulti) part).parts; + } else { + parts.add(part); + } + boolean isIf = false; + int end = part.end; + for (GraphPart p : parts) { + end = p.end; + int start = p.start; + isIf = false; + if (code.code.get(end).definition instanceof JumpIns) { + end--; + } else if (code.code.get(end).definition instanceof IfTypeIns) { + end--; + isIf = true; + } else if (code.code.get(end).definition instanceof LookupSwitchIns) { + isSwitch = true; + end--; } - HashMap caseValuesMap = new HashMap(); + ConvertOutput co = code.toSourceOutput(false, false, 0, localRegs, stack, scopeStack, abc, abc.constants, abc.method_info, body, start, end, lrn, fqn, new boolean[code.code.size()]); + output.addAll(co.output); - stack.pop(); - caseValuesMap.put(code.code.get(part.nextParts.get(1).start).operands[0], stack.pop()); + } + if (isIf) { + AVM2Instruction ins = code.code.get(end + 1); + if ((stack.size() >= 2) && (ins.definition instanceof IfFalseIns) && (stack.get(stack.size() - 1) == stack.get(stack.size() - 2))) { + printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, parent, part.nextParts.get(1), part.nextParts.get(0), loops, localRegs, body, ignoredSwitches); + TreeItem second = stack.pop(); + TreeItem first = stack.pop(); + stack.push(new AndTreeItem(ins, first, second)); + ret.addAll(printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, parent, part.nextParts.get(0), stopPart, loops, localRegs, body, ignoredSwitches)); + return ret; + } else if ((stack.size() >= 2) && (ins.definition instanceof IfTrueIns) && (stack.get(stack.size() - 1) == stack.get(stack.size() - 2))) { + printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, parent, part.nextParts.get(1), part.nextParts.get(0), loops, localRegs, body, ignoredSwitches); + TreeItem second = stack.pop(); + TreeItem first = stack.pop(); + stack.push(new OrTreeItem(ins, first, second)); + ret.addAll(printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, parent, part.nextParts.get(0), stopPart, loops, localRegs, body, ignoredSwitches)); + return ret; + } else if (((ins.definition instanceof IfStrictNeIns)) && ((part.nextParts.get(1).getHeight() == 2) && (code.code.get(part.nextParts.get(1).start).definition instanceof PushByteIns) && (code.code.get(part.nextParts.get(1).nextParts.get(0).end).definition instanceof LookupSwitchIns))) { - GraphPart switchLoc = part.nextParts.get(1).nextParts.get(0); - - while (code.code.get(part.nextParts.get(0).end).definition instanceof IfStrictNeIns) { - part = part.nextParts.get(0); - code.toSourceOutput(false,false, 0, localRegs, stack, scopeStack, abc, abc.constants, abc.method_info, body, part.start, part.end - 1, lrn, fqn, new boolean[code.code.size()]); - stack.pop(); - caseValuesMap.put(code.code.get(part.nextParts.get(1).start).operands[0], stack.pop()); - } - boolean hasDefault = false; - if (code.code.get(part.nextParts.get(0).start).definition instanceof PushByteIns) { - hasDefault = true; - } - List caseValues = new ArrayList(); - for (int i = 0; i < switchLoc.nextParts.size() - 1; i++) { - if (caseValuesMap.containsKey(i)) { - caseValues.add(caseValuesMap.get(i)); - } else { - continue; - } - } - - List> caseCommands = new ArrayList>(); - GraphPart next = null; - for (GraphPart p : allParts) { - if (p.start == switchLoc.end + 1) { - next = p; - break; - } - } - - TreeItem ti = checkLoop(next, stopPart, loops); - loops.add(new Loop(null, next)); - //switchLoc.getNextPartPath(new ArrayList()); - List valuesMapping = new ArrayList(); - List caseBodies = new ArrayList(); - for (int i = 0; i < caseValues.size(); i++) { - GraphPart cur = switchLoc.nextParts.get(1 + i); - if (!caseBodies.contains(cur)) { - caseBodies.add(cur); - } - valuesMapping.add(caseBodies.indexOf(cur)); - } - - List defaultCommands = new ArrayList(); - GraphPart defaultPart = null; - if (hasDefault) { - defaultPart = switchLoc.nextParts.get(switchLoc.nextParts.size() - 1); - defaultCommands = printGraph(methodPath,stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, switchLoc, defaultPart, next, loops, localRegs, body, ignoredSwitches); - } - - List ignored = new ArrayList(); - for (Loop l : loops) { - ignored.add(l.loopContinue); - } - - for (int i = 0; i < caseBodies.size(); i++) { - List cc = new ArrayList(); - GraphPart nextCase=null; - nextCase=next; - if (next != null) { - if (i < caseBodies.size() - 1) { - if (!caseBodies.get(i).leadsTo(caseBodies.get(i + 1), ignored)) { - cc.add(new BreakTreeItem(null, next.start)); - }else{ - nextCase=caseBodies.get(i + 1); - } - } else if (hasDefault) { - if (!caseBodies.get(i).leadsTo(defaultPart, ignored)) { - cc.add(new BreakTreeItem(null, next.start)); - }else{ - nextCase=defaultPart; - } + TreeItem switchedObject = null; + if (!output.isEmpty()) { + if (output.get(output.size() - 1) instanceof SetLocalTreeItem) { + switchedObject = ((SetLocalTreeItem) output.get(output.size() - 1)).value; } } - cc.addAll(0,printGraph(methodPath,stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, switchLoc, caseBodies.get(i), nextCase, loops, localRegs, body, ignoredSwitches)); - caseCommands.add(cc); - } + HashMap caseValuesMap = new HashMap(); - SwitchTreeItem sti = new SwitchTreeItem(null, next==null?-1:next.start, switchedObject, caseValues, caseCommands, defaultCommands, valuesMapping); - ret.add(sti); + stack.pop(); + caseValuesMap.put(code.code.get(part.nextParts.get(1).start).operands[0], stack.pop()); - if(next!=null){ - if (ti != null) { - ret.add(ti); - } else { - ret.addAll(printGraph(methodPath,stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, null, next, stopPart, loops, localRegs, body, ignoredSwitches)); + GraphPart switchLoc = part.nextParts.get(1).nextParts.get(0); + + while (code.code.get(part.nextParts.get(0).end).definition instanceof IfStrictNeIns) { + part = part.nextParts.get(0); + code.toSourceOutput(false, false, 0, localRegs, stack, scopeStack, abc, abc.constants, abc.method_info, body, part.start, part.end - 1, lrn, fqn, new boolean[code.code.size()]); + stack.pop(); + caseValuesMap.put(code.code.get(part.nextParts.get(1).start).operands[0], stack.pop()); + } + boolean hasDefault = false; + if (code.code.get(part.nextParts.get(0).start).definition instanceof PushByteIns) { + hasDefault = true; + } + List caseValues = new ArrayList(); + for (int i = 0; i < switchLoc.nextParts.size() - 1; i++) { + if (caseValuesMap.containsKey(i)) { + caseValues.add(caseValuesMap.get(i)); + } else { + continue; + } } - } - return ret; - } else { - try { - ins.definition.translate(false, 0, new HashMap(), stack, new Stack(), abc.constants, ins, abc.method_info, output, body, abc, lrn, fqn); - } catch (Exception ex) { - System.err.println("ip:" + (end + 1)); - ex.printStackTrace(); - } - } - //((IfTypeIns)ins.definition).translateInverted(new HashMap(), co.stack, ins); - } - } catch (ConvertException ex) { - Logger.getLogger(Graph.class.getName()).log(Level.SEVERE, null, ex); - } - - int ip = part.start; - int addr = code.fixAddrAfterDebugLine(code.pos2adr(part.start)); - int maxend = -1; - List catchedExceptions = new ArrayList(); - for (int e = 0; e < body.exceptions.length; e++) { - if (addr == code.fixAddrAfterDebugLine(body.exceptions[e].start)) { - if (!body.exceptions[e].isFinally()) { - if (((body.exceptions[e].end) > maxend) && (!parsedExceptions.contains(body.exceptions[e]))) { - catchedExceptions.clear(); - maxend = code.fixAddrAfterDebugLine(body.exceptions[e].end); - catchedExceptions.add(body.exceptions[e]); - } else if (code.fixAddrAfterDebugLine(body.exceptions[e].end) == maxend) { - catchedExceptions.add(body.exceptions[e]); - } - } - } - } - if (catchedExceptions.size() > 0) { - parsedExceptions.addAll(catchedExceptions); - int endpos = code.adr2pos(code.fixAddrAfterDebugLine(catchedExceptions.get(0).end)); - int endposStartBlock=code.adr2pos(catchedExceptions.get(0).end); + List> caseCommands = new ArrayList>(); + GraphPart next = null; - List> catchedCommands = new ArrayList>(); - if (code.code.get(endpos).definition instanceof JumpIns) { - int afterCatchAddr = code.pos2adr(endpos + 1) + code.code.get(endpos).operands[0]; - int afterCatchPos = code.adr2pos(afterCatchAddr); - Collections.sort(catchedExceptions, new Comparator() { - public int compare(ABCException o1, ABCException o2) { + List loopContinues = new ArrayList(); + for (Loop l : loops) { + if (l.loopContinue != null) { + loopContinues.add(l.loopContinue); + } + } + + next = switchLoc.getNextPartPath(loopContinues); + /*for (GraphPart p : allParts) { + if (p.start == switchLoc.end + 1) { + next = p; + break; + } + }*/ + + TreeItem ti = checkLoop(next, stopPart, loops); + loops.add(new Loop(null, next)); + //switchLoc.getNextPartPath(new ArrayList()); + List valuesMapping = new ArrayList(); + List caseBodies = new ArrayList(); + for (int i = 0; i < caseValues.size(); i++) { + GraphPart cur = switchLoc.nextParts.get(1 + i); + if (!caseBodies.contains(cur)) { + caseBodies.add(cur); + } + valuesMapping.add(caseBodies.indexOf(cur)); + } + + List defaultCommands = new ArrayList(); + GraphPart defaultPart = null; + if (hasDefault) { + defaultPart = switchLoc.nextParts.get(switchLoc.nextParts.size() - 1); + defaultCommands = printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, switchLoc, defaultPart, next, loops, localRegs, body, ignoredSwitches); + } + + List ignored = new ArrayList(); + for (Loop l : loops) { + ignored.add(l.loopContinue); + } + + for (int i = 0; i < caseBodies.size(); i++) { + List cc = new ArrayList(); + GraphPart nextCase = null; + nextCase = next; + if (next != null) { + if (i < caseBodies.size() - 1) { + if (!caseBodies.get(i).leadsTo(caseBodies.get(i + 1), ignored)) { + cc.add(new BreakTreeItem(null, next.start)); + } else { + nextCase = caseBodies.get(i + 1); + } + } else if (hasDefault) { + if (!caseBodies.get(i).leadsTo(defaultPart, ignored)) { + cc.add(new BreakTreeItem(null, next.start)); + } else { + nextCase = defaultPart; + } + } + } + cc.addAll(0, printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, switchLoc, caseBodies.get(i), nextCase, loops, localRegs, body, ignoredSwitches)); + caseCommands.add(cc); + } + + SwitchTreeItem sti = new SwitchTreeItem(null, next == null ? -1 : next.start, switchedObject, caseValues, caseCommands, defaultCommands, valuesMapping); + ret.add(sti); + + if (next != null) { + if (ti != null) { + ret.add(ti); + } else { + ret.addAll(printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, null, next, stopPart, loops, localRegs, body, ignoredSwitches)); + } + } + return ret; + } else { try { - return code.fixAddrAfterDebugLine(o1.target) - code.fixAddrAfterDebugLine(o2.target); - } catch (ConvertException ex) { - return 0; + ins.definition.translate(false, 0, new HashMap(), stack, new Stack(), abc.constants, ins, abc.method_info, output, body, abc, lrn, fqn); + } catch (Exception ex) { + System.err.println("ip:" + (end + 1)); + ex.printStackTrace(); } } - }); + //((IfTypeIns)ins.definition).translateInverted(new HashMap(), co.stack, ins); + } + } catch (ConvertException ex) { + Logger.getLogger(Graph.class.getName()).log(Level.SEVERE, null, ex); + } + + int ip = part.start; + int addr = code.fixAddrAfterDebugLine(code.pos2adr(part.start)); + int maxend = -1; + List catchedExceptions = new ArrayList(); + for (int e = 0; e < body.exceptions.length; e++) { + if (addr == code.fixAddrAfterDebugLine(body.exceptions[e].start)) { + if (!body.exceptions[e].isFinally()) { + if (((body.exceptions[e].end) > maxend) && (!parsedExceptions.contains(body.exceptions[e]))) { + catchedExceptions.clear(); + maxend = code.fixAddrAfterDebugLine(body.exceptions[e].end); + catchedExceptions.add(body.exceptions[e]); + } else if (code.fixAddrAfterDebugLine(body.exceptions[e].end) == maxend) { + catchedExceptions.add(body.exceptions[e]); + } + } + } + } + if (catchedExceptions.size() > 0) { + parsedExceptions.addAll(catchedExceptions); + int endpos = code.adr2pos(code.fixAddrAfterDebugLine(catchedExceptions.get(0).end)); + int endposStartBlock = code.adr2pos(catchedExceptions.get(0).end); - List finallyCommands = new ArrayList(); - int returnPos = afterCatchPos; - for (int e = 0; e < body.exceptions.length; e++) { - if (body.exceptions[e].isFinally()) { - if (addr == code.fixAddrAfterDebugLine(body.exceptions[e].start)) { - if (afterCatchPos + 1 == code.adr2pos(code.fixAddrAfterDebugLine(body.exceptions[e].end))) { - AVM2Instruction jmpIns = code.code.get(code.adr2pos(code.fixAddrAfterDebugLine(body.exceptions[e].end))); - if (jmpIns.definition instanceof JumpIns) { - int finStart = code.adr2pos(code.fixAddrAfterDebugLine(body.exceptions[e].end) + jmpIns.getBytes().length + jmpIns.operands[0]); - finallyJumps.add(finStart); - /*if (unknownJumps.contains(finStart)) { - unknownJumps.remove((Integer) finStart); - }*/ - for (int f = finStart; f < code.code.size(); f++) { - if (code.code.get(f).definition instanceof LookupSwitchIns) { - AVM2Instruction swins = code.code.get(f); - if (swins.operands.length >= 3) { - if (swins.operands[0] == swins.getBytes().length) { - if (code.adr2pos(code.pos2adr(f) + swins.operands[2]) < finStart) { - GraphPart fpart = null; - for (GraphPart p : allParts) { - if (p.start == finStart) { - fpart = p; - break; + List> catchedCommands = new ArrayList>(); + if (code.code.get(endpos).definition instanceof JumpIns) { + int afterCatchAddr = code.pos2adr(endpos + 1) + code.code.get(endpos).operands[0]; + int afterCatchPos = code.adr2pos(afterCatchAddr); + Collections.sort(catchedExceptions, new Comparator() { + public int compare(ABCException o1, ABCException o2) { + try { + return code.fixAddrAfterDebugLine(o1.target) - code.fixAddrAfterDebugLine(o2.target); + } catch (ConvertException ex) { + return 0; + } + } + }); + + + List finallyCommands = new ArrayList(); + int returnPos = afterCatchPos; + for (int e = 0; e < body.exceptions.length; e++) { + if (body.exceptions[e].isFinally()) { + if (addr == code.fixAddrAfterDebugLine(body.exceptions[e].start)) { + if (afterCatchPos + 1 == code.adr2pos(code.fixAddrAfterDebugLine(body.exceptions[e].end))) { + AVM2Instruction jmpIns = code.code.get(code.adr2pos(code.fixAddrAfterDebugLine(body.exceptions[e].end))); + if (jmpIns.definition instanceof JumpIns) { + int finStart = code.adr2pos(code.fixAddrAfterDebugLine(body.exceptions[e].end) + jmpIns.getBytes().length + jmpIns.operands[0]); + finallyJumps.add(finStart); + /*if (unknownJumps.contains(finStart)) { + unknownJumps.remove((Integer) finStart); + }*/ + for (int f = finStart; f < code.code.size(); f++) { + if (code.code.get(f).definition instanceof LookupSwitchIns) { + AVM2Instruction swins = code.code.get(f); + if (swins.operands.length >= 3) { + if (swins.operands[0] == swins.getBytes().length) { + if (code.adr2pos(code.pos2adr(f) + swins.operands[2]) < finStart) { + GraphPart fpart = null; + for (GraphPart p : allParts) { + if (p.start == finStart) { + fpart = p; + break; + } } - } - stack.push(new ExceptionTreeItem(body.exceptions[e])); - GraphPart fepart = null; - for (GraphPart p : allParts) { - if (p.start == f + 1) { - fepart = p; - break; + stack.push(new ExceptionTreeItem(body.exceptions[e])); + GraphPart fepart = null; + for (GraphPart p : allParts) { + if (p.start == f + 1) { + fepart = p; + break; + } } + //code.code.get(f).ignored = true; + ignoredSwitches.add(f); + finallyCommands = printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, parent, fpart, fepart, loops, localRegs, body, ignoredSwitches); + returnPos = f + 1; + break; } - //code.code.get(f).ignored = true; - ignoredSwitches.add(f); - finallyCommands = printGraph(methodPath,stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, parent, fpart, fepart, loops, localRegs, body, ignoredSwitches); - returnPos = f + 1; - break; } } } } - } - break; + break; + } } } } } - } - for (int e = 0; e < catchedExceptions.size(); e++) { - int eendpos; - if (e < catchedExceptions.size() - 1) { - eendpos = code.adr2pos(code.fixAddrAfterDebugLine(catchedExceptions.get(e + 1).target)) - 2; - } else { - eendpos = afterCatchPos - 1; - } - Stack substack = new Stack(); - substack.add(new ExceptionTreeItem(catchedExceptions.get(e))); - - GraphPart npart = null; - int findpos = code.adr2pos(code.fixAddrAfterDebugLine(catchedExceptions.get(e).target)); - for (GraphPart p : allParts) { - if (p.start == findpos) { - npart = p; - break; + for (int e = 0; e < catchedExceptions.size(); e++) { + int eendpos; + if (e < catchedExceptions.size() - 1) { + eendpos = code.adr2pos(code.fixAddrAfterDebugLine(catchedExceptions.get(e + 1).target)) - 2; + } else { + eendpos = afterCatchPos - 1; } + Stack substack = new Stack(); + substack.add(new ExceptionTreeItem(catchedExceptions.get(e))); + + GraphPart npart = null; + int findpos = code.adr2pos(code.fixAddrAfterDebugLine(catchedExceptions.get(e).target)); + for (GraphPart p : allParts) { + if (p.start == findpos) { + npart = p; + break; + } + } + + GraphPart nepart = null; + for (GraphPart p : allParts) { + if (p.start == eendpos + 1) { + nepart = p; + break; + } + } + stack.add(new ExceptionTreeItem(catchedExceptions.get(e))); + catchedCommands.add(printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, parent, npart, nepart, loops, localRegs, body, ignoredSwitches)); } GraphPart nepart = null; + for (GraphPart p : allParts) { - if (p.start == eendpos + 1) { + if (p.start == endposStartBlock) { nepart = p; break; } } - stack.add(new ExceptionTreeItem(catchedExceptions.get(e))); - catchedCommands.add(printGraph(methodPath,stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, parent, npart, nepart, loops, localRegs, body, ignoredSwitches)); + List tryCommands = printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, parent, part, nepart, loops, localRegs, body, ignoredSwitches); + + output.clear(); + output.add(new TryTreeItem(tryCommands, catchedExceptions, catchedCommands, finallyCommands)); + ip = returnPos; + addr = code.pos2adr(ip); } - GraphPart nepart = null; - + } + + if (ip != part.start) { + part = null; for (GraphPart p : allParts) { - if (p.start == endposStartBlock) { - nepart = p; + if (p.start == ip) { + part = p; break; } } - List tryCommands = printGraph(methodPath,stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, parent, part, nepart, loops, localRegs, body, ignoredSwitches); - - output.clear(); - output.add(new TryTreeItem(tryCommands, catchedExceptions, catchedCommands, finallyCommands)); - ip = returnPos; - addr = code.pos2adr(ip); + ret.addAll(output); + ret.addAll(printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, null, part, stopPart, loops, localRegs, body, ignoredSwitches)); + return ret; } - } - - if (ip != part.start) { - part = null; - for (GraphPart p : allParts) { - if (p.start == ip) { - part = p; - break; - } - } - ret.addAll(output); - ret.addAll(printGraph(methodPath,stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, null, part, stopPart, loops, localRegs, body, ignoredSwitches)); - return ret; - } - - List loopContinues = new ArrayList(); - for (Loop l : loops) { - if (l.loopContinue != null) { - loopContinues.add(l.loopContinue); - } - } - boolean loop = false; - if ((!part.nextParts.isEmpty()) && part.nextParts.get(0).leadsTo(part, loopContinues)) { - loop = true; - } - if (((part.nextParts.size() == 2) || ((part.nextParts.size() == 1) && loop)) && (!isSwitch)) { - - boolean doWhile = loop; - if (loop && output.isEmpty()) { - doWhile = false; - } - Loop currentLoop = new Loop(part, null); - if (loop) { - loops.add(currentLoop); - } - - loopContinues = new ArrayList(); + List loopContinues = new ArrayList(); for (Loop l : loops) { if (l.loopContinue != null) { loopContinues.add(l.loopContinue); } } - - if (part.nextParts.size() > 1) { - currentLoop.loopBreak = part.nextParts.get(1); + boolean loop = false; + if ((!part.nextParts.isEmpty()) && part.nextParts.get(0).leadsTo(part, loopContinues)) { + loop = true; } + if (((part.nextParts.size() == 2) || ((part.nextParts.size() == 1) && loop)) && (!isSwitch)) { - int breakIp = -1; - if (currentLoop.loopBreak != null) { - breakIp = currentLoop.loopBreak.start; - } - TreeItem expr = null; - if ((code.code.get(part.end).definition instanceof JumpIns) || (!(code.code.get(part.end).definition instanceof IfTypeIns))) { - expr = new BooleanTreeItem(null, true); - } else { - if (stack.isEmpty()) { - + boolean doWhile = loop; + if (loop && output.isEmpty()) { + doWhile = false; + } + Loop currentLoop = new Loop(part, null); + if (loop) { + loops.add(currentLoop); } - expr = stack.pop(); - } - if (doWhile) { - ret.add(new DoWhileTreeItem(null, breakIp, part.start, output, expr)); - } else { - ret.addAll(output); - } - GraphPart next = part.getNextPartPath(loopContinues); - - if (loop && (!doWhile)) { - List loopBody = null; - List finalCommands = null; - GraphPart finalPart=null; - boolean isFor=false; - try{ - loopBody=printGraph(methodPath,stack, scopeStack, allParts, parsedExceptions, finallyJumps, level + 1, part, part.nextParts.get(0), stopPart, loops, localRegs, body, ignoredSwitches); - }catch(ForException fex){ - loopBody=fex.output; - finalCommands=fex.finalOutput; - if(!finalCommands.isEmpty()){ - finalCommands.remove(finalCommands.size()-1); //remove continue - } - finalPart=fex.continuePart; - isFor=true; - for(ContinueTreeItem cti:finalPart.forContinues){ - cti.loopPos=breakIp; + loopContinues = new ArrayList(); + for (Loop l : loops) { + if (l.loopContinue != null) { + loopContinues.add(l.loopContinue); } } - if(isFor){ - ret.add(new ForTreeItem(null, breakIp, finalPart.start, new ArrayList(), expr,finalCommands,loopBody)); - } else if ((expr instanceof HasNextTreeItem) && (!loopBody.isEmpty()) && (loopBody.get(0) instanceof SetTypeTreeItem) && (((SetTypeTreeItem) loopBody.get(0)).getValue().getNotCoerced() instanceof NextValueTreeItem)) { - TreeItem obj = ((SetTypeTreeItem) loopBody.get(0)).getObject(); - loopBody.remove(0); - ret.add(new ForEachInTreeItem(null, breakIp, part.start, new InTreeItem(expr.instruction, obj, ((HasNextTreeItem) expr).collection), loopBody)); - } else if ((expr instanceof HasNextTreeItem) && (!loopBody.isEmpty()) && (loopBody.get(0) instanceof SetTypeTreeItem) && (((SetTypeTreeItem) loopBody.get(0)).getValue().getNotCoerced() instanceof NextNameTreeItem)) { - TreeItem obj = ((SetTypeTreeItem) loopBody.get(0)).getObject(); - loopBody.remove(0); - ret.add(new ForInTreeItem(null, breakIp, part.start, new InTreeItem(expr.instruction, obj, ((HasNextTreeItem) expr).collection), loopBody)); + + if (part.nextParts.size() > 1) { + currentLoop.loopBreak = part.nextParts.get(1); + } + + int breakIp = -1; + if (currentLoop.loopBreak != null) { + breakIp = currentLoop.loopBreak.start; + } + TreeItem expr = null; + if ((code.code.get(part.end).definition instanceof JumpIns) || (!(code.code.get(part.end).definition instanceof IfTypeIns))) { + expr = new BooleanTreeItem(null, true); } else { - ret.add(new WhileTreeItem(null, breakIp, part.start, expr, loopBody)); + if (stack.isEmpty()) { + } + expr = stack.pop(); } - } else if (!loop) { - if (expr instanceof LogicalOp) { - expr = ((LogicalOp) expr).invert(); - } - int stackSizeBefore = stack.size(); - Stack trueStack = (Stack) stack.clone(); - Stack falseStack = (Stack) stack.clone(); - TreeItem lopTrue = checkLoop(part.nextParts.get(1), stopPart, loops); - TreeItem lopFalse = null; - if (next != part.nextParts.get(0)) { - lopFalse = checkLoop(part.nextParts.get(0), stopPart, loops); - } - List onTrue = new ArrayList(); - if (lopTrue != null) { - onTrue.add(lopTrue); + if (doWhile) { + ret.add(new DoWhileTreeItem(null, breakIp, part.start, output, expr)); } else { - if (debugMode) { - System.err.println("ONTRUE: (inside " + part + ")"); - } - onTrue = printGraph(methodPath,trueStack, scopeStack, allParts, parsedExceptions, finallyJumps, level + 1, part, part.nextParts.get(1), next==null?stopPart:next, loops, localRegs, body, ignoredSwitches); - if (debugMode) { - System.err.println("/ONTRUE (inside " + part + ")"); - } - } - List onFalse = new ArrayList(); - if (lopFalse != null) { - onFalse.add(lopFalse); - } else { - if (debugMode) { - System.err.println("ONFALSE: (inside " + part + ")"); - } - onFalse = (((next == part.nextParts.get(0)) || (part.nextParts.get(0).path.equals(part.path) || part.nextParts.get(0).path.length() < part.path.length())) ? new ArrayList() : printGraph(methodPath,falseStack, scopeStack, allParts, parsedExceptions, finallyJumps, level + 1, part, part.nextParts.get(0), next==null?stopPart:next, loops, localRegs, body, ignoredSwitches)); - if (debugMode) { - System.err.println("/ONFALSE (inside " + part + ")"); - } + ret.addAll(output); } - if (onTrue.isEmpty() && onFalse.isEmpty() && (trueStack.size() > stackSizeBefore) && (falseStack.size() > stackSizeBefore)) { - stack.push(new TernarOpTreeItem(null, expr, trueStack.pop(), falseStack.pop())); - } else { - ret.add(new IfTreeItem(null, expr, onTrue, onFalse)); - } - } - if (loop && (part.nextParts.size() > 1)) { - ret.addAll(printGraph(methodPath,stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, part, part.nextParts.get(1), stopPart, loops, localRegs, body, ignoredSwitches)); - } + GraphPart next = part.getNextPartPath(loopContinues); - if (next != null) { - boolean finallyJump = false; - for (int f : finallyJumps) { - if (next.start == f) { - finallyJump = true; - break; + if (loop && (!doWhile)) { + List loopBody = null; + List finalCommands = null; + GraphPart finalPart = null; + boolean isFor = false; + try { + loopBody = printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level + 1, part, part.nextParts.get(0), stopPart, loops, localRegs, body, ignoredSwitches); + } catch (ForException fex) { + loopBody = fex.output; + finalCommands = fex.finalOutput; + if (!finalCommands.isEmpty()) { + finalCommands.remove(finalCommands.size() - 1); //remove continue + } + finalPart = fex.continuePart; + isFor = true; + for (ContinueTreeItem cti : finalPart.forContinues) { + cti.loopPos = breakIp; + } } - } - if (!finallyJump) { - TreeItem ti = checkLoop(next, stopPart, loops); - if (ti != null) { - ret.add(ti); + if (isFor) { + ret.add(new ForTreeItem(null, breakIp, finalPart.start, new ArrayList(), expr, finalCommands, loopBody)); + } else if ((expr instanceof HasNextTreeItem) && (!loopBody.isEmpty()) && (loopBody.get(0) instanceof SetTypeTreeItem) && (((SetTypeTreeItem) loopBody.get(0)).getValue().getNotCoerced() instanceof NextValueTreeItem)) { + TreeItem obj = ((SetTypeTreeItem) loopBody.get(0)).getObject(); + loopBody.remove(0); + ret.add(new ForEachInTreeItem(null, breakIp, part.start, new InTreeItem(expr.instruction, obj, ((HasNextTreeItem) expr).collection), loopBody)); + } else if ((expr instanceof HasNextTreeItem) && (!loopBody.isEmpty()) && (loopBody.get(0) instanceof SetTypeTreeItem) && (((SetTypeTreeItem) loopBody.get(0)).getValue().getNotCoerced() instanceof NextNameTreeItem)) { + TreeItem obj = ((SetTypeTreeItem) loopBody.get(0)).getObject(); + loopBody.remove(0); + ret.add(new ForInTreeItem(null, breakIp, part.start, new InTreeItem(expr.instruction, obj, ((HasNextTreeItem) expr).collection), loopBody)); + } else { + ret.add(new WhileTreeItem(null, breakIp, part.start, expr, loopBody)); + } + } else if (!loop) { + if (expr instanceof LogicalOp) { + expr = ((LogicalOp) expr).invert(); + } + int stackSizeBefore = stack.size(); + Stack trueStack = (Stack) stack.clone(); + Stack falseStack = (Stack) stack.clone(); + TreeItem lopTrue = checkLoop(part.nextParts.get(1), stopPart, loops); + TreeItem lopFalse = null; + if (next != part.nextParts.get(0)) { + lopFalse = checkLoop(part.nextParts.get(0), stopPart, loops); + } + List onTrue = new ArrayList(); + if (lopTrue != null) { + onTrue.add(lopTrue); } else { if (debugMode) { - System.err.println("NEXT: (inside " + part + ")"); + System.err.println("ONTRUE: (inside " + part + ")"); } - ret.addAll(printGraph(methodPath,stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, part, next, stopPart, loops, localRegs, body, ignoredSwitches)); + onTrue = printGraph(methodPath, trueStack, scopeStack, allParts, parsedExceptions, finallyJumps, level + 1, part, part.nextParts.get(1), next == null ? stopPart : next, loops, localRegs, body, ignoredSwitches); if (debugMode) { - System.err.println("/NEXT: (inside " + part + ")"); + System.err.println("/ONTRUE (inside " + part + ")"); } } + List onFalse = new ArrayList(); + if (lopFalse != null) { + onFalse.add(lopFalse); + } else { + if (debugMode) { + System.err.println("ONFALSE: (inside " + part + ")"); + } + onFalse = (((next == part.nextParts.get(0)) || (part.nextParts.get(0).path.equals(part.path) || part.nextParts.get(0).path.length() < part.path.length())) ? new ArrayList() : printGraph(methodPath, falseStack, scopeStack, allParts, parsedExceptions, finallyJumps, level + 1, part, part.nextParts.get(0), next == null ? stopPart : next, loops, localRegs, body, ignoredSwitches)); + if (debugMode) { + System.err.println("/ONFALSE (inside " + part + ")"); + } + } + + if (onTrue.isEmpty() && onFalse.isEmpty() && (trueStack.size() > stackSizeBefore) && (falseStack.size() > stackSizeBefore)) { + stack.push(new TernarOpTreeItem(null, expr, trueStack.pop(), falseStack.pop())); + } else { + ret.add(new IfTreeItem(null, expr, onTrue, onFalse)); + } + } + if (loop && (part.nextParts.size() > 1)) { + ret.addAll(printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, part, part.nextParts.get(1), stopPart, loops, localRegs, body, ignoredSwitches)); } - } - } else { - ret.addAll(output); - } - onepart: - if (part.nextParts.size() == 1 && (!loop)) { - if (part.end - part.start > 4) { - if (code.code.get(part.end).definition instanceof PopIns) { - if (code.code.get(part.end - 1).definition instanceof LabelIns) { - if (code.code.get(part.end - 2).definition instanceof PushByteIns) { - //if (code.code.get(part.end - 3).definition instanceof SetLocalTypeIns) { - if (part.nextParts.size() == 1) { - GraphPart sec = part.nextParts.get(0); - - if (code.code.get(sec.end).definition instanceof ReturnValueIns) { - if (sec.end - sec.start >= 3) { - if (code.code.get(sec.end - 1).definition instanceof KillIns) { - if (code.code.get(sec.end - 2).definition instanceof GetLocalTypeIns) { - if (!output.isEmpty()) { - if (output.get(output.size() - 1) instanceof SetLocalTreeItem) { - sec.ignored = true; - ret.add(new ReturnValueTreeItem(code.code.get(sec.end), ((SetLocalTreeItem) output.get(output.size() - 1)).value)); - break onepart; - } - } - } - } - } - - } else if (code.code.get(sec.end).definition instanceof ReturnVoidIns) { - ret.add(new ReturnVoidTreeItem(code.code.get(sec.end))); - break onepart; - } - //} + if (next != null) { + boolean finallyJump = false; + for (int f : finallyJumps) { + if (next.start == f) { + finallyJump = true; + break; + } + } + if (!finallyJump) { + TreeItem ti = checkLoop(next, stopPart, loops); + if (ti != null) { + ret.add(ti); + } else { + if (debugMode) { + System.err.println("NEXT: (inside " + part + ")"); + } + ret.addAll(printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, part, next, stopPart, loops, localRegs, body, ignoredSwitches)); + if (debugMode) { + System.err.println("/NEXT: (inside " + part + ")"); } } } } - } - - for (int f : finallyJumps) { - if (part.nextParts.get(0).start == f) { - if ((!output.isEmpty()) && (output.get(output.size() - 1) instanceof SetLocalTreeItem)) { - ret.add(new ReturnValueTreeItem(null, ((SetLocalTreeItem) output.get(output.size() - 1)).value)); - } else { - ret.add(new ReturnVoidTreeItem(null)); - } - - break onepart; - } - } - - GraphPart p = part.nextParts.get(0); - TreeItem lop = checkLoop(p, stopPart, loops); - if (lop == null) { - if (p.path.length() == part.path.length()) { - ret.addAll(printGraph(methodPath,stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, part, p, stopPart, loops, localRegs, body, ignoredSwitches)); - }else{ - if(p!=stopPart){ - ContinueTreeItem cti=new ContinueTreeItem(null, -1); - p.forContinues.add(cti); - ret.add(cti); - //ret.add(new CommentTreeItem(null, "Jump to different path")); - } - } } else { - ret.add(lop); + ret.addAll(output); } - //} - //ret += (strOfChars(level, TAB) + "continue;\r\n"); - //} - } - if (isSwitch && (!ignoredSwitches.contains(part.end))) { - //ret.add(new CommentTreeItem(code.code.get(part.end), "Switch not supported")); - TreeItem switchedObject = stack.pop(); - List caseValues=new ArrayList(); - List valueMappings=new ArrayList(); - List> caseCommands=new ArrayList>(); - - GraphPart next = part.getNextPartPath(loopContinues); - int breakPos=-1; - if(next!=null){ - breakPos=next.start; - } - List defaultCommands=printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, part, part.nextParts.get(0), stopPart, loops, localRegs, body, ignoredSwitches); - - for(int i=0;i caseBody=new ArrayList(); - if(i())){ - caseBody.add(new BreakTreeItem(null, breakPos)); - }else{ - nextCase=part.nextParts.get(1+i+1); + onepart: + if (part.nextParts.size() == 1 && (!loop)) { + if (part.end - part.start > 4) { + if (code.code.get(part.end).definition instanceof PopIns) { + if (code.code.get(part.end - 1).definition instanceof LabelIns) { + if (code.code.get(part.end - 2).definition instanceof PushByteIns) { + + //if (code.code.get(part.end - 3).definition instanceof SetLocalTypeIns) { + if (part.nextParts.size() == 1) { + GraphPart sec = part.nextParts.get(0); + + if (code.code.get(sec.end).definition instanceof ReturnValueIns) { + if (sec.end - sec.start >= 3) { + if (code.code.get(sec.end - 1).definition instanceof KillIns) { + if (code.code.get(sec.end - 2).definition instanceof GetLocalTypeIns) { + if (!output.isEmpty()) { + if (output.get(output.size() - 1) instanceof SetLocalTreeItem) { + sec.ignored = true; + ret.add(new ReturnValueTreeItem(code.code.get(sec.end), ((SetLocalTreeItem) output.get(output.size() - 1)).value)); + break onepart; + } + } + } + } + } + + } else if (code.code.get(sec.end).definition instanceof ReturnVoidIns) { + ret.add(new ReturnVoidTreeItem(code.code.get(sec.end))); + break onepart; + } + //} + } + } + } } - }else if(!part.nextParts.get(1+i).leadsTo(part.nextParts.get(0), new ArrayList())){ - caseBody.add(new BreakTreeItem(null, breakPos)); - }else{ - nextCase=part.nextParts.get(0); } - caseBody.addAll(0,printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, part, part.nextParts.get(1+i), nextCase, loops, localRegs, body, ignoredSwitches)); - caseCommands.add(caseBody); + + for (int f : finallyJumps) { + if (part.nextParts.get(0).start == f) { + if ((!output.isEmpty()) && (output.get(output.size() - 1) instanceof SetLocalTreeItem)) { + ret.add(new ReturnValueTreeItem(null, ((SetLocalTreeItem) output.get(output.size() - 1)).value)); + } else { + ret.add(new ReturnVoidTreeItem(null)); + } + + break onepart; + } + } + + GraphPart p = part.nextParts.get(0); + TreeItem lop = checkLoop(p, stopPart, loops); + if (lop == null) { + if (p.path.length() == part.path.length()) { + ret.addAll(printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, part, p, stopPart, loops, localRegs, body, ignoredSwitches)); + } else { + if ((p != stopPart) && (p.refs.size() > 1)) { + ContinueTreeItem cti = new ContinueTreeItem(null, -1); + p.forContinues.add(cti); + ret.add(cti); + } + } + } else { + ret.add(lop); + } + //} + //ret += (strOfChars(level, TAB) + "continue;\r\n"); + //} } - - SwitchTreeItem swt=new SwitchTreeItem(null, breakPos, switchedObject, caseValues, caseCommands,defaultCommands, valueMappings); - ret.add(swt); - - TreeItem lopNext = checkLoop(next, stopPart, loops); - if(lopNext!=null){ - ret.add(lopNext); - }else{ - ret.addAll(printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, part, next, stopPart, loops, localRegs, body, ignoredSwitches)); + if (isSwitch && (!ignoredSwitches.contains(part.end))) { + //ret.add(new CommentTreeItem(code.code.get(part.end), "Switch not supported")); + TreeItem switchedObject = stack.pop(); + List caseValues = new ArrayList(); + List valueMappings = new ArrayList(); + List> caseCommands = new ArrayList>(); + + GraphPart next = part.getNextPartPath(loopContinues); + int breakPos = -1; + if (next != null) { + breakPos = next.start; + } + List defaultCommands = printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, part, part.nextParts.get(0), stopPart, loops, localRegs, body, ignoredSwitches); + + for (int i = 0; i < part.nextParts.size() - 1; i++) { + caseValues.add(new IntegerValueTreeItem(null, (Long) (long) i)); + valueMappings.add(i); + GraphPart nextCase = next; + List caseBody = new ArrayList(); + if (i < part.nextParts.size() - 1 - 1) { + if (!part.nextParts.get(1 + i).leadsTo(part.nextParts.get(1 + i + 1), new ArrayList())) { + caseBody.add(new BreakTreeItem(null, breakPos)); + } else { + nextCase = part.nextParts.get(1 + i + 1); + } + } else if (!part.nextParts.get(1 + i).leadsTo(part.nextParts.get(0), new ArrayList())) { + caseBody.add(new BreakTreeItem(null, breakPos)); + } else { + nextCase = part.nextParts.get(0); + } + caseBody.addAll(0, printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, part, part.nextParts.get(1 + i), nextCase, loops, localRegs, body, ignoredSwitches)); + caseCommands.add(caseBody); + } + + SwitchTreeItem swt = new SwitchTreeItem(null, breakPos, switchedObject, caseValues, caseCommands, defaultCommands, valueMappings); + ret.add(swt); + + TreeItem lopNext = checkLoop(next, stopPart, loops); + if (lopNext != null) { + ret.add(lopNext); + } else { + ret.addAll(printGraph(methodPath, stack, scopeStack, allParts, parsedExceptions, finallyJumps, level, part, next, stopPart, loops, localRegs, body, ignoredSwitches)); + } + } - - } - - }catch(ForException fex){ + + } catch (ForException fex) { ret.addAll(fex.output); - fex.output=ret; + fex.output = ret; throw fex; } code.clearTemporaryRegisters(ret); - if(!part.forContinues.isEmpty()){ - throw new ForException(new ArrayList(), ret,part); + if (!part.forContinues.isEmpty()) { + throw new ForException(new ArrayList(), ret, part); } return ret; } @@ -838,11 +845,17 @@ public class Graph { if (!doChildren) { + List uniqueRefs = new ArrayList(); + for (GraphPart r : part.refs) { + if (!uniqueRefs.contains(r)) { + uniqueRefs.add(r); + } + } loopi: for (; i <= part.path.length(); i++) { lastpref = null; int pos = -1; - for (GraphPart r : part.refs) { + for (GraphPart r : uniqueRefs) { pos++; if (r.path.startsWith("e")) { continue; @@ -870,8 +883,8 @@ public class Graph { if (i > part.path.length()) { i = part.path.length(); } - if (modify && ((part.refs.size() > 1) && (prvni >= 0))) { - String newpath = part.refs.get(prvni).path.substring(0, i); + if (modify && ((uniqueRefs.size() > 1) && (prvni >= 0))) { + String newpath = uniqueRefs.get(prvni).path.substring(0, i); if (!part.path.equals(newpath)) { if (part.path.startsWith(newpath)) { String origPath = part.path; @@ -900,16 +913,12 @@ public class Graph { } } } - if (part.nextParts.size() == 2) { - GraphPart left = part.nextParts.get(0); - GraphPart right = part.nextParts.get(1); - if (true) { //(!visited.contains(left)) && (!visited.contains(right)) - if (left.path.length() > part.path.length() + 1) { - left.path = part.path + "0"; - fixed = true; - } - if (right.path.length() > part.path.length() + 1) { - right.path = part.path + "1"; + if (part.nextParts.size() > 1) { + for (int j = 0; j < part.nextParts.size(); j++) { + GraphPart npart = part.nextParts.get(j); + + if (npart.path.length() > part.path.length() + 1) { + npart.path = part.path + "" + j; fixed = true; } } diff --git a/trunk/src/com/jpexs/asdec/abc/gui/MethodCodePanel.java b/trunk/src/com/jpexs/asdec/abc/gui/MethodCodePanel.java index c7bceecde..62b02bd35 100644 --- a/trunk/src/com/jpexs/asdec/abc/gui/MethodCodePanel.java +++ b/trunk/src/com/jpexs/asdec/abc/gui/MethodCodePanel.java @@ -89,7 +89,7 @@ public class MethodCodePanel extends JPanel implements ActionListener { // buttonsPanel.add(saveButton); // buttonsPan.add(execButton); - //add(buttonsPanel, BorderLayout.SOUTH); + add(buttonsPanel, BorderLayout.SOUTH); } public void actionPerformed(ActionEvent e) { diff --git a/trunk/src/com/jpexs/asdec/gui/MainFrame.java b/trunk/src/com/jpexs/asdec/gui/MainFrame.java index 74b279af8..97ff7fbce 100644 --- a/trunk/src/com/jpexs/asdec/gui/MainFrame.java +++ b/trunk/src/com/jpexs/asdec/gui/MainFrame.java @@ -267,11 +267,11 @@ public class MainFrame extends JFrame implements ActionListener { miControlFlowAll.setActionCommand("RESTORECONTROLFLOWALL"); miControlFlowAll.addActionListener(this); + menuDeobfuscation.add(miRenameIdentifiers); //menuDeobfuscation.add(miSubLimiter); menuDeobfuscation.add(miDeobfuscation); /*menuDeobfuscation.add(miDeobfuscate); - menuDeobfuscation.addSeparator();*/ - menuDeobfuscation.add(miRenameIdentifiers); + menuDeobfuscation.addSeparator();*/ /*menuDeobfuscation.add(miRemoveDeadCode); menuDeobfuscation.add(miRemoveDeadCodeAll); menuDeobfuscation.add(miTraps);