From f90f5fbd32ae7a7e42d00f5cb1b53cf9cb3de579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Fri, 18 Nov 2022 16:03:48 +0100 Subject: [PATCH] Fixed #1840 AS3 - Allow to compile object literal keys with nonstring/numbers in obfuscated code --- CHANGELOG.md | 2 ++ .../flash/abc/avm2/model/NameValuePair.java | 9 ++++++++- .../abc/avm2/parser/script/ActionScript3Parser.java | 11 ++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6153f3761..2880eb459 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ All notable changes to this project will be documented in this file. - AS3 Direct editation - slow property resolving (Now up to 10 times faster compilation) - [#1875] Garbage collect SWF and its caches after closing it - [#1807] Proper parenthesis around call inside another call +- [#1840] AS3 - Allow to compile object literal keys with nonstring/numbers in obfuscated code ### Changed - GFX - DefineExternalImage2 no longer handled as character @@ -2612,6 +2613,7 @@ All notable changes to this project will be documented in this file. [#1692]: https://www.free-decompiler.com/flash/issues/1692 [#1757]: https://www.free-decompiler.com/flash/issues/1757 [#1807]: https://www.free-decompiler.com/flash/issues/1807 +[#1840]: https://www.free-decompiler.com/flash/issues/1840 [#1867]: https://www.free-decompiler.com/flash/issues/1867 [#1868]: https://www.free-decompiler.com/flash/issues/1868 [#1649]: https://www.free-decompiler.com/flash/issues/1649 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/NameValuePair.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/NameValuePair.java index 1e15726ee..5376b479c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/NameValuePair.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/NameValuePair.java @@ -46,8 +46,15 @@ public class NameValuePair extends AVM2Item { } @Override - public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { + public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { + boolean needsParents = !((name.getNotCoerced() instanceof NumberValueAVM2Item) || (name.getNotCoerced() instanceof StringAVM2Item)); // special for obfuscated strings + if (needsParents) { + writer.append("("); + } name.toStringString(writer, localData); + if (needsParents) { + writer.append(")"); + } writer.append(":"); if (value instanceof TernarOpItem) { //Ternar operator contains ":" writer.append("("); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java index c42084b39..71fe62f45 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java @@ -2351,10 +2351,15 @@ public class ActionScript3Parser { lexer.pushback(s); } s = lex(); - expected(s, lexer.yyline(), SymbolGroup.IDENTIFIER, SymbolType.STRING, SymbolType.INTEGER, SymbolType.DOUBLE); + expected(s, lexer.yyline(), SymbolGroup.IDENTIFIER, SymbolType.STRING, SymbolType.INTEGER, SymbolType.DOUBLE, SymbolType.PARENT_OPEN); - GraphTargetItem n = new StringAVM2Item(null, null, s.value.toString()); -//expression(allOpenedNamespaces, thisType,pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, allowRemainder, variables); + GraphTargetItem n; + if (s.type == SymbolType.PARENT_OPEN) { //special for obfuscated SWFs + n = expression(allOpenedNamespaces, thisType,pkg,needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, allowRemainder, variables, false); + expectedType(SymbolType.PARENT_CLOSE); + } else { + n = new StringAVM2Item(null, null, s.value.toString()); + } expectedType(SymbolType.COLON); GraphTargetItem v = expression(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, allowRemainder, variables, false);