From 05f7561314056b9aa93a6ccce448f2e9a593a80e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Mon, 25 Jan 2021 19:59:39 +0100 Subject: [PATCH] AS3 p-code more RAbcDasm like: commas in parameters list (WARNING: Breaks backward compatibility) --- CHANGELOG.md | 5 +++-- .../flash/abc/avm2/instructions/AVM2Instruction.java | 8 +++++++- .../flash/abc/avm2/parser/pcode/ASM3Parser.java | 6 ++++++ .../flash/ActionScript3DeobfuscatorTest.java | 12 ++++++------ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cdc6053ac..6203285a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file. - Graphviz graphs colorized - AS3: Show try graph heads in Graphviz distinguished - #341, #1379 AS3: Support for scripts not using kill instruction -- AS3 method trait p-code indentation +- AS3 method trait p-code indentation, instruction name padding - AS3 editation of body traits (slot/const only) ### Fixed @@ -23,7 +23,8 @@ All notable changes to this project will be documented in this file. ### Changed - AS3 test methods separated to classes -- AS3 p-code more RAbcDasm like (parenthesis after True/False/Undefined/Null trait kinds) +- AS3 p-code more RAbcDasm like: parenthesis after True/False/Undefined/Null trait kinds +- AS3 p-code more RAbcDasm like: commas in parameters list (WARNING: Breaks backward compatibility) ### Removed - Code structure detection in Graphviz graphs as it was usually wrong diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java index a29e5b64d..9578de898 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java @@ -230,6 +230,9 @@ public class AVM2Instruction implements Cloneable, GraphSourceItem { public String getParams(AVM2ConstantPool constants, List fullyQualifiedNames) { StringBuilder s = new StringBuilder(); for (int i = 0; i < definition.operands.length; i++) { + if (i > 0) { + s.append(","); + } switch (definition.operands[i]) { case AVM2Code.DAT_NAMESPACE_INDEX: if (operands[i] == 0) { @@ -373,8 +376,11 @@ public class AVM2Instruction implements Cloneable, GraphSourceItem { public String toStringNoAddress(AVM2ConstantPool constants, List fullyQualifiedNames) { String s = definition.instructionName; + for (int i = s.length(); i < 19; i++) { + s += " "; + } s += getParams(constants, fullyQualifiedNames) + getComment(); - return s; + return s.trim(); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/pcode/ASM3Parser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/pcode/ASM3Parser.java index 571fab952..ca08f78f8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/pcode/ASM3Parser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/pcode/ASM3Parser.java @@ -854,6 +854,12 @@ public class ASM3Parser { for (int i = 0; i < def.operands.length; i++) { ParsedSymbol parsedOperand = lexer.lex(); + if (i > 0) { + if (parsedOperand.type != ParsedSymbol.TYPE_COMMA) { + throw new AVM2ParseException("Comma (,) expected", lexer.yyline()); + } + parsedOperand = lexer.lex(); + } switch (def.operands[i]) { case AVM2Code.DAT_MULTINAME_INDEX: lexer.pushback(parsedOperand); diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DeobfuscatorTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DeobfuscatorTest.java index 3b412fbdf..22417447b 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DeobfuscatorTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DeobfuscatorTest.java @@ -240,14 +240,14 @@ public class ActionScript3DeobfuscatorTest extends ActionScriptTestBase { + "b:pushbyte 3\r\n"); Assert.assertEquals(res, "getlocal_0\r\n" + "pushscope\r\n" - + "pushbyte 3\r\n" - + "pushbyte 4\r\n" - + "ifeq ofs000e\r\n" - + "jump ofs0010\r\n" + + "pushbyte 3\r\n" + + "pushbyte 4\r\n" + + "ifeq ofs000e\r\n" + + "jump ofs0010\r\n" + "ofs000e:\r\n" - + "pushbyte 4\r\n" + + "pushbyte 4\r\n" + "ofs0010:\r\n" - + "pushbyte 3\r\n" + + "pushbyte 3\r\n" + "returnvoid\r\n"); }