diff --git a/CHANGELOG.md b/CHANGELOG.md index 3baf23913..ea552d5f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ All notable changes to this project will be documented in this file. - [#116] AS3 Do not parse DoABC tags inside sprites - [#116] Cyclic buttons - AS1/2 new keyword on empty method name +- AS2 getters and setters decoding ## [19.0.0] - 2023-10-01 ### Added diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/CallMethodActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/CallMethodActionItem.java index 4eab72e43..3aec081e5 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/CallMethodActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/CallMethodActionItem.java @@ -43,6 +43,13 @@ public class CallMethodActionItem extends ActionItem { public List arguments; + public static int SPECIAL_GETTER = 1; + public static int SPECIAL_SETTER = 2; + + + private int special = 0; + private String setterGetterVarName = null; + @Override public void visit(GraphTargetVisitorInterface visitor) { visitor.visitAll(arguments); @@ -54,10 +61,50 @@ public class CallMethodActionItem extends ActionItem { this.methodName = methodName; this.arguments = arguments; this.scriptObject = scriptObject; + + if (methodName instanceof DirectValueActionItem) { + DirectValueActionItem dv = (DirectValueActionItem) methodName; + if (dv.isString()) { + String methodNameStr = dv.getAsString(); + if (methodNameStr.startsWith("__get__") && arguments.isEmpty()) { + special = SPECIAL_GETTER; + setterGetterVarName = methodNameStr.substring(7); + } else if (methodNameStr.startsWith("__set__") && arguments.size() == 1) { + special = SPECIAL_SETTER; + setterGetterVarName = methodNameStr.substring(7); + precedence = PRECEDENCE_ASSIGMENT; + } + } + } } @Override public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { + if (special == SPECIAL_GETTER) { + if (scriptObject.getPrecedence() > this.precedence) { + writer.append("("); + scriptObject.toString(writer, localData); + writer.append(")"); + } else { + scriptObject.toString(writer, localData); + } + writer.append("."); + writer.append(setterGetterVarName); + return writer; + } else if (special == SPECIAL_SETTER) { + if (scriptObject.getPrecedence() > this.precedence) { + writer.append("("); + scriptObject.toString(writer, localData); + writer.append(")"); + } else { + scriptObject.toString(writer, localData); + } + writer.append("."); + writer.append(setterGetterVarName); + writer.append(" = "); + arguments.get(0).toStringNL(writer, localData); + return writer; + } if (methodName instanceof DirectValueActionItem) { boolean blankMethod = false; diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2ClassesTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2ClassesTest.java index 2d665635a..3b9721210 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2ClassesTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2ClassesTest.java @@ -56,7 +56,7 @@ public class ActionScript2ClassesTest extends ActionScript2TestBase { assertNotNull(dia); HighlightedTextWriter writer = new HighlightedTextWriter(new CodeFormatting(), false); try { - Action.actionsToSource(new HashMap<>() /*FIXME*/,dia, dia.getActions(), "", writer, Utf8Helper.charsetName); + Action.actionsToSource(new HashMap<>() /*FIXME*/, dia, dia.getActions(), "", writer, Utf8Helper.charsetName); } catch (InterruptedException ex) { fail(); } @@ -184,4 +184,28 @@ public class ActionScript2ClassesTest extends ActionScript2TestBase { + "trace(\"okay\");\r\n" + "}\r\n"); } + + @Test + public void testCallSetterGetter() { + compareSrc("TestCallSetterGetter", " var myobj;\n" + + " function TestCallSetterGetter()\n" + + " {\n" + + " }\n" + + " function testSetterCall()\n" + + " {\n" + + " this.myobj.myvar = 5;\n" + + " }\n" + + " function testGetterCall()\n" + + " {\n" + + " return this.myobj.myvar;\n" + + " }\n" + + " function testStatGetterCall()\n" + + " {\n" + + " return com.jpexs.flash.test.testcases.TestSetterGetter.mystvar;\n" + + " }\n" + + " function testStatSetterCall(val)\n" + + " {\n" + + " com.jpexs.flash.test.testcases.TestSetterGetter.mystvar = 6;\n" + + " }"); + } }