diff --git a/trunk/nbproject/ide-file-targets.xml b/trunk/nbproject/ide-file-targets.xml index 6c3becb55..743bf78b1 100644 --- a/trunk/nbproject/ide-file-targets.xml +++ b/trunk/nbproject/ide-file-targets.xml @@ -8,13 +8,11 @@ - + - - - + diff --git a/trunk/src/com/jpexs/decompiler/flash/Configuration.java b/trunk/src/com/jpexs/decompiler/flash/Configuration.java index 681210b31..70c3e890c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/Configuration.java +++ b/trunk/src/com/jpexs/decompiler/flash/Configuration.java @@ -128,7 +128,7 @@ public class Configuration { ObjectInputStream ois = null; try { ois = new ObjectInputStream(new FileInputStream(file)); - + config = (HashMap) ois.readObject(); } catch (FileNotFoundException ex) { } catch (ClassNotFoundException cnf) { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2GraphSource.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2GraphSource.java index b04104892..f5ab543c2 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2GraphSource.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2GraphSource.java @@ -62,12 +62,12 @@ public class AVM2GraphSource extends GraphSource { return code.code.isEmpty(); } - @Override + @Override @SuppressWarnings("unchecked") public List translatePart(GraphPart part, List localData, Stack stack, int start, int end) { - List ret = new ArrayList(); - Object o=localData.get(AVM2Graph.DATA_SCOPESTACK); - Stack newstack=(Stack)o ; + List ret = new ArrayList(); + Object o = localData.get(AVM2Graph.DATA_SCOPESTACK); + Stack newstack = (Stack) o; ConvertOutput co = code.toSourceOutput(part, false, isStatic, scriptIndex, classIndex, localRegs, stack, newstack, abc, abc.constants, abc.method_info, body, start, end, localRegNames, fullyQualifiedNames, new boolean[size()]); ret.addAll(co.output); return ret; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/gui/ABCPanel.java b/trunk/src/com/jpexs/decompiler/flash/abc/gui/ABCPanel.java index 5a675459f..ce8987526 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/gui/ABCPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/gui/ABCPanel.java @@ -380,7 +380,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener { JPanel panConstants = new JPanel(); panConstants.setLayout(new BorderLayout()); - + constantTypeList = new JComboBox(new Object[]{"UINT", "INT", "DOUBLE", "DECIMAL", "STRING", "NAMESPACE", "NAMESPACESET", "MULTINAME"}); constantTable = new JTable(); if (abc != null) { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/gui/DeobfuscationDialog.java b/trunk/src/com/jpexs/decompiler/flash/abc/gui/DeobfuscationDialog.java index 752972d32..661f333ab 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/gui/DeobfuscationDialog.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/gui/DeobfuscationDialog.java @@ -59,7 +59,7 @@ public class DeobfuscationDialog extends JDialog implements ActionListener { cp.add(lab1); Hashtable labelTable = new Hashtable(); //labelTable.put(new Integer(LEVEL_NONE), new JLabel("None")); - + labelTable.put(new Integer(LEVEL_REMOVE_DEAD_CODE), new JLabel("Remove dead code")); labelTable.put(new Integer(LEVEL_REMOVE_TRAPS), new JLabel("Remove traps")); labelTable.put(new Integer(LEVEL_RESTORE_CONTROL_FLOW), new JLabel("Restore control flow")); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/gui/TraitsList.java b/trunk/src/com/jpexs/decompiler/flash/abc/gui/TraitsList.java index 1c5206c3e..2b69f99b0 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/gui/TraitsList.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/gui/TraitsList.java @@ -52,7 +52,7 @@ public class TraitsList extends JList implements ListSelectionListener { @SuppressWarnings("unchecked") public void setABC(List abcTags, ABC abc) { this.abc = abc; - this.abcTags = abcTags; + this.abcTags = abcTags; setModel(new DefaultListModel()); setClassIndex(-1, -1); } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/Action.java b/trunk/src/com/jpexs/decompiler/flash/action/Action.java index 186eb5c87..5d2ea84a8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/Action.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/Action.java @@ -664,7 +664,7 @@ public class Action implements GraphSourceItem { @Override @SuppressWarnings("unchecked") - public void translate(List localData, Stack stack, List output) { + public void translate(List localData, Stack stack, List output) { translate(stack, output, (HashMap) localData.get(0), (HashMap) localData.get(1), (HashMap) localData.get(2)); } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/RegisterNumber.java b/trunk/src/com/jpexs/decompiler/flash/action/swf4/RegisterNumber.java index 0c60dc263..fb023c3d1 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/RegisterNumber.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/RegisterNumber.java @@ -21,6 +21,28 @@ public class RegisterNumber { public int number; public String name = null; + @Override + public int hashCode() { + int hash = 3; + hash = 47 * hash + this.number; + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final RegisterNumber other = (RegisterNumber) obj; + if (this.number != other.number) { + return false; + } + return true; + } + public RegisterNumber(int number) { this.number = number; } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionStoreRegister.java b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionStoreRegister.java index 2fe386cc2..cc80a1e23 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionStoreRegister.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionStoreRegister.java @@ -22,7 +22,11 @@ import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.parser.ParseException; import com.jpexs.decompiler.flash.action.parser.pcode.FlasmLexer; import com.jpexs.decompiler.flash.action.swf4.RegisterNumber; +import com.jpexs.decompiler.flash.action.treemodel.DecrementTreeItem; import com.jpexs.decompiler.flash.action.treemodel.DirectValueTreeItem; +import com.jpexs.decompiler.flash.action.treemodel.IncrementTreeItem; +import com.jpexs.decompiler.flash.action.treemodel.PostDecrementTreeItem; +import com.jpexs.decompiler.flash.action.treemodel.PostIncrementTreeItem; import com.jpexs.decompiler.flash.action.treemodel.StoreRegisterTreeItem; import com.jpexs.decompiler.flash.graph.GraphSourceItemPos; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -70,28 +74,50 @@ public class ActionStoreRegister extends Action { @Override public void translate(Stack stack, List output, java.util.HashMap regNames, HashMap variables, HashMap functions) { - GraphTargetItem item = stack.pop(); + GraphTargetItem value = stack.pop(); RegisterNumber rn = new RegisterNumber(registerNumber); if (regNames.containsKey(registerNumber)) { rn.name = regNames.get(registerNumber); } - item.moreSrc.add(new GraphSourceItemPos(this, 0)); + value.moreSrc.add(new GraphSourceItemPos(this, 0)); boolean define = !variables.containsKey("__register" + registerNumber); - variables.put("__register" + registerNumber, item); - if (item instanceof DirectValueTreeItem) { - if (((DirectValueTreeItem) item).value instanceof RegisterNumber) { - if (((RegisterNumber) ((DirectValueTreeItem) item).value).number == registerNumber) { - stack.push(item); + variables.put("__register" + registerNumber, value); + if (value instanceof DirectValueTreeItem) { + if (((DirectValueTreeItem) value).value instanceof RegisterNumber) { + if (((RegisterNumber) ((DirectValueTreeItem) value).value).number == registerNumber) { + stack.push(value); return; } } } - if (item instanceof StoreRegisterTreeItem) { - if (((StoreRegisterTreeItem) item).register.number == registerNumber) { - stack.push(item); + if (value instanceof StoreRegisterTreeItem) { + if (((StoreRegisterTreeItem) value).register.number == registerNumber) { + stack.push(value); return; } } - stack.push(new StoreRegisterTreeItem(this, rn, item, define)); + + if (value instanceof IncrementTreeItem) { + GraphTargetItem obj = ((IncrementTreeItem) value).object; + if (!stack.isEmpty()) { + if (stack.peek().equals(obj)) { + stack.pop(); + stack.push(new PostIncrementTreeItem(this, obj)); + return; + } + } + } + if (value instanceof DecrementTreeItem) { + GraphTargetItem obj = ((DecrementTreeItem) value).object; + if (!stack.isEmpty()) { + if (stack.peek().equals(obj)) { + stack.pop(); + stack.push(new PostDecrementTreeItem(this, obj)); + stack.push(obj); + return; + } + } + } + stack.push(new StoreRegisterTreeItem(this, rn, value, define)); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/flv/FLVOutputStream.java b/trunk/src/com/jpexs/decompiler/flash/flv/FLVOutputStream.java index 4e1e9479a..735696473 100644 --- a/trunk/src/com/jpexs/decompiler/flash/flv/FLVOutputStream.java +++ b/trunk/src/com/jpexs/decompiler/flash/flv/FLVOutputStream.java @@ -188,8 +188,7 @@ public class FLVOutputStream extends OutputStream { writeSCRIPTDATASTRING((String) v.value); break; case 3: - @SuppressWarnings("unchecked") - List objects = (List) v.value; + @SuppressWarnings("unchecked") List objects = (List) v.value; for (SCRIPTDATAOBJECT o : objects) { writeSCRIPTDATAOBJECT(o); } @@ -208,8 +207,7 @@ public class FLVOutputStream extends OutputStream { writeUI16((int) (Integer) v.value); break; case 8: - @SuppressWarnings("unchecked") - List variables = (List) v.value; + @SuppressWarnings("unchecked") List variables = (List) v.value; writeUI32(variables.size()); for (SCRIPTDATAVARIABLE var : variables) { writeSCRIPTDATAVARIABLE(var); @@ -220,8 +218,7 @@ public class FLVOutputStream extends OutputStream { //reserved break; case 10: - @SuppressWarnings("unchecked") - List stvariables = (List) v.value; + @SuppressWarnings("unchecked") List stvariables = (List) v.value; writeUI32(stvariables.size()); for (SCRIPTDATAVARIABLE var : stvariables) { writeSCRIPTDATAVARIABLE(var); diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/DoWhileItem.java b/trunk/src/com/jpexs/decompiler/flash/graph/DoWhileItem.java index 05e3ecb7f..9c79cb1a9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/DoWhileItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/DoWhileItem.java @@ -57,7 +57,7 @@ public class DoWhileItem extends LoopItem implements Block { if (expression.get(i).isEmpty()) { continue; } - if (i > 0) { + if (!expStr.equals("")) { expStr += ", "; } expStr += expression.get(i).toString(localData); diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/ForTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/graph/ForTreeItem.java index 3a1576145..1d4783cf9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/ForTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/ForTreeItem.java @@ -55,20 +55,31 @@ public class ForTreeItem extends LoopItem implements Block { String ret = ""; ret += "loop" + loop.id + ":\r\n"; ret += hilight("for("); + int p = 0; for (int i = 0; i < firstCommands.size(); i++) { - if (i > 0) { + if (firstCommands.get(i).isEmpty()) { + continue; + } + + if (p > 0) { ret += ","; } ret += stripSemicolon(firstCommands.get(i).toString(localData)); + p++; } ret += ";"; ret += expression.toString(localData); ret += ";"; + p = 0; for (int i = 0; i < finalCommands.size(); i++) { - if (i > 0) { + if (finalCommands.get(i).isEmpty()) { + continue; + } + if (p > 0) { ret += ","; } ret += stripSemicolon(finalCommands.get(i).toString(localData)); + p++; } ret += hilight(")") + "\r\n{\r\n"; for (GraphTargetItem ti : commands) { diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java b/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java index ce6749ff2..bdf52d7a1 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java @@ -479,6 +479,32 @@ public class Graph { items.add(new MarkItem("finish")); } + private static GraphTargetItem getLastNoEnd(List list) { + if (list.isEmpty()) { + return null; + } + if (list.get(list.size() - 1) instanceof ScriptEndItem) { + if (list.size() >= 2) { + return list.get(list.size() - 2); + } + return list.get(list.size() - 1); + } + return list.get(list.size() - 1); + } + + private static void removeLastNoEnd(List list) { + if (list.isEmpty()) { + return; + } + if (list.get(list.size() - 1) instanceof ScriptEndItem) { + if (list.size() >= 2) { + list.remove(list.size() - 2); + } + return; + } + list.remove(list.size() - 1); + } + protected List printGraph(List visited, List localData, Stack stack, List allParts, GraphPart parent, GraphPart part, GraphPart stopPart, List loops, HashMap> forFinalCommands) { if (visited.contains(part)) { //return new ArrayList(); @@ -1013,9 +1039,9 @@ public class Graph { List newBody = new ArrayList(); List nextcmds = new ArrayList(); - if ((!loopBody.isEmpty()) && (loopBody.get(loopBody.size() - 1) instanceof IfItem)) { - IfItem ift = (IfItem) loopBody.get(loopBody.size() - 1); - if ((!ift.onFalse.isEmpty()) && ((ift.onFalse.get(ift.onFalse.size() - 1) instanceof ExitItem) || ((ift.onFalse.get(ift.onFalse.size() - 1) instanceof MarkItem) && ((MarkItem) (ift.onFalse.get(ift.onFalse.size() - 1))).getMark().equals("finish")))) {//((ift.onFalse.size() == 1) && (ift.onFalse.get(0) instanceof ContinueItem) && (((ContinueItem) ift.onFalse.get(0)).loopId == currentLoop.id))) { + if (getLastNoEnd(loopBody) instanceof IfItem) { + IfItem ift = (IfItem) getLastNoEnd(loopBody); + if (getLastNoEnd(ift.onTrue) instanceof ContinueItem) {//||)))/*(getLastNoEnd(ift.onFalse)!=null) && */(!(getLastNoEnd(ift.onFalse) instanceof ContinueItem))){ //((ift.onFalse.get(ift.onFalse.size() - 1) instanceof ExitItem) || ((ift.onFalse.get(ift.onFalse.size() - 1) instanceof MarkItem) && ((MarkItem) (ift.onFalse.get(ift.onFalse.size() - 1))).getMark().equals("finish")))) {//((ift.onFalse.size() == 1) && (ift.onFalse.get(0) instanceof ContinueItem) && (((ContinueItem) ift.onFalse.get(0)).loopId == currentLoop.id))) { if (ift.expression != null) { expr = ift.expression; /*if (expr instanceof LogicalOpItem) { @@ -1027,8 +1053,8 @@ public class Graph { nextcmds = ift.onFalse; newBody = ift.onTrue; - loopBody.remove(loopBody.size() - 1); - } else if ((!ift.onTrue.isEmpty()) && ((ift.onTrue.get(ift.onTrue.size() - 1) instanceof ExitItem) || ((ift.onTrue.get(ift.onTrue.size() - 1) instanceof MarkItem) && ((MarkItem) (ift.onTrue.get(ift.onTrue.size() - 1))).getMark().equals("finish")))) {//((ift.onTrue.size() == 1) && (ift.onTrue.get(0) instanceof ContinueItem) && (((ContinueItem) ift.onTrue.get(0)).loopId == currentLoop.id))) { + removeLastNoEnd(loopBody); + } else { //if (/*(getLastNoEnd(ift.onTrue)!=null) &&*/((!(getLastNoEnd(ift.onTrue) instanceof ContinueItem)))) { //((ift.onTrue.get(ift.onTrue.size() - 1) instanceof ExitItem) || ((ift.onTrue.get(ift.onTrue.size() - 1) instanceof MarkItem) && ((MarkItem) (ift.onTrue.get(ift.onTrue.size() - 1))).getMark().equals("finish")))) {//((ift.onTrue.size() == 1) && (ift.onTrue.get(0) instanceof ContinueItem) && (((ContinueItem) ift.onTrue.get(0)).loopId == currentLoop.id))) { if (ift.expression != null) { expr = ift.expression; if (expr instanceof LogicalOpItem) { @@ -1039,18 +1065,20 @@ public class Graph { } newBody = ift.onFalse; nextcmds = ift.onTrue; - loopBody.remove(loopBody.size() - 1); + removeLastNoEnd(loopBody); if (newBody.isEmpty()) { //addIf.addAll(loopBody); } } } - checkContinueAtTheEnd(newBody, currentLoop); - if ((!newBody.isEmpty()) && (!(newBody.get(0) instanceof ScriptEndItem))) { // && (addIf.get(addIf.size() - 1) instanceof ContinueItem) && (((ContinueItem) addIf.get(addIf.size() - 1)).loopId == currentLoop.id)) { + + if ((!newBody.isEmpty()) && (newBody.get(newBody.size() - 1) instanceof ContinueItem)) {//(!(newBody.get(0) instanceof ScriptEndItem))) { // && (addIf.get(addIf.size() - 1) instanceof ContinueItem) && (((ContinueItem) addIf.get(addIf.size() - 1)).loopId == currentLoop.id)) { + checkContinueAtTheEnd(newBody, currentLoop); loopBody.add(expr); ret.add(new WhileItem(null, currentLoop, loopBody, newBody)); ret.addAll(nextcmds); } else { + checkContinueAtTheEnd(newBody, currentLoop); List ex = new ArrayList(); ex.add(expr); ret.add(new DoWhileItem(null, currentLoop, loopBody, ex)); diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/WhileItem.java b/trunk/src/com/jpexs/decompiler/flash/graph/WhileItem.java index 8e203f1f4..957dadef0 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/WhileItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/WhileItem.java @@ -46,7 +46,7 @@ public class WhileItem extends LoopItem implements Block { if (expression.get(i).isEmpty()) { continue; } - if (i > 0) { + if (!expStr.equals("")) { expStr += ", "; } expStr += expression.get(i).toString(localData); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/proxy/ProxyFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/proxy/ProxyFrame.java index 1220e8570..d61c1fa09 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/proxy/ProxyFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/proxy/ProxyFrame.java @@ -74,7 +74,7 @@ public class ProxyFrame extends JFrame implements ActionListener, CatchedListene @SuppressWarnings("unchecked") public ProxyFrame() { - listModel = new SWFListModel(Configuration.getReplacements()); + listModel = new SWFListModel(Configuration.getReplacements()); swfList = new JList(listModel); swfList.addMouseListener(this); swfList.setFont(new Font("Monospaced", Font.PLAIN, 12));