shown only the constant pool(s) in pcode editor

This commit is contained in:
honfika@gmail.com
2015-05-07 15:25:28 +02:00
parent e7c8a8bf06
commit 732087f20f
11 changed files with 147 additions and 30 deletions

View File

@@ -50,6 +50,7 @@ import com.jpexs.decompiler.flash.action.swf4.ActionIf;
import com.jpexs.decompiler.flash.action.swf4.ActionNot;
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.action.swf4.RegisterNumber;
import com.jpexs.decompiler.flash.action.swf5.ActionConstantPool;
import com.jpexs.decompiler.flash.action.swf5.ActionDefineFunction;
import com.jpexs.decompiler.flash.action.swf5.ActionEquals2;
import com.jpexs.decompiler.flash.action.swf7.ActionDefineFunction2;
@@ -412,6 +413,10 @@ public abstract class Action implements GraphSourceItem {
* @return GraphTextWriter
*/
public static GraphTextWriter actionsToString(List<DisassemblyListener> listeners, long address, ActionList list, int version, ScriptExportMode exportMode, GraphTextWriter writer) {
if (exportMode == ScriptExportMode.CONSTANTS) {
return constantPoolActionsToString(listeners, address, list, version, exportMode, writer);
}
long offset;
Set<Long> importantOffsets = getActionsAllRefs(list);
/*List<ConstantPool> cps = SWFInputStream.getConstantPool(new ArrayList<DisassemblyListener>(), new ActionGraphSource(list, version, new HashMap<Integer, String>(), new HashMap<String, GraphTargetItem>(), new HashMap<String, GraphTargetItem>()), 0, version, path);
@@ -423,14 +428,13 @@ public abstract class Action implements GraphSourceItem {
offset = address;
int pos = 0;
boolean lastPush = false;
for (GraphSourceItem s : list) {
for (Action a : list) {
if (pos % INFORM_LISTENER_RESOLUTION == 0) {
for (DisassemblyListener listener : listeners) {
listener.progressToString(pos + 1, list.size());
}
}
Action a = (Action) s;
if (exportMode == ScriptExportMode.PCODE_HEX) {
if (lastPush) {
writer.newLine();
@@ -585,6 +589,30 @@ public abstract class Action implements GraphSourceItem {
return writer;
}
public static GraphTextWriter constantPoolActionsToString(List<DisassemblyListener> listeners, long address, ActionList list, int version, ScriptExportMode exportMode, GraphTextWriter writer) {
int poolIdx = 0;
writer.appendNoHilight(Helper.constants).newLine();
for (Action a : list) {
if (a instanceof ActionConstantPool) {
ActionConstantPool cPool = (ActionConstantPool) a;
int constIdx = 0;
for (String c : cPool.constantPool) {
writer.appendNoHilight(poolIdx);
writer.appendNoHilight("|");
writer.appendNoHilight(constIdx);
writer.appendNoHilight("|");
writer.appendNoHilight(c);
writer.newLine();
constIdx++;
}
poolIdx++;
}
}
return writer;
}
/**
* Convert action to ASM source
*

View File

@@ -1,18 +1,19 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library 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
* 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.exporters.modes;
/**
@@ -21,5 +22,5 @@ package com.jpexs.decompiler.flash.exporters.modes;
*/
public enum ScriptExportMode {
AS, PCODE, PCODE_HEX, HEX, CONSTANTS;
}

View File

@@ -110,6 +110,7 @@ public class DoActionTag extends Tag implements ASMSource {
if (actions == null) {
actions = getActions();
}
return Action.actionsToString(listeners, 0, actions, swf.version, exportMode, writer);
}

View File

@@ -66,6 +66,10 @@ public class Helper {
public static String newLine = System.getProperty("line.separator");
public static String hexData = "#hexdata";
public static String constants = "#constants";
public static String decompilationErrorAdd = null;
private static final Map<String, Area> shapeCache = new HashMap<>();

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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();
}
}
}

View File

@@ -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

View File

@@ -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