diff --git a/CHANGELOG.md b/CHANGELOG.md index fcf176c75..90708336b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,8 @@ All notable changes to this project will be documented in this file. - AS1/2 - switch with nontrivial expressions like and/or,ternar (second pass) - AS1/2 - ifFrameLoaded with nontrivial items inside - AS1/2 - (mb)length is expressioncommand, not a command +- AS1/2 - get/set top level properties +- AS1/2 - properties postincrement ## [14.6.0] - 2021-11-22 ### Added diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java index 48eb8c6e1..34ef2bb57 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java @@ -158,6 +158,14 @@ public abstract class Action implements GraphSourceItem { public static final List propertyNamesList = Arrays.asList(propertyNames); + public static final List propertyNamesListLowerCase = new ArrayList<>(); + + { + for (String s : propertyNamesList) { + propertyNamesListLowerCase.add(s.toLowerCase()); + } + } + private static final Logger logger = Logger.getLogger(Action.class.getName()); /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GetPropertyActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GetPropertyActionItem.java index bb8568713..2fe923793 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GetPropertyActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GetPropertyActionItem.java @@ -56,16 +56,16 @@ public class GetPropertyActionItem extends ActionItem { @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { - /*if (isEmptyString(target)) { + if (isEmptyString(target)) { return writer.append(Action.propertyNames[propertyIndex]); - }*/ + } - if (!useGetPropertyFunction && !isEmptyString(target)) { + /*if (!useGetPropertyFunction) { target.appendToNoQuotes(writer, localData); writer.append(":"); writer.append(Action.propertyNames[propertyIndex]); return writer; - } + }*/ writer.append("getProperty"); writer.spaceBeforeCallParenthesies(2); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/SetPropertyActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/SetPropertyActionItem.java index fa1b4f561..35d5d89f2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/SetPropertyActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/SetPropertyActionItem.java @@ -79,10 +79,10 @@ public class SetPropertyActionItem extends ActionItem implements SetTypeActionIt @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { - /*if (isEmptyString(target)) { + if (isEmptyString(target)) { writer.append(Action.propertyNames[propertyIndex]).append(" = "); return value.toString(writer, localData); - }*/ + } writer.append("setProperty"); writer.spaceBeforeCallParenthesies(3); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java index f85df1670..68703c71f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java @@ -2034,13 +2034,13 @@ public class ActionScript2Parser { if (var.getVariableName().equals("getProperty") && args.size() == 2 && (args.get(1) instanceof VariableActionItem) - && (Action.propertyNamesList.contains(((VariableActionItem) args.get(1)).getVariableName()))) { - ret = new GetPropertyActionItem(null, null, args.get(0), Action.propertyNamesList.indexOf(((VariableActionItem) args.get(1)).getVariableName())); + && (Action.propertyNamesListLowerCase.contains(((VariableActionItem) args.get(1)).getVariableName().toLowerCase()))) { + ret = new GetPropertyActionItem(null, null, args.get(0), Action.propertyNamesListLowerCase.indexOf(((VariableActionItem) args.get(1)).getVariableName().toLowerCase())); } else if (var.getVariableName().equals("setProperty") && args.size() == 3 && (args.get(1) instanceof VariableActionItem) - && (Action.propertyNamesList.contains(((VariableActionItem) args.get(1)).getVariableName()))) { - ret = new SetPropertyActionItem(null, null, args.get(0), Action.propertyNamesList.indexOf(((VariableActionItem) args.get(1)).getVariableName()), args.get(2)); + && (Action.propertyNamesListLowerCase.contains(((VariableActionItem) args.get(1)).getVariableName().toLowerCase()))) { + ret = new SetPropertyActionItem(null, null, args.get(0), Action.propertyNamesListLowerCase.indexOf(((VariableActionItem) args.get(1)).getVariableName().toLowerCase()), args.get(2)); } else { ret = new CallFunctionActionItem(null, null, var, args); } @@ -2287,18 +2287,7 @@ public class ActionScript2Parser { GraphTargetItem stored = v.getStoreValue(); int propIndex = -1; boolean hasSubVars = false; - if (varName.contains(":")) { - hasSubVars = true; - String lowerNameStr = varName.toLowerCase(); - for (int p = 0; p < Action.propertyNames.length; p++) { - String prop = Action.propertyNames[p]; - if (lowerNameStr.endsWith(":" + prop.toLowerCase())) { - propIndex = p; - varName = varName.substring(0, varName.lastIndexOf(":")); - break; - } - } - } + propIndex = Action.propertyNamesListLowerCase.indexOf(varName.toLowerCase()); if (v.isDefinition()) { if (hasSubVars) { throw new ActionParseException("Invalid : character in variable definition", lexer.yyline()); @@ -2306,13 +2295,13 @@ public class ActionScript2Parser { v.setBoxedValue(new DefineLocalActionItem(null, null, pushConst(varName), stored)); } else if (stored != null) { if (propIndex > -1) { - v.setBoxedValue(new SetPropertyActionItem(null, null, pushConst(varName), propIndex, stored)); + v.setBoxedValue(new SetPropertyActionItem(null, null, pushConst(""), propIndex, stored)); } else { v.setBoxedValue(new SetVariableActionItem(null, null, pushConst(varName), stored)); } } else if (propIndex > -1) { - v.setBoxedValue(new GetPropertyActionItem(null, null, pushConst(varName), propIndex)); + v.setBoxedValue(new GetPropertyActionItem(null, null, pushConst(""), propIndex)); } else { v.setBoxedValue(new GetVariableActionItem(null, null, pushConst(varName))); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionSetProperty.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionSetProperty.java index dab47a280..da214969e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionSetProperty.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionSetProperty.java @@ -106,6 +106,15 @@ public class ActionSetProperty extends Action { } stack.push(new PostIncrementActionItem(this, lineStartAction, obj)); return; + } else { + IncrementActionItem dec = (IncrementActionItem) value.getThroughDuplicate(); + if (dec.object instanceof GetPropertyActionItem) { + GetPropertyActionItem gp = (GetPropertyActionItem) dec.object; + if (gp.target.valueEquals(target) && gp.propertyIndex == indexInt) { + output.add(new PostIncrementActionItem(this, lineStartAction, gp)); + return; + } + } } } if (value.getThroughDuplicate() instanceof DecrementActionItem) { @@ -117,6 +126,15 @@ public class ActionSetProperty extends Action { } stack.push(new PostDecrementActionItem(this, lineStartAction, obj)); return; + } else { + DecrementActionItem dec = (DecrementActionItem) value.getThroughDuplicate(); + if (dec.object instanceof GetPropertyActionItem) { + GetPropertyActionItem gp = (GetPropertyActionItem) dec.object; + if (gp.target.valueEquals(target) && gp.propertyIndex == indexInt) { + output.add(new PostDecrementActionItem(this, lineStartAction, gp)); + return; + } + } } }