From 819fa7692ae9e2e99d850bf0007b26eec6850911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Thu, 25 Feb 2021 21:40:00 +0100 Subject: [PATCH] Fixed: #1169 AS1/2 direct editation - getmember after new operator --- CHANGELOG.md | 1 + .../parser/script/ActionScript2Parser.java | 58 +++++++++---------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc13ed649..8aa2099fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. - #1100, #1123, #1516 AS1/2/3 direct editation - comma operator - #1618 Export to PDF selectable text escaping and text size - #1101 AS3 direct editation - handling imported vars +- #1169 AS1/2 direct editation - getmember after new operator ### Changed - #1616 Close SWF menuitem is last in the context menu 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 af327aae0..c98fae6a9 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 @@ -1317,7 +1317,7 @@ public class ActionScript2Parser { List commaItems = new ArrayList<>(); ParsedSymbol symb; do { - GraphTargetItem prim = expressionPrimary(false, inFunction, inMethod, allowRemainder, variables, functions); + GraphTargetItem prim = expressionPrimary(false, inFunction, inMethod, allowRemainder, variables, functions, true); if (prim == null) { return null; } @@ -1397,7 +1397,7 @@ public class ActionScript2Parser { } } - rhs = expressionPrimary(allowRemainder, inFunction, inMethod, allowRemainder, variables, functions); + rhs = expressionPrimary(allowRemainder, inFunction, inMethod, allowRemainder, variables, functions, true); if (rhs == null) { lexer.pushback(op); break; @@ -1639,7 +1639,7 @@ public class ActionScript2Parser { return arrCnt; } - private GraphTargetItem expressionPrimary(boolean allowEmpty, boolean inFunction, boolean inMethod, boolean allowRemainder, List variables, List functions) throws IOException, ActionParseException { + private GraphTargetItem expressionPrimary(boolean allowEmpty, boolean inFunction, boolean inMethod, boolean allowRemainder, List variables, List functions, boolean allowCall) throws IOException, ActionParseException { if (debugMode) { System.out.println("primary:"); } @@ -1681,7 +1681,7 @@ public class ActionScript2Parser { break; case NEGATE: versionRequired(s, 5); - ret = expressionPrimary(false, inFunction, inMethod, false, variables, functions); + ret = expressionPrimary(false, inFunction, inMethod, false, variables, functions, true); ret = new BitXorActionItem(null, null, ret, new DirectValueActionItem(4.294967295E9)); break; @@ -1695,7 +1695,7 @@ public class ActionScript2Parser { } else { lexer.pushback(s); - GraphTargetItem num = expressionPrimary(false, inFunction, inMethod, true, variables, functions); + GraphTargetItem num = expressionPrimary(false, inFunction, inMethod, true, variables, functions, true); if ((num instanceof DirectValueActionItem) && (((DirectValueActionItem) num).value instanceof Long)) { ((DirectValueActionItem) num).value = -(Long) ((DirectValueActionItem) num).value; @@ -1719,7 +1719,7 @@ public class ActionScript2Parser { } break; case TYPEOF: - ret = new TypeOfActionItem(null, null, expressionPrimary(false, inFunction, inMethod, false, variables, functions)); + ret = new TypeOfActionItem(null, null, expressionPrimary(false, inFunction, inMethod, false, variables, functions, true)); allowMemberOrCall = true; break; case TRUE: @@ -1798,7 +1798,7 @@ public class ActionScript2Parser { break; case DELETE: - GraphTargetItem varDel = expressionPrimary(false, inFunction, inMethod, false, variables, functions); + GraphTargetItem varDel = expressionPrimary(false, inFunction, inMethod, false, variables, functions, true); if (varDel instanceof GetMemberActionItem) { GetMemberActionItem gm = (GetMemberActionItem) varDel; ret = new DeleteActionItem(null, null, gm.object, gm.memberName); @@ -1808,7 +1808,7 @@ public class ActionScript2Parser { break; case INCREMENT: case DECREMENT: //preincrement - GraphTargetItem prevar = expressionPrimary(false, inFunction, inMethod, false, variables, functions);//variable(inFunction, inMethod, variables, functions); + GraphTargetItem prevar = expressionPrimary(false, inFunction, inMethod, false, variables, functions, true);//variable(inFunction, inMethod, variables, functions); if (s.type == SymbolType.INCREMENT) { ret = new PreIncrementActionItem(null, null, prevar); } @@ -1818,7 +1818,7 @@ public class ActionScript2Parser { break; case NOT: - ret = new NotItem(null, null, expressionPrimary(false, inFunction, inMethod, false, variables, functions)); + ret = new NotItem(null, null, expressionPrimary(false, inFunction, inMethod, false, variables, functions, true)); break; case PARENT_OPEN: @@ -1828,31 +1828,28 @@ public class ActionScript2Parser { allowMemberOrCall = true; break; case NEW: - GraphTargetItem newvar = expressionPrimary(false, inFunction, inMethod, false, variables, functions);//variable(inFunction, inMethod, variables, functions); - if (newvar instanceof CastOpActionItem) { - List args = new ArrayList<>(); - args.add((((CastOpActionItem) newvar).object)); - newvar = ((CastOpActionItem) newvar).constructor; - if (newvar instanceof GetMemberActionItem) { - ret = new NewMethodActionItem(null, null, ((GetMemberActionItem) newvar).object, ((GetMemberActionItem) newvar).memberName, args); - } else if (newvar instanceof VariableActionItem) { - ret = new NewObjectActionItem(null, null, newvar, args); - } - } else if (newvar instanceof ToNumberActionItem) { + GraphTargetItem newvar = expressionPrimary(false, inFunction, inMethod, false, variables, functions, false);//variable(inFunction, inMethod, variables, functions); + if (newvar instanceof ToNumberActionItem) { List args = new ArrayList<>(); if (((ToNumberActionItem) newvar).value != null) { args.add(((ToNumberActionItem) newvar).value); } ret = new NewObjectActionItem(null, null, pushConst("Number"), args); - } else if (newvar instanceof CallMethodActionItem) { - CallMethodActionItem ca = (CallMethodActionItem) newvar; - ret = new NewMethodActionItem(null, null, ca.scriptObject, ca.methodName, ca.arguments); - } else if (newvar instanceof CallFunctionActionItem) { - CallFunctionActionItem cf = (CallFunctionActionItem) newvar; - ret = new NewObjectActionItem(null, null, cf.functionName, cf.arguments); + } else if (newvar instanceof GetMemberActionItem) { + + GetMemberActionItem ca = (GetMemberActionItem) newvar; + expectedType(SymbolType.PARENT_OPEN); + List args = call(inFunction, inMethod, variables, functions); + ret = new NewMethodActionItem(null, null, ca.object, ca.memberName, args); + } else if (newvar instanceof VariableActionItem) { + VariableActionItem cf = (VariableActionItem) newvar; + expectedType(SymbolType.PARENT_OPEN); + List args = call(inFunction, inMethod, variables, functions); + ret = new NewObjectActionItem(null, null, pushConst(cf.getVariableName()), args); } else { throw new ActionParseException("Invalid new item", lexer.yyline()); } + allowMemberOrCall = true; break; case EVAL: @@ -1869,7 +1866,7 @@ public class ActionScript2Parser { case SUPER: case PATH: if (s.value.equals("not")) { - ret = new NotItem(null, null, expressionPrimary(false, inFunction, inMethod, false, variables, functions)); + ret = new NotItem(null, null, expressionPrimary(false, inFunction, inMethod, false, variables, functions, true)); } else { if (s.type == SymbolType.PATH) { expectedType(SymbolType.COLON); @@ -1896,7 +1893,7 @@ public class ActionScript2Parser { } if (allowMemberOrCall && ret != null) { - ret = memberOrCall(ret, inFunction, inMethod, variables, functions); + ret = memberOrCall(ret, inFunction, inMethod, variables, functions, allowCall); } if (debugMode) { System.out.println("/primary"); @@ -1932,10 +1929,13 @@ public class ActionScript2Parser { return false; } - private GraphTargetItem memberOrCall(GraphTargetItem ret, boolean inFunction, boolean inMethod, List variables, List functions) throws IOException, ActionParseException { + private GraphTargetItem memberOrCall(GraphTargetItem ret, boolean inFunction, boolean inMethod, List variables, List functions, boolean allowCall) throws IOException, ActionParseException { ParsedSymbol op = lex(); while (op.isType(SymbolType.PARENT_OPEN, SymbolType.BRACKET_OPEN, SymbolType.DOT)) { if (op.type == SymbolType.PARENT_OPEN) { + if (!allowCall) { + break; + } List args = call(inFunction, inMethod, variables, functions); if (isCastOp(ret) && args.size() == 1) { ret = new CastOpActionItem(null, null, ret, args.get(0));