From b9660cdfeca6ed127740bddde8cc6ffedf399a77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Fri, 12 Feb 2021 06:13:38 +0100 Subject: [PATCH] #1597 Option to use old style lookupswitch in AS3 P-code --- CHANGELOG.md | 3 ++- .../abc/avm2/instructions/AVM2Instruction.java | 13 ++++++++++--- .../flash/abc/avm2/parser/pcode/ASM3Parser.java | 10 ++++++---- .../flash/configuration/Configuration.java | 4 ++++ .../gui/locales/AdvancedSettingsDialog.properties | 2 ++ .../locales/AdvancedSettingsDialog_cs.properties | 5 ++++- 6 files changed, 28 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75aca97ad..a97a37b75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ All notable changes to this project will be documented in this file. ## [Unreleased] ### Added - #1594 Option to disable AS3 P-code indentation, label on separate line -- #1594 Option to use old style of getlocalx, setlocalx with underscore +- #1594 Option to use old style of getlocalx, setlocalx with underscore in AS3 P-code +- #1597 Option to use old style lookupswitch in AS3 P-code ### Fixed - #1114 Script search results dialogs closing on swf close 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 eae79f1b3..73b17527a 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 @@ -348,8 +348,13 @@ public class AVM2Instruction implements Cloneable, GraphSourceItem { s.append(Helper.formatAddress(address + operands[i])); break; case AVM2Code.OPT_CASE_OFFSETS: - s.append(" ["); - boolean first = true; + if (Configuration.useOldStyleLookupSwitchAs3PCode.get()) { + s.append(" "); + s.append(operands[i]); + } else { + s.append(" ["); + } + boolean first = !Configuration.useOldStyleLookupSwitchAs3PCode.get(); for (int j = i + 1; j < operands.length; j++) { if (!first) { s.append(", "); @@ -358,7 +363,9 @@ public class AVM2Instruction implements Cloneable, GraphSourceItem { s.append("ofs"); s.append(Helper.formatAddress(address + operands[j])); } - s.append("]"); + if (!Configuration.useOldStyleLookupSwitchAs3PCode.get()) { + s.append("]"); + } break; default: s.append(" "); 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 ca6356f86..4bfb1cb23 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 @@ -1061,14 +1061,13 @@ public class ASM3Parser { while (parsedOperand.type == ParsedSymbol.TYPE_IDENTIFIER) { offsetItems.add(new CaseOffsetItem((String) parsedOperand.value, code.code.size(), i + (c + 1))); c++; - parsedOperand = lexer.lex(); + parsedOperand = lexer.lex(); if (parsedOperand.type == ParsedSymbol.TYPE_BRACKET_CLOSE) { break; } - if (parsedOperand.type != ParsedSymbol.TYPE_COMMA) { - throw new AVM2ParseException("Comma , expected", lexer.yyline()); + if (parsedOperand.type == ParsedSymbol.TYPE_COMMA) { + parsedOperand = lexer.lex(); } - parsedOperand = lexer.lex(); } if (parsedOperand.type != ParsedSymbol.TYPE_BRACKET_CLOSE) { throw new AVM2ParseException("Bracket close ] expected", lexer.yyline()); @@ -1087,6 +1086,9 @@ public class ASM3Parser { for (int c = 0; c <= patCount; c++) { parsedOperand = lexer.lex(); + if (parsedOperand.type == ParsedSymbol.TYPE_COMMA) { + parsedOperand = lexer.lex(); + } if (parsedOperand.type == ParsedSymbol.TYPE_IDENTIFIER) { offsetItems.add(new CaseOffsetItem((String) parsedOperand.value, code.code.size(), i + (c + 1))); operandsList.add(0); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java index 9afe3fcfe..1abc39ddd 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java @@ -667,6 +667,10 @@ public final class Configuration { @ConfigurationDefaultBoolean(false) @ConfigurationCategory("script") public static ConfigurationItem useOldStyleGetSetLocalsAs3PCode = null; + + @ConfigurationDefaultBoolean(false) + @ConfigurationCategory("script") + public static ConfigurationItem useOldStyleLookupSwitchAs3PCode = null; private enum OSId { WINDOWS, OSX, UNIX diff --git a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties index 1b1a32918..cba2e046a 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties @@ -495,4 +495,6 @@ config.description.labelOnSeparateLineAs3PCode = Make label in AS3 P-code stand config.name.useOldStyleGetSetLocalsAs3PCode = Use oldstyle getlocal_x instead of getlocalx in AS3 P-code config.description.useOldStyleGetSetLocalsAs3PCode = Use oldstyle getlocal_x, setlocal_x from FFDec 12.x or older +config.name.useOldStyleLookupSwitchAs3PCode = Use oldstyle lookupswitch without brackets in AS3 P-code +config.description.useOldStyleLookupSwitchAs3PCode = Use oldstyle lookupswitch from FFDec 12.x or older diff --git a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_cs.properties b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_cs.properties index 72efe6760..d2f5a7037 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_cs.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_cs.properties @@ -485,4 +485,7 @@ config.name.labelOnSeparateLineAs3PCode = N\u00e1v\u011b\u0161t\u00ed v AS3 P-k\ config.description.labelOnSeparateLineAs3PCode = N\u00e1v\u011b\u0161t\u00ed v AS3 P-k\u00f3du budou st\u00e1t na zvl\u00e1\u0161tn\u00edm \u0159\u00e1dku config.name.useOldStyleGetSetLocalsAs3PCode = Pou\u017e\u00edvat postaru getlocal_x m\u00edsto getlocalx v AS3 P-k\u00f3du -config.description.useOldStyleGetSetLocalsAs3PCode = Pou\u017e\u00edvat postaru getlocal_x, setlocal_x z FFDec 12.x \u010di star\u0161\u00edho \ No newline at end of file +config.description.useOldStyleGetSetLocalsAs3PCode = Pou\u017e\u00edvat postaru getlocal_x, setlocal_x z FFDec 12.x a star\u0161\u00edho + +config.name.useOldStyleLookupSwitchAs3PCode = Pou\u017e\u00edvat star\u00fd styl lookupswitch bez hranat\u00fdch z\u00e1vorek v AS3 P-k\u00f3du +config.description.useOldStyleLookupSwitchAs3PCode = Pou\u017e\u00edvat star\u00fd styl lookupswitch z FFDec 12.x a star\u0161\u00edho