From 294ed03a940c055080ca349a0b8b2a204736f98b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Mon, 5 Aug 2024 19:26:53 +0200 Subject: [PATCH] Added: #2221 AS3 P-code - add new function button (creates methodinfo, methodbody) --- CHANGELOG.md | 3 + .../flash/configuration/Configuration.java | 5 ++ .../decompiler/flash/gui/abc/ABCPanel.java | 2 - .../flash/gui/abc/MethodCodePanel.java | 69 +++++++++++++++--- .../flash/gui/graphics/addfunction16.png | Bin 0 -> 809 bytes .../locales/AdvancedSettingsDialog.properties | 2 + .../AdvancedSettingsDialog_cs.properties | 5 +- .../flash/gui/locales/MainFrame.properties | 13 +++- .../flash/gui/locales/MainFrame_cs.properties | 13 +++- 9 files changed, 98 insertions(+), 14 deletions(-) create mode 100644 src/com/jpexs/decompiler/flash/gui/graphics/addfunction16.png diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ae62a40c..d9f7c7867 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Added +- [#2221] AS3 P-code - add new function button (creates methodinfo, methodbody) ## [21.0.0] - 2024-08-05 ### Added @@ -3463,6 +3465,7 @@ Major version of SWF to XML export changed to 2. [alpha 9]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha8...alpha9 [alpha 8]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha7...alpha8 [alpha 7]: https://github.com/jindrapetrik/jpexs-decompiler/releases/tag/alpha7 +[#2221]: https://www.free-decompiler.com/flash/issues/2221 [#2176]: https://www.free-decompiler.com/flash/issues/2176 [#2179]: https://www.free-decompiler.com/flash/issues/2179 [#2185]: https://www.free-decompiler.com/flash/issues/2185 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 15315ddc1..be925bda5 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 @@ -1008,6 +1008,11 @@ public final class Configuration { @ConfigurationDefaultBoolean(true) @ConfigurationCategory("script") public static ConfigurationItem warningAbcClean = null; + + @ConfigurationDefaultBoolean(true) + @ConfigurationCategory("script") + public static ConfigurationItem warningAddFunction = null; + private enum OSId { WINDOWS, OSX, UNIX diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index e95908ed7..1deabfe74 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -51,7 +51,6 @@ import com.jpexs.decompiler.flash.configuration.SwfSpecificCustomConfiguration; import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.gui.AppDialog; import com.jpexs.decompiler.flash.gui.AppStrings; -import com.jpexs.decompiler.flash.gui.BreakpointListDialog; import com.jpexs.decompiler.flash.gui.DebugPanel; import com.jpexs.decompiler.flash.gui.DebuggerHandler; import com.jpexs.decompiler.flash.gui.FasterScrollPane; @@ -114,7 +113,6 @@ import java.util.Map; import java.util.Objects; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.regex.Pattern; import javax.swing.AbstractAction; import javax.swing.BorderFactory; import javax.swing.BoxLayout; diff --git a/src/com/jpexs/decompiler/flash/gui/abc/MethodCodePanel.java b/src/com/jpexs/decompiler/flash/gui/abc/MethodCodePanel.java index aa2db5958..4c6bd3432 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/MethodCodePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/MethodCodePanel.java @@ -17,6 +17,12 @@ package com.jpexs.decompiler.flash.gui.abc; import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instructions; +import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; +import com.jpexs.decompiler.flash.abc.types.MethodBody; +import com.jpexs.decompiler.flash.abc.types.MethodInfo; +import com.jpexs.decompiler.flash.abc.types.ValueKind; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; @@ -25,16 +31,24 @@ import com.jpexs.decompiler.flash.gui.DocsPanel; import com.jpexs.decompiler.flash.gui.FasterScrollPane; import com.jpexs.decompiler.flash.gui.Main; import com.jpexs.decompiler.flash.gui.View; +import com.jpexs.decompiler.flash.gui.ViewMessages; import com.jpexs.decompiler.flash.gui.controls.JPersistentSplitPane; import com.jpexs.decompiler.flash.gui.controls.NoneSelectedButtonGroup; import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType; +import com.jpexs.decompiler.flash.tags.Tag; import java.awt.BorderLayout; import java.awt.Dimension; +import java.awt.FlowLayout; import java.awt.Insets; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; import java.awt.event.ActionEvent; +import java.util.List; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JSplitPane; import javax.swing.JToggleButton; @@ -49,12 +63,14 @@ public class MethodCodePanel extends JPanel { private final FasterScrollPane sourceScrollPane; - public JPanel buttonsPanel; + public JPanel detailButtonsPanel; private final JToggleButton hexButton; private final JToggleButton hexOnlyButton; + private final JButton addFunctionButton; + private final DocsPanel docsPanel; public ABC getABC() { @@ -140,8 +156,8 @@ public class MethodCodePanel extends JPanel { sourceTextArea.changeContentType("text/flasm3"); sourceTextArea.setFont(Configuration.getSourceFont()); - buttonsPanel = new JPanel(); - buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS)); + detailButtonsPanel = new JPanel(); + detailButtonsPanel.setLayout(new BoxLayout(detailButtonsPanel, BoxLayout.X_AXIS)); JButton graphButton = new JButton(View.getIcon("graph16")); graphButton.addActionListener(this::graphButtonActionPerformed); @@ -158,16 +174,30 @@ public class MethodCodePanel extends JPanel { hexOnlyButton.setToolTipText(AppStrings.translate("button.viewhex")); hexOnlyButton.setMargin(new Insets(3, 3, 3, 3)); + addFunctionButton = new JButton(View.getIcon("addfunction16")); + addFunctionButton.addActionListener(this::addFunctionButtonActionPerformed); + addFunctionButton.setToolTipText(AppStrings.translate("button.addfunction")); + addFunctionButton.setMargin(new Insets(3, 3, 3, 3)); + NoneSelectedButtonGroup exportModeButtonGroup = new NoneSelectedButtonGroup(); exportModeButtonGroup.add(hexButton); exportModeButtonGroup.add(hexOnlyButton); - buttonsPanel.add(graphButton); - buttonsPanel.add(Box.createRigidArea(new Dimension(10, 0))); - buttonsPanel.add(hexButton); - buttonsPanel.add(hexOnlyButton); - buttonsPanel.add(new JPanel()); + detailButtonsPanel.add(graphButton); + detailButtonsPanel.add(Box.createRigidArea(new Dimension(10, 0))); + detailButtonsPanel.add(hexButton); + detailButtonsPanel.add(hexOnlyButton); + JPanel buttonsPanel = new JPanel(); + buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS)); + JPanel editVisibleButtonsPanel = new JPanel(); + editVisibleButtonsPanel.setLayout(new BoxLayout(editVisibleButtonsPanel, BoxLayout.X_AXIS)); + editVisibleButtonsPanel.add(addFunctionButton); + + buttonsPanel.add(detailButtonsPanel); + buttonsPanel.add(Box.createHorizontalStrut(5)); + buttonsPanel.add(editVisibleButtonsPanel); + buttonsPanel.add(Box.createHorizontalGlue()); add(buttonsPanel, BorderLayout.NORTH); } @@ -196,6 +226,27 @@ public class MethodCodePanel extends JPanel { sourceTextArea.setHex(getExportMode(), false); } + private void addFunctionButtonActionPerformed(ActionEvent evt) { + if (ViewMessages.showConfirmDialog(this, AppStrings.translate("message.confirm.addfunction"), AppStrings.translate("message.warning"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, Configuration.warningAddFunction, JOptionPane.OK_OPTION) != JOptionPane.OK_OPTION) { + return; + } + MethodInfo methodInfoObj = new MethodInfo(new int[0], 0, 0, 0, null, null); + ABC abc = getABC(); + int methodInfo = abc.addMethodInfo(methodInfoObj); + MethodBody body = new MethodBody(); + List code = body.getCode().code; + code.add(new AVM2Instruction(0, AVM2Instructions.ReturnVoid, new int[0])); + body.method_info = methodInfo; + abc.addMethodBody(body); + ((Tag) abc.parentTag).setModified(true); + if (ViewMessages.showConfirmDialog(this, AppStrings.translate("addfunction.result").replace("%method_info_index%", "" + methodInfo), AppStrings.translate("addfunction.result.title"), JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION) { + return; + } + StringSelection stringSelection = new StringSelection("" + methodInfo); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(stringSelection, null); + } + public ASMSourceEditorPane getSourceTextArea() { return sourceTextArea; } @@ -216,6 +267,6 @@ public class MethodCodePanel extends JPanel { sourceTextArea.setEditable(val); sourceTextArea.getCaret().setVisible(true); - buttonsPanel.setVisible(!val); + detailButtonsPanel.setVisible(!val); } } diff --git a/src/com/jpexs/decompiler/flash/gui/graphics/addfunction16.png b/src/com/jpexs/decompiler/flash/gui/graphics/addfunction16.png new file mode 100644 index 0000000000000000000000000000000000000000..9c799402fa597c94dcdd2af4a9bfe3582836f68e GIT binary patch literal 809 zcmV+^1J?YBP)EX>4Tx04R}tkv&MmKpe$iQ%j3f6zm}4kfAzR5EXHhDi*;)X)CnqU~=gfG-*gu zTpR`0f`cE6RRe3JS*_Mt`=0!T;exi3;X2I`B(Q`eQV=1djtZ)<5TjKi#YCF+;~xHD$DbmXOs)zT zITlcZ3d!+<|H1EW&EnLgn-q=%ffw8U7zKj6K&xTf-^aGyIsyF8z?IhV*P6iWC+Urj z7Ci#`w}Ff6jwbH`mpj1FlP(#OBl&3x#Uk*2M&FbN25*7hHMh6+K29HiEOoVf0~{Oz zV^Vg010qNS#tmY zE+YT{E+YYWr9XB6000McNliru=m-T6HVxY5#smNW02y>eSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Nlj2!fese{0099>L_t(I%f*quO9F8i#y{UX9TKFt&EeA4dJGymI7(b;mG#zKX7dcr*Lu*B19Anjyoy}eH-H7P!GQ0;Iq8HAKv$UU_&T? zd?PQ*g|HbaErxZ&|ADdT3EL-7X+PNB6VnLO@|oqPc=gziZMhh>=036zFcg?3t%o}2 znY7iC!?iYd)-LX$11ANK=kX2w0dB3Wslt4L>(~%PP_(WIB5>@#{K{={oU|1m>5V)| zqBruS;v-s8Rqv7Gefao+%aU-_RphepG6YkHz&YjU8xHnzV3=RL&7OFjKrp4FH08F> nn%wSKltn-(_