From c63fd4ebd95f91908ddfd0cc91494464d77ccb6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Wed, 31 Jul 2013 22:21:50 +0200 Subject: [PATCH] Issue #258 AS1/2 chained assignments AS1/2 Detecting temporary registers assignment spaces --- .../flash/abc/avm2/graph/AVM2Graph.java | 2 +- .../abc/avm2/model/InitPropertyAVM2Item.java | 2 +- .../abc/avm2/model/SetLocalAVM2Item.java | 2 +- .../abc/avm2/model/SetPropertyAVM2Item.java | 2 +- .../flash/abc/avm2/model/SetSlotAVM2Item.java | 2 +- .../abc/avm2/model/SetSuperAVM2Item.java | 2 +- .../decompiler/flash/action/ActionGraph.java | 11 +++- .../action/model/DecrementActionItem.java | 2 +- .../action/model/DefineLocalActionItem.java | 3 + .../action/model/IncrementActionItem.java | 2 +- .../action/model/SetMemberActionItem.java | 4 +- .../action/model/SetPropertyActionItem.java | 4 +- .../action/model/SetVariableActionItem.java | 2 +- .../action/model/StoreRegisterActionItem.java | 2 +- .../flash/action/model/TemporaryRegister.java | 63 +++++++++++++++++++ .../flash/action/swf4/ActionPush.java | 10 ++- .../flash/action/swf4/ActionSetProperty.java | 32 +++++++++- .../flash/action/swf4/ActionSetVariable.java | 33 +++++++++- .../flash/action/swf5/ActionSetMember.java | 27 +++++++- .../action/swf5/ActionStoreRegister.java | 6 ++ .../src/com/jpexs/decompiler/graph/Graph.java | 10 +-- 21 files changed, 193 insertions(+), 30 deletions(-) create mode 100644 trunk/src/com/jpexs/decompiler/flash/action/model/TemporaryRegister.java diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java index bc322f220..114141351 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java @@ -640,7 +640,7 @@ public class AVM2Graph extends Graph { } @Override - protected void finalProcess(List list, int level) { + protected void finalProcess(List list, int level, List localData) { if (level == 0) { if (!list.isEmpty()) { if (list.get(list.size() - 1) instanceof ReturnVoidAVM2Item) { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/InitPropertyAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/InitPropertyAVM2Item.java index 3e6f3abc9..b8276691f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/InitPropertyAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/InitPropertyAVM2Item.java @@ -38,7 +38,7 @@ public class InitPropertyAVM2Item extends AVM2Item implements SetTypeAVM2Item, A @Override public String toString(ConstantPool constants, HashMap localRegNames, List fullyQualifiedNames) { - return formatProperty(constants, object, propertyName, localRegNames, fullyQualifiedNames) + hilight("=") + value.toString(constants, localRegNames, fullyQualifiedNames); + return formatProperty(constants, object, propertyName, localRegNames, fullyQualifiedNames) + hilight(" = ") + value.toString(constants, localRegNames, fullyQualifiedNames); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/SetLocalAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/SetLocalAVM2Item.java index 61bcece5a..57ad8a23b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/SetLocalAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/SetLocalAVM2Item.java @@ -36,7 +36,7 @@ public class SetLocalAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assig @Override public String toString(ConstantPool constants, HashMap localRegNames, List fullyQualifiedNames) { - return hilight(localRegName(localRegNames, regIndex) + "=") + value.toString(constants, localRegNames, fullyQualifiedNames); + return hilight(localRegName(localRegNames, regIndex) + " = ") + value.toString(constants, localRegNames, fullyQualifiedNames); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/SetPropertyAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/SetPropertyAVM2Item.java index efc8a7dae..5c7b11e1a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/SetPropertyAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/SetPropertyAVM2Item.java @@ -44,7 +44,7 @@ public class SetPropertyAVM2Item extends AVM2Item implements SetTypeAVM2Item, As @Override public String toString(ConstantPool constants, HashMap localRegNames, List fullyQualifiedNames) { - return formatProperty(constants, object, propertyName, localRegNames, fullyQualifiedNames) + hilight("=") + value.toString(constants, localRegNames, fullyQualifiedNames); + return formatProperty(constants, object, propertyName, localRegNames, fullyQualifiedNames) + hilight(" = ") + value.toString(constants, localRegNames, fullyQualifiedNames); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSlotAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSlotAVM2Item.java index 8c0e65ffb..e7e4c0c52 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSlotAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSlotAVM2Item.java @@ -46,7 +46,7 @@ public class SetSlotAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assign @Override public String toString(ConstantPool constants, HashMap localRegNames, List fullyQualifiedNames) { - return getName(constants, localRegNames, fullyQualifiedNames) + hilight("=") + value.toString(constants, localRegNames, fullyQualifiedNames); + return getName(constants, localRegNames, fullyQualifiedNames) + hilight(" = ") + value.toString(constants, localRegNames, fullyQualifiedNames); } public String getName(ConstantPool constants, HashMap localRegNames, List fullyQualifiedNames) { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSuperAVM2Item.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSuperAVM2Item.java index 1e0acf465..5b0b197d6 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSuperAVM2Item.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/model/SetSuperAVM2Item.java @@ -48,7 +48,7 @@ public class SetSuperAVM2Item extends AVM2Item { if (Highlighting.stripHilights(calee).equals("this.")) { calee = ""; } - return calee + hilight("super.") + propertyName.toString(constants, localRegNames, fullyQualifiedNames) + hilight("=") + value.toString(constants, localRegNames, fullyQualifiedNames); + return calee + hilight("super.") + propertyName.toString(constants, localRegNames, fullyQualifiedNames) + hilight(" = ") + value.toString(constants, localRegNames, fullyQualifiedNames); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/ActionGraph.java b/trunk/src/com/jpexs/decompiler/flash/action/ActionGraph.java index 54ffee0e6..25600886c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/ActionGraph.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/ActionGraph.java @@ -48,7 +48,9 @@ import com.jpexs.decompiler.graph.model.SwitchItem; import com.jpexs.decompiler.graph.model.WhileItem; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.Stack; /** @@ -92,7 +94,13 @@ public class ActionGraph extends Graph { } @Override - protected void finalProcess(List list, int level) { + protected void finalProcess(List list, int level, List localData) { + + if (localData.isEmpty()) { + localData.add(new HashSet()); //List of temporaryRegisters + } + @SuppressWarnings("unchecked") + Set temporaryRegisters = (HashSet) localData.get(0); List ret = Action.checkClass(list); if (ret != list) { list.clear(); @@ -184,6 +192,7 @@ public class ActionGraph extends Graph { } } + //detectChained(list, temporaryRegisters); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/model/DecrementActionItem.java b/trunk/src/com/jpexs/decompiler/flash/action/model/DecrementActionItem.java index 3eb385476..25366e322 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/model/DecrementActionItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/model/DecrementActionItem.java @@ -42,7 +42,7 @@ public class DecrementActionItem extends ActionItem { @Override public String toString(ConstantPool constants) { - return object.toString(constants) + hilight("-1"); + return object.toString(constants) + hilight(" - 1"); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/model/DefineLocalActionItem.java b/trunk/src/com/jpexs/decompiler/flash/action/model/DefineLocalActionItem.java index c81c9baa3..6a5ca1832 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/model/DefineLocalActionItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/model/DefineLocalActionItem.java @@ -34,6 +34,9 @@ public class DefineLocalActionItem extends ActionItem implements SetTypeActionIt public List getAllSubItems() { List ret = new ArrayList<>(); ret.add(name); + if (value != null) { + ret.add(value); + } return ret; } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/model/IncrementActionItem.java b/trunk/src/com/jpexs/decompiler/flash/action/model/IncrementActionItem.java index 2e70c0cb7..50b5f50c7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/model/IncrementActionItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/model/IncrementActionItem.java @@ -42,7 +42,7 @@ public class IncrementActionItem extends ActionItem { @Override public String toString(ConstantPool constants) { - return object.toString(constants) + hilight("+1"); + return object.toString(constants) + hilight(" + 1"); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/model/SetMemberActionItem.java b/trunk/src/com/jpexs/decompiler/flash/action/model/SetMemberActionItem.java index 6efbb9d81..d0f2212eb 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/model/SetMemberActionItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/model/SetMemberActionItem.java @@ -79,9 +79,9 @@ public class SetMemberActionItem extends ActionItem implements SetTypeActionItem public String toString(ConstantPool constants) { if (!((objectName instanceof DirectValueActionItem) && (((DirectValueActionItem) objectName).value instanceof String))) { //if(!(functionName instanceof GetVariableActionItem)) - return object.toString(constants) + "[" + stripQuotes(objectName, constants) + "]" + "=" + value.toString(constants); + return object.toString(constants) + "[" + stripQuotes(objectName, constants) + "]" + " = " + value.toString(constants); } - return object.toString(constants) + "." + stripQuotes(objectName, constants) + "=" + value.toString(constants); + return object.toString(constants) + "." + stripQuotes(objectName, constants) + " = " + value.toString(constants); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/model/SetPropertyActionItem.java b/trunk/src/com/jpexs/decompiler/flash/action/model/SetPropertyActionItem.java index 19fec3ba9..8155805aa 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/model/SetPropertyActionItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/model/SetPropertyActionItem.java @@ -70,9 +70,9 @@ public class SetPropertyActionItem extends ActionItem implements SetTypeActionIt @Override public String toString(ConstantPool constants) { if (isEmptyString(target)) { - return hilight(Action.propertyNames[propertyIndex] + "=") + value.toString(constants); + return hilight(Action.propertyNames[propertyIndex] + " = ") + value.toString(constants); } - return target.toString(constants) + hilight("." + Action.propertyNames[propertyIndex] + "=") + value.toString(constants); + return target.toString(constants) + hilight("." + Action.propertyNames[propertyIndex] + " = ") + value.toString(constants); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/model/SetVariableActionItem.java b/trunk/src/com/jpexs/decompiler/flash/action/model/SetVariableActionItem.java index 198bcf87b..424446faf 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/model/SetVariableActionItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/model/SetVariableActionItem.java @@ -67,7 +67,7 @@ public class SetVariableActionItem extends ActionItem implements SetTypeActionIt @Override public String toString(ConstantPool constants) { if (name instanceof DirectValueActionItem || name instanceof GetVariableActionItem) { - return stripQuotes(name, constants) + hilight("=") + value.toString(constants); + return stripQuotes(name, constants) + hilight(" = ") + value.toString(constants); } else { return hilight("set(") + name.toString(constants) + hilight(",") + value.toString(constants) + hilight(")"); } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/model/StoreRegisterActionItem.java b/trunk/src/com/jpexs/decompiler/flash/action/model/StoreRegisterActionItem.java index eacdae1b9..d838d0e32 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/model/StoreRegisterActionItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/model/StoreRegisterActionItem.java @@ -65,7 +65,7 @@ public class StoreRegisterActionItem extends ActionItem implements SetTypeAction @Override public String toString(ConstantPool constants) { - return (define ? hilight("var ") : "") + hilight(register.translate() + "=") + value.toString(constants); + return (define ? hilight("var ") : "") + hilight(register.translate() + " = ") + value.toString(constants); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/model/TemporaryRegister.java b/trunk/src/com/jpexs/decompiler/flash/action/model/TemporaryRegister.java new file mode 100644 index 000000000..ceef5ea86 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/action/model/TemporaryRegister.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2013 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.action.model; + +import com.jpexs.decompiler.graph.GraphSourceItemPos; +import com.jpexs.decompiler.graph.GraphTargetItem; +import java.util.List; + +/** + * + * @author JPEXS + */ +public class TemporaryRegister extends GraphTargetItem { + + public TemporaryRegister(GraphTargetItem value) { + super(value.src, value.precedence); + this.value = value; + } + + @Override + public String toString(List localData) { + return value.toString(localData); + } + + @Override + public boolean hasReturnValue() { + return value.hasReturnValue(); + } + + @Override + public Object getResult() { + return value.getResult(); + } + + @Override + public List getAllSubItems() { + return value.getAllSubItems(); + } + + @Override + public List getNeededSources() { + return value.getNeededSources(); + } + + @Override + public GraphTargetItem getNotCoerced() { + return value.getNotCoerced(); + } +} diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java index 521816933..9cb0356a6 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java @@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.model.DirectValueActionItem; +import com.jpexs.decompiler.flash.action.model.TemporaryRegister; import com.jpexs.decompiler.flash.action.parser.ParseException; import com.jpexs.decompiler.flash.action.parser.pcode.ASMParsedSymbol; import com.jpexs.decompiler.flash.action.parser.pcode.FlasmLexer; @@ -347,13 +348,18 @@ public class ActionPush extends Action { } }*/ DirectValueActionItem dvt = new DirectValueActionItem(this, pos, o, constantPool); - stack.push(dvt); - if (o instanceof RegisterNumber) { + + if (o instanceof RegisterNumber) {//TemporaryRegister dvt.computedRegValue = variables.get("__register" + ((RegisterNumber) o).number); if (regNames.containsKey(((RegisterNumber) o).number)) { ((RegisterNumber) o).name = regNames.get(((RegisterNumber) o).number); } } + if (dvt.computedRegValue instanceof TemporaryRegister) { + stack.push(((TemporaryRegister) dvt.computedRegValue).value); + } else { + stack.push(dvt); + } pos++; } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionSetProperty.java b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionSetProperty.java index c4b770f6f..6ad42a3c4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionSetProperty.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionSetProperty.java @@ -19,11 +19,15 @@ package com.jpexs.decompiler.flash.action.swf4; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.model.DecrementActionItem; import com.jpexs.decompiler.flash.action.model.DirectValueActionItem; +import com.jpexs.decompiler.flash.action.model.GetPropertyActionItem; import com.jpexs.decompiler.flash.action.model.IncrementActionItem; import com.jpexs.decompiler.flash.action.model.PostDecrementActionItem; import com.jpexs.decompiler.flash.action.model.PostIncrementActionItem; import com.jpexs.decompiler.flash.action.model.SetPropertyActionItem; import com.jpexs.decompiler.flash.action.model.StoreRegisterActionItem; +import com.jpexs.decompiler.flash.action.model.TemporaryRegister; +import com.jpexs.decompiler.flash.action.model.operations.PreDecrementActionItem; +import com.jpexs.decompiler.flash.action.model.operations.PreIncrementActionItem; import com.jpexs.decompiler.graph.GraphTargetItem; import java.util.HashMap; import java.util.List; @@ -61,7 +65,7 @@ public class ActionSetProperty extends Action { } } } - if (value instanceof DecrementActionItem) { + if (value.getThroughDuplicate() instanceof DecrementActionItem) { GraphTargetItem obj = ((DecrementActionItem) value).object; if (!stack.isEmpty()) { if (stack.peek().valueEquals(obj)) { @@ -71,9 +75,31 @@ public class ActionSetProperty extends Action { } } } + + GraphTargetItem ret = new SetPropertyActionItem(this, target, indexInt, value); + if (value instanceof StoreRegisterActionItem) { - ((StoreRegisterActionItem) value).define = false; + StoreRegisterActionItem sr = (StoreRegisterActionItem) value; + if (sr.define) { + value = sr.getValue(); + ((SetPropertyActionItem) ret).setValue(value); + if (value instanceof IncrementActionItem) { + if (((IncrementActionItem) value).object instanceof GetPropertyActionItem) { + if (((GetPropertyActionItem) ((IncrementActionItem) value).object).valueEquals(((SetPropertyActionItem) ret).getObject())) { + ret = new PreIncrementActionItem(this, ((IncrementActionItem) value).object); + } + } + } else if (value instanceof DecrementActionItem) { + if (((DecrementActionItem) value).object instanceof GetPropertyActionItem) { + if (((GetPropertyActionItem) ((DecrementActionItem) value).object).valueEquals(((SetPropertyActionItem) ret).getObject())) { + ret = new PreDecrementActionItem(this, ((DecrementActionItem) value).object); + } + } + } + variables.put("__register" + sr.register.number, new TemporaryRegister(ret)); + return; + } } - output.add(new SetPropertyActionItem(this, target, indexInt, value)); + output.add(ret); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionSetVariable.java b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionSetVariable.java index 8d2102d6e..2130f7c05 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionSetVariable.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionSetVariable.java @@ -25,6 +25,9 @@ import com.jpexs.decompiler.flash.action.model.PostDecrementActionItem; import com.jpexs.decompiler.flash.action.model.PostIncrementActionItem; import com.jpexs.decompiler.flash.action.model.SetVariableActionItem; import com.jpexs.decompiler.flash.action.model.StoreRegisterActionItem; +import com.jpexs.decompiler.flash.action.model.TemporaryRegister; +import com.jpexs.decompiler.flash.action.model.operations.PreDecrementActionItem; +import com.jpexs.decompiler.flash.action.model.operations.PreIncrementActionItem; import com.jpexs.decompiler.flash.helpers.Highlighting; import com.jpexs.decompiler.graph.GraphTargetItem; import java.util.HashMap; @@ -83,10 +86,34 @@ public class ActionSetVariable extends Action { } } } + + GraphTargetItem ret = new SetVariableActionItem(this, name, value); + if (value instanceof StoreRegisterActionItem) { - ((StoreRegisterActionItem) value).define = false; + StoreRegisterActionItem sr = (StoreRegisterActionItem) value; + if (sr.define) { + value = sr.getValue(); + ((SetVariableActionItem) ret).setValue(value); + if (value instanceof IncrementActionItem) { + if (((IncrementActionItem) value).object instanceof GetVariableActionItem) { + if (((GetVariableActionItem) ((IncrementActionItem) value).object).name.valueEquals(name)) { + ret = new PreIncrementActionItem(this, ((IncrementActionItem) value).object); + } + } + } else if (value instanceof DecrementActionItem) { + if (((DecrementActionItem) value).object instanceof GetVariableActionItem) { + if (((GetVariableActionItem) ((DecrementActionItem) value).object).name.valueEquals(name)) { + ret = new PreDecrementActionItem(this, ((DecrementActionItem) value).object); + } + } + } + + + variables.put("__register" + sr.register.number, new TemporaryRegister(ret)); + return; + } } - SetVariableActionItem svt = new SetVariableActionItem(this, name, value); - output.add(svt); + + output.add(ret); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionSetMember.java b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionSetMember.java index 0ea33b051..4fe3354dd 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionSetMember.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionSetMember.java @@ -24,6 +24,9 @@ import com.jpexs.decompiler.flash.action.model.PostDecrementActionItem; import com.jpexs.decompiler.flash.action.model.PostIncrementActionItem; import com.jpexs.decompiler.flash.action.model.SetMemberActionItem; import com.jpexs.decompiler.flash.action.model.StoreRegisterActionItem; +import com.jpexs.decompiler.flash.action.model.TemporaryRegister; +import com.jpexs.decompiler.flash.action.model.operations.PreDecrementActionItem; +import com.jpexs.decompiler.flash.action.model.operations.PreIncrementActionItem; import com.jpexs.decompiler.graph.GraphTargetItem; import java.util.HashMap; import java.util.List; @@ -86,9 +89,29 @@ public class ActionSetMember extends Action { } } } + GraphTargetItem ret = new SetMemberActionItem(this, object, memberName, value); if (value instanceof StoreRegisterActionItem) { - ((StoreRegisterActionItem) value).define = false; + StoreRegisterActionItem sr = (StoreRegisterActionItem) value; + if (sr.define) { + value = sr.getValue(); + ((SetMemberActionItem) ret).setValue(value); + if (value instanceof IncrementActionItem) { + if (((IncrementActionItem) value).object instanceof GetMemberActionItem) { + if (((GetMemberActionItem) ((IncrementActionItem) value).object).valueEquals(((SetMemberActionItem) ret).getObject())) { + ret = new PreIncrementActionItem(this, ((IncrementActionItem) value).object); + } + } + } else if (value instanceof DecrementActionItem) { + if (((DecrementActionItem) value).object instanceof GetMemberActionItem) { + if (((GetMemberActionItem) ((DecrementActionItem) value).object).valueEquals(((SetMemberActionItem) ret).getObject())) { + ret = new PreDecrementActionItem(this, ((DecrementActionItem) value).object); + } + } + } + variables.put("__register" + sr.register.number, new TemporaryRegister(ret)); + return; + } } - output.add(new SetMemberActionItem(this, object, memberName, value)); + output.add(ret); } } 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 e7b38dfe5..dc15c2392 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionStoreRegister.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionStoreRegister.java @@ -25,6 +25,7 @@ import com.jpexs.decompiler.flash.action.model.IncrementActionItem; import com.jpexs.decompiler.flash.action.model.PostDecrementActionItem; import com.jpexs.decompiler.flash.action.model.PostIncrementActionItem; import com.jpexs.decompiler.flash.action.model.StoreRegisterActionItem; +import com.jpexs.decompiler.flash.action.model.TemporaryRegister; 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; @@ -80,6 +81,11 @@ public class ActionStoreRegister extends Action { rn.name = regNames.get(registerNumber); } value.moreSrc.add(new GraphSourceItemPos(this, 0)); + if (variables.containsKey("__register" + registerNumber)) { + if (variables.get("__register" + registerNumber) instanceof TemporaryRegister) { + variables.remove("__register" + registerNumber); + } + } boolean define = !variables.containsKey("__register" + registerNumber); if (regNames.containsKey(registerNumber)) { define = false; diff --git a/trunk/src/com/jpexs/decompiler/graph/Graph.java b/trunk/src/com/jpexs/decompiler/graph/Graph.java index c43c2dd9a..93c4bfc6d 100644 --- a/trunk/src/com/jpexs/decompiler/graph/Graph.java +++ b/trunk/src/com/jpexs/decompiler/graph/Graph.java @@ -578,7 +578,7 @@ public class Graph { List ret = printGraph(new ArrayList(), localData, stack, allParts, null, heads.get(0), null, loops, staticOperation, path); processIfs(ret); finalProcessStack(stack, ret); - finalProcessAll(ret, 0); + finalProcessAll(ret, 0, new ArrayList<>()); return ret; @@ -587,19 +587,19 @@ public class Graph { public void finalProcessStack(Stack stack, List output) { } - private void finalProcessAll(List list, int level) { - finalProcess(list, level); + private void finalProcessAll(List list, int level, List localData) { + finalProcess(list, level, localData); for (GraphTargetItem item : list) { if (item instanceof Block) { List> subs = ((Block) item).getSubs(); for (List sub : subs) { - finalProcessAll(sub, level + 1); + finalProcessAll(sub, level + 1, localData); } } } } - protected void finalProcess(List list, int level) { + protected void finalProcess(List list, int level, List localData) { } private void processIfs(List list) {