diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ABCContainerTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ABCContainerTag.java index bde90f277..ef58ef708 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ABCContainerTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ABCContainerTag.java @@ -28,4 +28,6 @@ public interface ABCContainerTag extends Comparable { public ABC getABC(); public SWF getSwf(); + + public void setABC(ABC abc); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABC2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABC2Tag.java index fe4871556..e15216737 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABC2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABC2Tag.java @@ -117,6 +117,8 @@ public class DoABC2Tag extends Tag implements ABCContainerTag { return abc; } + + @Override public String getName() { return super.getName() + (!name.isEmpty() ? " (" + name + ")" : ""); @@ -143,4 +145,9 @@ public class DoABC2Tag extends Tag implements ABCContainerTag { } } } + + @Override + public void setABC(ABC abc) { + this.abc = abc; + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCTag.java index 3b645768a..2eb2ed9a4 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoABCTag.java @@ -110,4 +110,9 @@ public class DoABCTag extends Tag implements ABCContainerTag { } } } + + @Override + public void setABC(ABC abc) { + this.abc = abc; + } } diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3AssemblerTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3AssemblerTest.java index 2163885f7..10eea8333 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3AssemblerTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3AssemblerTest.java @@ -77,6 +77,10 @@ public class ActionScript3AssemblerTest extends ActionScriptTestBase { public int compareTo(ABCContainerTag o) { return 0; } + + @Override + public void setABC(ABC abc) { + } }); } diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DeobfuscatorTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DeobfuscatorTest.java index defb3f9ab..ec9c09bda 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DeobfuscatorTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3DeobfuscatorTest.java @@ -87,6 +87,10 @@ public class ActionScript3DeobfuscatorTest extends ActionScriptTestBase { public int compareTo(ABCContainerTag o) { return 0; } + + @Override + public void setABC(ABC abc) { + } }); MethodBody b = new MethodBody(abc, new Traits(), new byte[0], new ABCException[0]); AVM2Code code = ASM3Parser.parse(abc, new StringReader(str), null, b, new MethodInfo()); @@ -118,6 +122,10 @@ public class ActionScript3DeobfuscatorTest extends ActionScriptTestBase { public int compareTo(ABCContainerTag o) { return 0; } + + @Override + public void setABC(ABC abc) { + } }); ActionScript3Parser par = new ActionScript3Parser(abc, new ArrayList<>(), false); HighlightedTextWriter writer = new HighlightedTextWriter(new CodeFormatting(), false); diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index bfe03a76f..cd9896d4a 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -934,7 +934,9 @@ public class Main { doABC2Tag.setTimelined(dummySwf); dummySwf.clearModified(); startWork(AppStrings.translate("work.reading.abc"), this); - return new ABC(new ABCInputStream(new MemoryInputStream(Helper.readFile(file))), dummySwf, doABC2Tag, file, fileTitle); + ABC abc = new ABC(new ABCInputStream(new MemoryInputStream(Helper.readFile(file))), dummySwf, doABC2Tag, file, fileTitle); + doABC2Tag.setABC(abc); + return abc; } @Override diff --git a/src/com/jpexs/decompiler/flash/gui/abc/AddClassDialog.java b/src/com/jpexs/decompiler/flash/gui/abc/AddClassDialog.java index 645123372..53ee236dc 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/AddClassDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/AddClassDialog.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.gui.abc; import com.jpexs.decompiler.flash.SWF; +import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.gui.AppDialog; import com.jpexs.decompiler.flash.gui.Main; @@ -25,6 +26,7 @@ import com.jpexs.decompiler.flash.gui.View; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.timeline.Timelined; +import com.jpexs.decompiler.flash.treeitems.Openable; import java.awt.Component; import java.awt.Container; import java.awt.FlowLayout; @@ -60,24 +62,29 @@ public class AddClassDialog extends AppDialog { private Tag selectedPosition; private Timelined selectedTimelined; private int result = ERROR_OPTION; - - private SWF swf; - + + private Openable openable; + private int abcCount = 0; - + private JRadioButton existingAbcTagRadioButton = new JRadioButton(translate("abc.where.existing")); private JRadioButton newAbcTagRadioButton = new JRadioButton(translate("abc.where.new")); - public AddClassDialog(Window owner, SWF swf) { + public AddClassDialog(Window owner, Openable openable) { super(owner); - this.swf = swf; + this.openable = openable; abcCount = 0; - for(Tag t : swf.getTags()) { - if (t instanceof ABCContainerTag) { - abcCount++; + if (openable instanceof SWF) { + SWF swf = (SWF) openable; + for (Tag t : swf.getTags()) { + if (t instanceof ABCContainerTag) { + abcCount++; + } } + } else { + abcCount = 1; } - + setDefaultCloseOperation(HIDE_ON_CLOSE); setTitle(translate("dialog.title")); @@ -101,18 +108,23 @@ public class AddClassDialog extends AppDialog { }); ButtonGroup abcTargetButtonGroup = new ButtonGroup(); abcTargetButtonGroup.add(existingAbcTagRadioButton); - abcTargetButtonGroup.add(newAbcTagRadioButton); + abcTargetButtonGroup.add(newAbcTagRadioButton); existingAbcTagRadioButton.setSelected(true); abcTargetPanel.add(existingAbcTagRadioButton); abcTargetPanel.add(newAbcTagRadioButton); - + if (abcCount == 0) { newAbcTagRadioButton.setSelected(true); abcTargetPanel.setVisible(false); } - + + if (openable instanceof ABC) { + existingAbcTagRadioButton.setSelected(true); + abcTargetPanel.setVisible(false); + } + JPanel buttonsPanel = new JPanel(new FlowLayout()); - proceedButton.addActionListener(this::okButtonActionPerformed); + proceedButton.addActionListener(this::okButtonActionPerformed); cancelButton.addActionListener(this::cancelButtonActionPerformed); buttonsPanel.add(proceedButton); buttonsPanel.add(cancelButton); @@ -121,7 +133,7 @@ public class AddClassDialog extends AppDialog { classNameLabel.setAlignmentX(JLabel.CENTER); cnt.add(classNameLabel); cnt.add(classNameTextField); - + cnt.add(abcTargetPanel); cnt.add(buttonsPanel); @@ -154,14 +166,13 @@ public class AddClassDialog extends AppDialog { } private void checkEnabled() { - + if (existingAbcTagRadioButton.isSelected() && abcCount == 1) { proceedButton.setText(translate("button.ok")); } else { proceedButton.setText(translate("button.proceed")); } - - + boolean ok = true; if (classNameTextField.getText().isEmpty()) { @@ -173,16 +184,32 @@ public class AddClassDialog extends AppDialog { } if (ok) { - SWF swf = Main.getMainFrame().getPanel().getCurrentSwf(); - List classNames = new ArrayList<>(); - classNames.add(classNameTextField.getText()); - try { - List scriptPacks = swf.getScriptPacksByClassNames(classNames); - if (!scriptPacks.isEmpty()) { + + if (openable instanceof SWF) { + SWF swf = (SWF) openable; + List classNames = new ArrayList<>(); + classNames.add(classNameTextField.getText()); + try { + List scriptPacks = swf.getScriptPacksByClassNames(classNames); + if (!scriptPacks.isEmpty()) { + ok = false; + } + } catch (Exception ex) { + ok = false; + } + } + if (openable instanceof ABC) { + ABC abc = (ABC) openable; + List allAbcs = new ArrayList<>(); + allAbcs.add(abc); + try { + List scriptPacks = abc.findScriptPacksByPath(classNameTextField.getText(), allAbcs); + if (!scriptPacks.isEmpty()) { + ok = false; + } + } catch (Exception ex) { ok = false; } - } catch (Exception ex) { - ok = false; } } @@ -194,27 +221,31 @@ public class AddClassDialog extends AppDialog { return; } setVisible(false); - if (existingAbcTagRadioButton.isSelected()) { - SelectDoABCDialog selectDoABCDialog = new SelectDoABCDialog(owner, swf); - selectedAbcContainer = selectDoABCDialog.showDialog(); - if (selectedAbcContainer == null) { - cancelButtonActionPerformed(evt); - return; + if (openable instanceof ABC) { + selectedAbcContainer = ((ABC) openable).parentTag; + } else { + if (existingAbcTagRadioButton.isSelected()) { + SelectDoABCDialog selectDoABCDialog = new SelectDoABCDialog(owner, (SWF) openable); + selectedAbcContainer = selectDoABCDialog.showDialog(); + if (selectedAbcContainer == null) { + cancelButtonActionPerformed(evt); + return; + } + } + if (newAbcTagRadioButton.isSelected()) { + SelectTagPositionDialog selectTagPositionDialog = new SelectTagPositionDialog(owner, (SWF) openable, true); + if (selectTagPositionDialog.showDialog() != OK_OPTION) { + cancelButtonActionPerformed(evt); + return; + } + selectedPosition = selectTagPositionDialog.getSelectedTag(); + selectedTimelined = selectTagPositionDialog.getSelectedTimelined(); } } - if (newAbcTagRadioButton.isSelected()) { - SelectTagPositionDialog selectTagPositionDialog = new SelectTagPositionDialog(owner, swf, true); - if (selectTagPositionDialog.showDialog() != OK_OPTION) { - cancelButtonActionPerformed(evt); - return; - } - selectedPosition = selectTagPositionDialog.getSelectedTag(); - selectedTimelined = selectTagPositionDialog.getSelectedTimelined(); - } - + result = OK_OPTION; selectedClass = classNameTextField.getText(); - setVisible(false); + setVisible(false); } private void cancelButtonActionPerformed(ActionEvent evt) { @@ -229,6 +260,7 @@ public class AddClassDialog extends AppDialog { public int showDialog() { return showDialog(""); } + public int showDialog(String pkg) { classNameTextField.setText(pkg); selectedClass = null; @@ -253,5 +285,5 @@ public class AddClassDialog extends AppDialog { public ABCContainerTag getSelectedAbcContainer() { return selectedAbcContainer; - } + } } diff --git a/src/com/jpexs/decompiler/flash/gui/abc/RootABCContainerTag.java b/src/com/jpexs/decompiler/flash/gui/abc/RootABCContainerTag.java index 6a356e943..2bd365fb6 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/RootABCContainerTag.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/RootABCContainerTag.java @@ -48,4 +48,8 @@ public class RootABCContainerTag implements ABCContainerTag { public String toString() { return " - all - "; } + + @Override + public void setABC(ABC abc) { + } } diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java index dba245922..d7f0beaee 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java @@ -1548,10 +1548,11 @@ public class TagTreeContextMenu extends JPopupMenu { List sel = getTree().getSelected(); if (!sel.isEmpty()) { SWF swf = null; + Openable openable = null; String preselected = ""; if (sel.get(0) instanceof ClassesListTreeModel) { ClassesListTreeModel cl = (ClassesListTreeModel) sel.get(0); - Openable openable = cl.getOpenable(); + openable = cl.getOpenable(); if (openable instanceof SWF) { swf = (SWF) openable; } else { @@ -1560,7 +1561,7 @@ public class TagTreeContextMenu extends JPopupMenu { } if (sel.get(0) instanceof AS3Package) { AS3Package pkg = (AS3Package) sel.get(0); - Openable openable = pkg.getOpenable(); + openable = pkg.getOpenable(); if (openable instanceof SWF) { swf = (SWF) openable; } else { @@ -1572,6 +1573,9 @@ public class TagTreeContextMenu extends JPopupMenu { if (path[p] instanceof ClassesListTreeModel) { break; } + if (path[p] instanceof ABC) { + break; + } if (((AS3Package) path[p]).isDefaultPackage()) { break; } @@ -1580,12 +1584,12 @@ public class TagTreeContextMenu extends JPopupMenu { } TreePath scriptsPath = tree.getSelectionPaths()[0]; - while (!(scriptsPath.getLastPathComponent() instanceof ClassesListTreeModel)) { + while (!(scriptsPath.getLastPathComponent() instanceof ClassesListTreeModel) && !(scriptsPath.getLastPathComponent() instanceof ABC)) { scriptsPath = scriptsPath.getParentPath(); } { - AddClassDialog acd = new AddClassDialog(Main.getDefaultDialogsOwner(), swf); + AddClassDialog acd = new AddClassDialog(Main.getDefaultDialogsOwner(), openable); if (acd.showDialog(preselected) != AppDialog.OK_OPTION) { return; }