mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-25 17:01:01 +00:00
shown only the constant pool(s) in pcode editor
This commit is contained in:
@@ -1566,7 +1566,7 @@ public class CommandLineArgumentParser {
|
||||
|
||||
private static void replaceAS2PCode(String text, ASMSource src) throws IOException, InterruptedException {
|
||||
System.out.println("Replace AS1/2 PCode");
|
||||
if (text.trim().startsWith("#hexdata")) {
|
||||
if (text.trim().startsWith(Helper.hexData)) {
|
||||
src.setActionBytes(Helper.getBytesFromHexaText(text));
|
||||
} else {
|
||||
try {
|
||||
@@ -1597,7 +1597,7 @@ public class CommandLineArgumentParser {
|
||||
|
||||
private static void replaceAS3PCode(String text, ABC abc, int bodyIndex, Trait trait) throws IOException, InterruptedException {
|
||||
System.out.println("Replace AS3 PCode");
|
||||
if (text.trim().startsWith("#hexdata")) {
|
||||
if (text.trim().startsWith(Helper.hexData)) {
|
||||
byte[] data = Helper.getBytesFromHexaText(text);
|
||||
MethodBody mb = abc.bodies.get(bodyIndex);
|
||||
mb.setCodeBytes(data);
|
||||
|
||||
@@ -205,7 +205,7 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretLi
|
||||
public boolean save() {
|
||||
try {
|
||||
String text = getText();
|
||||
if (text.trim().startsWith("#hexdata")) {
|
||||
if (text.trim().startsWith(Helper.hexData)) {
|
||||
byte[] data = Helper.getBytesFromHexaText(text);
|
||||
MethodBody mb = abc.bodies.get(bodyIndex);
|
||||
mb.setCodeBytes(data);
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
|
||||
import com.jpexs.decompiler.flash.gui.AppStrings;
|
||||
import com.jpexs.decompiler.flash.gui.Main;
|
||||
import com.jpexs.decompiler.flash.gui.View;
|
||||
import com.jpexs.decompiler.flash.gui.controls.NoneSelectedButtonGroup;
|
||||
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Font;
|
||||
@@ -117,6 +118,10 @@ public class MethodCodePanel extends JPanel {
|
||||
hexOnlyButton.setToolTipText(AppStrings.translate("button.viewhex"));
|
||||
hexOnlyButton.setMargin(new Insets(3, 3, 3, 3));
|
||||
|
||||
NoneSelectedButtonGroup exportModeButtonGroup = new NoneSelectedButtonGroup();
|
||||
exportModeButtonGroup.add(hexButton);
|
||||
exportModeButtonGroup.add(hexOnlyButton);
|
||||
|
||||
buttonsPanel.add(graphButton);
|
||||
buttonsPanel.add(hexButton);
|
||||
buttonsPanel.add(hexOnlyButton);
|
||||
@@ -140,7 +145,6 @@ public class MethodCodePanel extends JPanel {
|
||||
return;
|
||||
}
|
||||
|
||||
hexOnlyButton.setSelected(false);
|
||||
sourceTextArea.setHex(getExportMode(), false);
|
||||
}
|
||||
|
||||
@@ -149,7 +153,6 @@ public class MethodCodePanel extends JPanel {
|
||||
return;
|
||||
}
|
||||
|
||||
hexButton.setSelected(false);
|
||||
sourceTextArea.setHex(getExportMode(), false);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ import com.jpexs.decompiler.flash.gui.SearchResultsDialog;
|
||||
import com.jpexs.decompiler.flash.gui.View;
|
||||
import com.jpexs.decompiler.flash.gui.abc.LineMarkedEditorPane;
|
||||
import com.jpexs.decompiler.flash.gui.controls.JPersistentSplitPane;
|
||||
import com.jpexs.decompiler.flash.gui.controls.NoneSelectedButtonGroup;
|
||||
import com.jpexs.decompiler.flash.gui.tagtree.TagTreeModel;
|
||||
import com.jpexs.decompiler.flash.helpers.HighlightedText;
|
||||
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
|
||||
@@ -115,6 +116,8 @@ public class ActionPanel extends JPanel implements SearchListener<ActionSearchRe
|
||||
|
||||
public JToggleButton hexOnlyButton;
|
||||
|
||||
public JToggleButton constantsViewButton;
|
||||
|
||||
public JToggleButton resolveConstantsButton;
|
||||
|
||||
public JLabel asmLabel = new HeaderLabel(AppStrings.translate("panel.disassembled"));
|
||||
@@ -143,6 +146,8 @@ public class ActionPanel extends JPanel implements SearchListener<ActionSearchRe
|
||||
|
||||
private HighlightedText srcHexOnly;
|
||||
|
||||
private HighlightedText srcConstants;
|
||||
|
||||
private String lastDecompiled = "";
|
||||
|
||||
private ASMSource lastASM;
|
||||
@@ -160,6 +165,7 @@ public class ActionPanel extends JPanel implements SearchListener<ActionSearchRe
|
||||
srcWithHex = null;
|
||||
srcNoHex = null;
|
||||
srcHexOnly = null;
|
||||
srcConstants = null;
|
||||
}
|
||||
|
||||
public String getStringUnderCursor() {
|
||||
@@ -327,25 +333,39 @@ public class ActionPanel extends JPanel implements SearchListener<ActionSearchRe
|
||||
}
|
||||
|
||||
public void setHex(ScriptExportMode exportMode) {
|
||||
if (exportMode != ScriptExportMode.HEX) {
|
||||
if (exportMode == ScriptExportMode.PCODE) {
|
||||
switch (exportMode) {
|
||||
case PCODE:
|
||||
if (srcNoHex == null) {
|
||||
srcNoHex = getHighlightedText(exportMode);
|
||||
}
|
||||
|
||||
setText(srcNoHex, "text/flasm");
|
||||
} else {
|
||||
break;
|
||||
case PCODE_HEX:
|
||||
if (srcWithHex == null) {
|
||||
srcWithHex = getHighlightedText(exportMode);
|
||||
}
|
||||
|
||||
setText(srcWithHex, "text/flasm");
|
||||
}
|
||||
} else {
|
||||
if (srcHexOnly == null) {
|
||||
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true);
|
||||
Helper.byteArrayToHexWithHeader(writer, src.getActionBytes());
|
||||
srcHexOnly = new HighlightedText(writer);
|
||||
}
|
||||
setText(srcHexOnly, "text/plain");
|
||||
break;
|
||||
case HEX:
|
||||
if (srcHexOnly == null) {
|
||||
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true);
|
||||
Helper.byteArrayToHexWithHeader(writer, src.getActionBytes());
|
||||
srcHexOnly = new HighlightedText(writer);
|
||||
}
|
||||
|
||||
setText(srcHexOnly, "text/plain");
|
||||
break;
|
||||
case CONSTANTS:
|
||||
if (srcConstants == null) {
|
||||
srcConstants = getHighlightedText(exportMode);
|
||||
}
|
||||
|
||||
setText(srcConstants, "text/plain");
|
||||
break;
|
||||
default:
|
||||
throw new Error("Export mode not supported: " + exportMode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,6 +434,7 @@ public class ActionPanel extends JPanel implements SearchListener<ActionSearchRe
|
||||
srcWithHex = null;
|
||||
srcNoHex = null;
|
||||
srcHexOnly = null;
|
||||
srcConstants = null;
|
||||
setHex(getExportMode());
|
||||
if (Configuration.decompile.get()) {
|
||||
setDecompiledText("// " + AppStrings.translate("work.decompiling") + "...");
|
||||
@@ -481,6 +502,17 @@ public class ActionPanel extends JPanel implements SearchListener<ActionSearchRe
|
||||
hexOnlyButton.setToolTipText(AppStrings.translate("button.viewhex"));
|
||||
hexOnlyButton.setMargin(new Insets(3, 3, 3, 3));
|
||||
|
||||
// todo: change icon
|
||||
constantsViewButton = new JToggleButton(View.getIcon("constantpool16"));
|
||||
constantsViewButton.addActionListener(this::constantsViewButtonActionPerformed);
|
||||
constantsViewButton.setToolTipText(AppStrings.translate("button.viewConstants"));
|
||||
constantsViewButton.setMargin(new Insets(3, 3, 3, 3));
|
||||
|
||||
NoneSelectedButtonGroup exportModeButtonGroup = new NoneSelectedButtonGroup();
|
||||
exportModeButtonGroup.add(hexButton);
|
||||
exportModeButtonGroup.add(hexOnlyButton);
|
||||
exportModeButtonGroup.add(constantsViewButton);
|
||||
|
||||
resolveConstantsButton = new JToggleButton(View.getIcon("constantpool16"));
|
||||
resolveConstantsButton.addActionListener(this::resolveConstantsButtonActionPerformed);
|
||||
resolveConstantsButton.setToolTipText(AppStrings.translate("button.resolveConstants"));
|
||||
@@ -492,6 +524,7 @@ public class ActionPanel extends JPanel implements SearchListener<ActionSearchRe
|
||||
topButtonsPan.add(graphButton);
|
||||
topButtonsPan.add(hexButton);
|
||||
topButtonsPan.add(hexOnlyButton);
|
||||
topButtonsPan.add(constantsViewButton);
|
||||
topButtonsPan.add(Box.createRigidArea(new Dimension(10, 0)));
|
||||
topButtonsPan.add(resolveConstantsButton);
|
||||
|
||||
@@ -621,14 +654,15 @@ public class ActionPanel extends JPanel implements SearchListener<ActionSearchRe
|
||||
}
|
||||
|
||||
public void setEditMode(boolean val) {
|
||||
boolean rawEdit = hexOnlyButton.isSelected();
|
||||
|
||||
if (val) {
|
||||
if (rawEdit) {
|
||||
if (hexOnlyButton.isSelected()) {
|
||||
setHex(ScriptExportMode.HEX);
|
||||
} else if (constantsViewButton.isSelected()) {
|
||||
setHex(ScriptExportMode.CONSTANTS);
|
||||
} else {
|
||||
setHex(ScriptExportMode.PCODE);
|
||||
}
|
||||
|
||||
editor.setEditable(true);
|
||||
saveButton.setVisible(true);
|
||||
editButton.setVisible(false);
|
||||
@@ -644,6 +678,7 @@ public class ActionPanel extends JPanel implements SearchListener<ActionSearchRe
|
||||
editor.getCaret().setVisible(true);
|
||||
asmLabel.setIcon(null);
|
||||
}
|
||||
|
||||
topButtonsPan.setVisible(!val);
|
||||
editMode = val;
|
||||
editor.requestFocusInWindow();
|
||||
@@ -705,12 +740,14 @@ public class ActionPanel extends JPanel implements SearchListener<ActionSearchRe
|
||||
}
|
||||
|
||||
private void hexButtonActionPerformed(ActionEvent evt) {
|
||||
hexOnlyButton.setSelected(false);
|
||||
setHex(getExportMode());
|
||||
}
|
||||
|
||||
private void hexOnlyButtonActionPerformed(ActionEvent evt) {
|
||||
hexButton.setSelected(false);
|
||||
setHex(getExportMode());
|
||||
}
|
||||
|
||||
private void constantsViewButtonActionPerformed(ActionEvent evt) {
|
||||
setHex(getExportMode());
|
||||
}
|
||||
|
||||
@@ -732,8 +769,11 @@ public class ActionPanel extends JPanel implements SearchListener<ActionSearchRe
|
||||
private void saveActionButtonActionPerformed(ActionEvent evt) {
|
||||
try {
|
||||
String text = editor.getText();
|
||||
if (text.trim().startsWith("#hexdata")) {
|
||||
String trimmed = text.trim();
|
||||
if (trimmed.startsWith(Helper.hexData)) {
|
||||
src.setActionBytes(Helper.getBytesFromHexaText(text));
|
||||
} else if (trimmed.startsWith(Helper.constants)) {
|
||||
throw new Error("Saving constants is not supported, yet.");
|
||||
} else {
|
||||
src.setActions(ASMParser.parse(0, true, text, src.getSwf().version, false));
|
||||
}
|
||||
@@ -786,7 +826,9 @@ public class ActionPanel extends JPanel implements SearchListener<ActionSearchRe
|
||||
|
||||
private ScriptExportMode getExportMode() {
|
||||
ScriptExportMode exportMode = hexOnlyButton.isSelected() ? ScriptExportMode.HEX
|
||||
: (hexButton.isSelected() ? ScriptExportMode.PCODE_HEX : ScriptExportMode.PCODE);
|
||||
: hexButton.isSelected() ? ScriptExportMode.PCODE_HEX
|
||||
: constantsViewButton.isSelected() ? ScriptExportMode.CONSTANTS
|
||||
: ScriptExportMode.PCODE;
|
||||
return exportMode;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2015 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.gui.controls;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.ButtonModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class NoneSelectedButtonGroup extends ButtonGroup {
|
||||
|
||||
@Override
|
||||
public void setSelected(ButtonModel model, boolean selected) {
|
||||
if (selected) {
|
||||
super.setSelected(model, selected);
|
||||
} else {
|
||||
clearSelection();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -584,3 +584,4 @@ menu.file.import.script = Import script
|
||||
contextmenu.copyTagWithDependencies = Copy tag with dependencies to
|
||||
button.replaceWithTag = Replace with other character tag
|
||||
button.resolveConstants = Resolve constants
|
||||
button.viewConstants = View Constants
|
||||
|
||||
@@ -583,3 +583,4 @@ menu.file.import.script = Szkript import\u00e1l\u00e1sa
|
||||
contextmenu.copyTagWithDependencies = M\u00e1sol\u00e1s ide f\u00fcgg\u0151s\u00e9gekkel
|
||||
button.replaceWithTag = Csere m\u00e1sik karakter tagre
|
||||
button.resolveConstants = Konstansok felold\u00e1sa
|
||||
button.viewConstants = Konstansok mutat\u00e1sa
|
||||
Reference in New Issue
Block a user