From ac15728b9d2d1ee5b39706477f30bfe4b71dea21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Thu, 11 Feb 2021 12:34:46 +0100 Subject: [PATCH] #1594 Option to disable AS3 P-code indentation, label on separate line --- CHANGELOG.md | 3 ++ .../decompiler/flash/abc/avm2/AVM2Code.java | 52 +++++++++++++++---- .../flash/abc/types/traits/Trait.java | 12 +++-- .../flash/configuration/Configuration.java | 11 +++- .../flash/gui/abc/ASMSourceEditorPane.java | 5 +- .../locales/AdvancedSettingsDialog.properties | 8 ++- .../AdvancedSettingsDialog_cs.properties | 47 ++++++++++++++++- 7 files changed, 121 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 748a0c4c9..6969cf86f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ 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 + ### Fixed - #1114 Script search results dialogs closing on swf close - #1159 Regexp syntax hilight when not a regexp (only division) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index 544187a84..f7d01ae45 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -1194,7 +1194,11 @@ public class AVM2Code implements Cloneable { public GraphTextWriter toASMSource(ABC abc, AVM2ConstantPool constants, MethodInfo info, MethodBody body, List outputMap, ScriptExportMode exportMode, GraphTextWriter writer) { if (info != null) { - writer.appendNoHilight("method").indent().newLine(); + writer.appendNoHilight("method"); + if (Configuration.indentAs3PCode.get()) { + writer.indent(); + } + writer.newLine(); writer.appendNoHilight("name "); writer.hilightSpecial(info.name_index == 0 ? "null" : "\"" + Helper.escapeActionScriptString(info.getName(constants)) + "\"", HighlightSpecialType.METHOD_NAME); writer.newLine(); @@ -1272,7 +1276,11 @@ public class AVM2Code implements Cloneable { Set importantOffsets = getImportantOffsets(body, true); if (body != null) { - writer.appendNoHilight("body").indent().newLine(); + writer.appendNoHilight("body"); + if (Configuration.indentAs3PCode.get()) { + writer.indent(); + } + writer.newLine(); writer.appendNoHilight("maxstack "); writer.appendNoHilight(body.max_stack); @@ -1292,12 +1300,19 @@ public class AVM2Code implements Cloneable { for (Trait t : body.traits.traits) { t.convertTraitHeader(abc, writer); - writer.unindent().appendNoHilight("end ; trait").newLine(); + if (Configuration.indentAs3PCode.get()) { + writer.unindent(); + } + writer.appendNoHilight("end ; trait").newLine(); } } writer.newLine(); - writer.appendNoHilight("code").indent().newLine(); + writer.appendNoHilight("code"); + if (Configuration.indentAs3PCode.get()) { + writer.indent(); + } + writer.newLine(); int ip = 0; int largeLimit = 20000; boolean markOffsets = code.size() <= largeLimit; @@ -1314,10 +1329,18 @@ public class AVM2Code implements Cloneable { } if (Configuration.showAllAddresses.get() || importantOffsets.contains(addr)) { String label = "ofs" + Helper.formatAddress(addr) + ":"; - writer.unindent().unindent().unindent(); + if (Configuration.labelOnSeparateLineAs3PCode.get() && Configuration.indentAs3PCode.get()) { + writer.unindent().unindent().unindent(); + } + writer.appendNoHilight(label); - writer.newLine(); - writer.indent().indent().indent(); + + if (Configuration.labelOnSeparateLineAs3PCode.get()) { + writer.newLine(); + if (Configuration.indentAs3PCode.get()) { + writer.indent().indent().indent(); + } + } } /*for (int e = 0; e < body.exceptions.length; e++) { if (body.exceptions[e].start == ofs) { @@ -1346,7 +1369,10 @@ public class AVM2Code implements Cloneable { } else if (exportMode == ScriptExportMode.CONSTANTS) { writer.appendNoHilight("Constant export mode is not supported.").newLine(); } - writer.unindent().appendNoHilight("end ; code").newLine(); + if (Configuration.indentAs3PCode.get()) { + writer.unindent(); + } + writer.appendNoHilight("end ; code").newLine(); if (body != null) { for (int e = 0; e < body.exceptions.length; e++) { ABCException exception = body.exceptions[e]; @@ -1374,10 +1400,16 @@ public class AVM2Code implements Cloneable { writer.appendNoHilight(" end"); writer.newLine(); } - writer.unindent().appendNoHilight("end ; body").newLine(); + if (Configuration.indentAs3PCode.get()) { + writer.unindent(); + } + writer.appendNoHilight("end ; body").newLine(); } if (info != null) { - writer.unindent().appendNoHilight("end ; method").newLine(); + if (Configuration.indentAs3PCode.get()) { + writer.unindent(); + } + writer.appendNoHilight("end ; method").newLine(); } return writer; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java index ace55aa30..1eb7fb9ba 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java @@ -366,7 +366,9 @@ public abstract class Trait implements Cloneable, Serializable { writer.hilightSpecial(traitType, HighlightSpecialType.TRAIT_TYPE); writer.appendNoHilight(" "); writer.hilightSpecial(abc.constants.multinameToString(name_index), HighlightSpecialType.TRAIT_NAME); - writer.indent(); + if (Configuration.indentAs3PCode.get()) { + writer.indent(); + } if ((kindFlags & ATTR_Final) > 0) { writer.newLine(); writer.append("flag "); @@ -394,7 +396,9 @@ public abstract class Trait implements Cloneable, Serializable { writer.append("\""); writer.append(Helper.escapeActionScriptString(abc.constants.getString(abc.metadata_info.get(m).name_index))); writer.append("\""); - writer.indent(); + if (Configuration.indentAs3PCode.get()) { + writer.indent(); + } writer.newLine(); if (m >= 0 && m < abc.metadata_info.size()) { for (int i = 0; i < abc.metadata_info.get(m).keys.length; i++) { @@ -414,7 +418,9 @@ public abstract class Trait implements Cloneable, Serializable { writer.newLine(); } } - writer.unindent(); + if (Configuration.indentAs3PCode.get()) { + writer.unindent(); + } writer.append("end ; metadata"); } } 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 a8f72b5e9..b6853d82e 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 @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.configuration; import com.jpexs.decompiler.flash.ApplicationInfo; @@ -655,6 +656,14 @@ public final class Configuration { @ConfigurationInternal public static ConfigurationItem showLineNumbersInPCodeGraphvizGraph = null; + @ConfigurationDefaultBoolean(true) + @ConfigurationCategory("format") + public static ConfigurationItem indentAs3PCode = null; + + @ConfigurationDefaultBoolean(true) + @ConfigurationCategory("format") + public static ConfigurationItem labelOnSeparateLineAs3PCode = null; + private enum OSId { WINDOWS, OSX, UNIX } diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java index e79d282e9..0346d8214 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java @@ -124,7 +124,10 @@ public class ASMSourceEditorPane extends DebuggableEditorPane implements CaretLi MethodBody body = abc.bodies.get(bodyIndex); abc.bodies.get(bodyIndex).getCode().toASMSource(abc, abc.constants, abc.method_info.get(body.method_info), body, exportMode, writer); if (trait != null && exportMode != ScriptExportMode.AS && exportMode != ScriptExportMode.AS_METHOD_STUBS) { - writer.unindent().appendNoHilight("end ; trait").newLine(); + if (Configuration.indentAs3PCode.get()) { + writer.unindent(); + } + writer.appendNoHilight("end ; trait").newLine(); } return new HighlightedText(writer); } diff --git a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties index 76def5899..773a9d8e4 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties @@ -484,4 +484,10 @@ config.name.showLineNumbersInPCodeGraphvizGraph = Show line numbers in Graphviz config.description.showLineNumbersInPCodeGraphvizGraph = Show line numbers in the P-code graphviz graph. config.name.padAs3PCodeInstructionName = Pad AS3 P-code instruction names -config.description.padAs3PCodeInstructionName = Pad AS3 P-code instruction names with spaces \ No newline at end of file +config.description.padAs3PCodeInstructionName = Pad AS3 P-code instruction names with spaces + +config.name.indentAs3PCode = Indent AS3 P-code +config.description.indentAs3PCode = Indent AS3 P-code blocks like trait/body/code + +config.name.labelOnSeparateLineAs3PCode = Label in AS3 P-code on separate line +config.description.labelOnSeparateLineAs3PCode = Make label in AS3 P-code stand on separate line 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 f2d6a7010..6db5efa3d 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_cs.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_cs.properties @@ -437,4 +437,49 @@ config.description.gui.sourceFont = N\u00e1zevP\u00edsma-StylP\u00edsma(Plain,Bo #after 11.1.0 config.name.as12DeobfuscatorExecutionLimit = Exeku\u010dn\u00ed limit AS1/2 deobfusk\u00e1toru -config.description.as12DeobfuscatorExecutionLimit = Maxim\u00e1ln\u00ed po\u010det instrukc\u00ed prov\u00e1d\u011bn\u00fdch b\u011bhem AS1/2 exeku\u010dn\u00ed deobfuskace \ No newline at end of file +config.description.as12DeobfuscatorExecutionLimit = Maxim\u00e1ln\u00ed po\u010det instrukc\u00ed prov\u00e1d\u011bn\u00fdch b\u011bhem AS1/2 exeku\u010dn\u00ed deobfuskace + +#Do not translate the Font Styles which is in the parenthesis:(Plain,Bold,Italic,BoldItalic) +config.name.gui.sourceFont = Zdrojov\u00fd styl p\u00edsma +config.description.gui.sourceFont = N\u00e1zevFontu-StylP\u00edsma(Plain,Bold,Italic,BoldItalic)-VelikostP\u00edsma + +#after 11.1.0 +config.name.as12DeobfuscatorExecutionLimit = AS1/2 spou\u0161t\u011bc\u00ed limit deobfusk\u00e1toru +config.description.as12DeobfuscatorExecutionLimit = Maxim\u00e1ln\u00ed po\u010det instrukc\u00ed zpracovan\u00fdch b\u011bhem AS1/2 spou\u0161t\u011bc\u00ed deobfuskace + +#option that ignore in 8.0.1 and other versions +config.name.showOriginalBytesInPcodeHex = (Internal) Zobrazit p\u016fvodn\u00ed byty +config.description.showOriginalBytesInPcodeHex = zobrazit p\u016fvodn\u00ed byty v P-k\u00f3d hex + +config.name.showFileOffsetInPcodeHex = (Internal) Zobrazit pozici v souboru +config.description.showFileOffsetInPcodeHex = zobrazit pozici v souboru v P-k\u00f3d hex + +config.name._enableFlexExport = (Internal) enableFlexExport +config.description.enableFlexExport = povolit Flex Export + +config.name._ignoreAdditionalFlexClasses = (Internal) ignoreAdditionalFlexClasses +config.description.ignoreAdditionalFlexClasses = ignorovat P\u0159\u00eddavn\u00e9 Flex t\u0159\u00eddy + +config.name.hwAcceleratedGraphics = (Internal) hwAcceleratedGraphics +config.description.hwAcceleratedGraphics = hw Akcelerovan\u00fd Grafika + +config.name.gui.avm2.splitPane.docs.dividerLocationPercent = (Internal) splitPanedocsdividerLocationPercent +config.description.gui.avm2.splitPane.docs.dividerLocationPercent = pozice v procentech um\u00edst\u011bn\u00ed dokumenta\u010dn\u00edho splitPane + +config.name.gui.dump.splitPane.dividerLocationPercent = (Internal) dumpsplitPanedividerLocationPercent +config.description.gui.dump.splitPane.dividerLocationPercent = pozice v procentech um\u00edst\u011bn\u00ed dump splitPane + +config.name.useAdobeFlashPlayerForPreviews = (P\u0159ekon\u00e1no) Pou\u017e\u00edvat Adobe Flash player pro n\u00e1hledy objekt\u016f +config.description.useAdobeFlashPlayerForPreviews = Pou\u017e\u00edvat Adobe Flash player pro n\u00e1hledy objekt\u016f. VAROV\u00c1N\u00cd: FlashPlayer nen\u00ed podporov\u00e1n\u00ed od 2021-01-12 + +config.name.showLineNumbersInPCodeGraphvizGraph = Zobrazovat \u010d\u00edsla \u0159\u00e1dek v Graphviz grafech +config.description.showLineNumbersInPCodeGraphvizGraph = Zobrazovat \u010d\u00edsla \u0159\u00e1dek v graphviz grafech P-k\u00f3du + +config.name.padAs3PCodeInstructionName = Zarovnat n\u00e1zvy instrukc\u00ed AS3 P-k\u00f3du +config.description.padAs3PCodeInstructionName = Zarovnat n\u00e1zvy instrukc\u00ed AS3 P-k\u00f3du mezerami + +config.name.indentAs3PCode = Odsadit AS3 P-k\u00f3d +config.description.indentAs3PCode = Odsadit AS3 P-k\u00f3d bloky jako trait/body/code + +config.name.labelOnSeparateLineAs3PCode = N\u00e1v\u011b\u0161t\u00ed v AS3 P-k\u00f3du na zvl\u00e1\u0161tn\u00edm \u0159\u00e1dku +config.description.labelOnSeparateLineAs3PCode = N\u00e1v\u011b\u0161t\u00ed v AS3 P-k\u00f3du budou st\u00e1t na zvl\u00e1\u0161tn\u00edm \u0159\u00e1dku \ No newline at end of file