diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index ea7fd2fda..bbb930a49 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -2405,18 +2405,30 @@ public class AVM2Code implements Serializable { } } - private static int removeTraps(List localData, Stack stack, List output, AVM2GraphSource code, int ip, int lastIp, List visited) { + private static class Decision { + + public boolean jumpUsed = false; + public boolean skipUsed = false; + } + + private static int removeTraps(boolean secondPass, boolean useVisited,List localData, Stack stack, List output, AVM2GraphSource code, int ip, int lastIp, List visited,HashMap decisions) { boolean debugMode = false; int ret = 0; while ((ip > -1) && ip < code.size()) { - if (visited.contains(ip)) { + if(useVisited && visited.contains(ip)){ break; } - visited.add(ip); + if(!visited.contains(ip)){ + visited.add(ip); + } lastIp = ip; GraphSourceItem ins = code.get(ip); + if(ins.isIgnored()){ + ip++; + continue; + } if (debugMode) { - System.out.println("Visit " + ip + ": " + ins + " stack:" + Highlighting.stripHilights(stack.toString())); + System.out.println((useVisited?"useV ":"")+"Visit " + ip + ": " + ins + " stack:" + Highlighting.stripHilights(stack.toString())); } if ((ins instanceof AVM2Instruction) && (((AVM2Instruction) ins).definition instanceof NewFunctionIns)) { stack.push(new BooleanTreeItem(null, true)); @@ -2439,28 +2451,45 @@ public class AVM2Code implements Serializable { System.out.println("SKIP"); } } + Decision dec = new Decision(); + if (decisions.containsKey(ins)) { + dec = decisions.get(ins); + }else{ + decisions.put(ins, dec); + } if (condition) { - ((AVM2Instruction) ins).definition = new JumpIns(); + dec.jumpUsed = true; } else { - ins.setIgnored(true); + dec.skipUsed = true; + } + + if (secondPass) { + if (condition && (dec.jumpUsed) && (!dec.skipUsed)) { + ((AVM2Instruction) ins).definition = new JumpIns(); + } + if ((!condition) && (!dec.jumpUsed) && (dec.skipUsed)) { + ins.setIgnored(true); + } } GraphTargetItem tar = stack.pop(); - for (GraphSourceItemPos pos : tar.getNeededSources()) { - if (pos.item != ins) { - pos.item.setIgnored(true); + if (secondPass && (dec.jumpUsed != dec.skipUsed)) { + for (GraphSourceItemPos pos : tar.getNeededSources()) { + if (pos.item != ins) { + pos.item.setIgnored(true); + } } } - ret += removeTraps(localData, stack, output, code, condition ? branches.get(0) : branches.get(1), ip, visited); + ret += removeTraps(secondPass,useVisited, localData, stack, output, code, condition ? branches.get(0) : branches.get(1), ip, visited,decisions); } else { - if (ins.isBranch()) { + if (ins.isBranch() && (!ins.isJump())) { stack.pop(); } for (int b : branches) { Stack brStack = (Stack) stack.clone(); if (b >= 0) { - ret += removeTraps(localData, brStack, output, code, b, ip, visited); + ret += removeTraps(secondPass,useVisited||(!ins.isJump()), localData, brStack, output, code, b, ip, visited,decisions); } else { if (debugMode) { System.out.println("Negative branch:" + b); @@ -2479,6 +2508,8 @@ public class AVM2Code implements Serializable { } public static int removeTraps(List localData, AVM2GraphSource code, int addr) { - return removeTraps(localData, new Stack(), new ArrayList(), code, code.adr2pos(addr), 0, new ArrayList()); + HashMap decisions=new HashMap(); + removeTraps(false,false, localData, new Stack(), new ArrayList(), code, code.adr2pos(addr), 0,new ArrayList(), decisions); + return removeTraps(true,false, localData, new Stack(), new ArrayList(), code, code.adr2pos(addr), 0,new ArrayList(),decisions); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/DecLocalIIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/DecLocalIIns.java index cf31379cb..bbd7e92bc 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/DecLocalIIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/DecLocalIIns.java @@ -22,6 +22,9 @@ import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; import com.jpexs.decompiler.flash.abc.avm2.treemodel.DecLocalTreeItem; +import com.jpexs.decompiler.flash.abc.avm2.treemodel.IntegerValueTreeItem; +import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.AddTreeItem; +import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.SubtractTreeItem; import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import java.util.HashMap; @@ -57,5 +60,7 @@ public class DecLocalIIns extends InstructionDefinition { public void translate(boolean isStatic, int classIndex, java.util.HashMap localRegs, Stack stack, java.util.Stack scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List output, com.jpexs.decompiler.flash.abc.types.MethodBody body, com.jpexs.decompiler.flash.abc.ABC abc, HashMap localRegNames, List fullyQualifiedNames) { int regIndex = ins.operands[0]; output.add(new DecLocalTreeItem(ins, regIndex)); + localRegs.put(regIndex, new SubtractTreeItem(ins, localRegs.get(regIndex), new IntegerValueTreeItem(ins, new Long(1)))); + } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/DecLocalIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/DecLocalIns.java index 69e24c80b..a7cfff629 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/DecLocalIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/DecLocalIns.java @@ -22,6 +22,8 @@ import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; import com.jpexs.decompiler.flash.abc.avm2.treemodel.DecLocalTreeItem; +import com.jpexs.decompiler.flash.abc.avm2.treemodel.IntegerValueTreeItem; +import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.SubtractTreeItem; import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import java.util.HashMap; @@ -57,5 +59,6 @@ public class DecLocalIns extends InstructionDefinition { public void translate(boolean isStatic, int classIndex, java.util.HashMap localRegs, Stack stack, java.util.Stack scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List output, com.jpexs.decompiler.flash.abc.types.MethodBody body, com.jpexs.decompiler.flash.abc.ABC abc, HashMap localRegNames, List fullyQualifiedNames) { int regIndex = ins.operands[0]; output.add(new DecLocalTreeItem(ins, regIndex)); + localRegs.put(regIndex, new SubtractTreeItem(ins, localRegs.get(regIndex), new IntegerValueTreeItem(ins, new Long(1)))); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/IncLocalIIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/IncLocalIIns.java index 70529a422..b4d7ff850 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/IncLocalIIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/IncLocalIIns.java @@ -21,6 +21,8 @@ import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; import com.jpexs.decompiler.flash.abc.avm2.treemodel.IncLocalTreeItem; +import com.jpexs.decompiler.flash.abc.avm2.treemodel.IntegerValueTreeItem; +import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.AddTreeItem; import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import java.util.HashMap; @@ -37,5 +39,6 @@ public class IncLocalIIns extends InstructionDefinition { public void translate(boolean isStatic, int classIndex, java.util.HashMap localRegs, Stack stack, java.util.Stack scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List output, com.jpexs.decompiler.flash.abc.types.MethodBody body, com.jpexs.decompiler.flash.abc.ABC abc, HashMap localRegNames, List fullyQualifiedNames) { int regIndex = ins.operands[0]; output.add(new IncLocalTreeItem(ins, regIndex)); + localRegs.put(regIndex, new AddTreeItem(ins, localRegs.get(regIndex), new IntegerValueTreeItem(ins, new Long(1)))); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/IncLocalIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/IncLocalIns.java index 4a784fb10..7658f1de8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/IncLocalIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/IncLocalIns.java @@ -21,6 +21,8 @@ import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; import com.jpexs.decompiler.flash.abc.avm2.treemodel.IncLocalTreeItem; +import com.jpexs.decompiler.flash.abc.avm2.treemodel.IntegerValueTreeItem; +import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.AddTreeItem; import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import java.util.HashMap; @@ -37,5 +39,6 @@ public class IncLocalIns extends InstructionDefinition { public void translate(boolean isStatic, int classIndex, java.util.HashMap localRegs, Stack stack, java.util.Stack scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List output, com.jpexs.decompiler.flash.abc.types.MethodBody body, com.jpexs.decompiler.flash.abc.ABC abc, HashMap localRegNames, List fullyQualifiedNames) { int regIndex = ins.operands[0]; output.add(new IncLocalTreeItem(ins, regIndex)); + localRegs.put(regIndex, new AddTreeItem(ins, localRegs.get(regIndex), new IntegerValueTreeItem(ins, new Long(1)))); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/IncLocalTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/IncLocalTreeItem.java index bf7954659..d73c5e8d9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/IncLocalTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/IncLocalTreeItem.java @@ -33,5 +33,5 @@ public class IncLocalTreeItem extends TreeItem { @Override public String toString(ConstantPool constants, HashMap localRegNames, List fullyQualifiedNames) { return localRegName(localRegNames, regIndex) + hilight("++"); - } + } }