From 1003ca35f3eecca4d211f620fb8f83398f01d281 Mon Sep 17 00:00:00 2001 From: Honfika Date: Fri, 27 Dec 2013 23:49:02 +0100 Subject: [PATCH] goto document class with multiple opened swfs issue fixed --- .../com/jpexs/decompiler/flash/gui/Main.java | 5 ++- .../decompiler/flash/gui/MainFramePanel.java | 22 ++++++------- .../decompiler/flash/gui/TagTreeModel.java | 15 +++++---- .../decompiler/flash/gui/abc/ABCPanel.java | 33 +++++++++---------- .../flash/gui/abc/ClassesListTree.java | 7 ++-- .../decompiler/flash/tags/base/ASMSource.java | 3 +- 6 files changed, 45 insertions(+), 40 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/Main.java b/trunk/src/com/jpexs/decompiler/flash/gui/Main.java index 9fbc69f36..1b2d983c2 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/Main.java @@ -305,6 +305,7 @@ public class Main { @Override protected Object doInBackground() throws Exception { + boolean first = true; for (SWFSourceInfo sourceInfo : sourceInfos) { SWF swf = null; try { @@ -319,6 +320,8 @@ public class Main { } final SWF swf1 = swf; + final boolean first1 = first; + first = false; try { Main.startWork(AppStrings.translate("work.creatingwindow") + "..."); View.execInEventDispatch(new Runnable() { @@ -331,7 +334,7 @@ public class Main { mainFrame = new MainFrameClassic(); } } - mainFrame.getPanel().load(swf1); + mainFrame.getPanel().load(swf1, first1); if (errorState) { mainFrame.getPanel().setErrorState(); } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFramePanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFramePanel.java index d016781ff..23690a289 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFramePanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFramePanel.java @@ -848,11 +848,9 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree enableDrop(true); } - public void load(SWF swf) { + public void load(SWF swf, boolean first) { List objs = new ArrayList<>(); - if (swf != null) { - objs.addAll(swf.tags); - } + objs.addAll(swf.tags); ArrayList abcList = new ArrayList<>(); getActionScript3(objs, abcList); @@ -868,7 +866,7 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree displayPanel.add(abcPanel, CARDACTIONSCRIPT3PANEL); detailPanel.add(abcPanel.tabbedPane, DETAILCARDAS3NAVIGATOR); } - abcPanel.setSwf(abcList, swf); + abcPanel.setSwf(swf); } else { if (actionPanel == null) { actionPanel = new ActionPanel(this); @@ -907,6 +905,10 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree showDetail(DETAILCARDEMPTYPANEL); showCard(CARDEMPTYPANEL); updateUi(swf); + + if (first && Configuration.gotoMainClassOnStartup.get()) { + gotoDocumentClass(swf); + } } private void updateUi(final SWF swf) { @@ -918,7 +920,7 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree boolean hasAbc = !abcList.isEmpty(); if (hasAbc) { - abcPanel.setSwf(abcList, swf); + abcPanel.setSwf(swf); } if (isWelcomeScreen) { @@ -1067,9 +1069,6 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree splitPos = splitPane2.getDividerLocation(); splitsInited = true; - if (Configuration.gotoMainClassOnStartup.get()) { - gotoDocumentClass(getCurrentSwf()); - } } }); @@ -1535,6 +1534,7 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree if (documentClass != null) { showDetail(DETAILCARDAS3NAVIGATOR); showCard(CARDACTIONSCRIPT3PANEL); + abcPanel.setSwf(swf); abcPanel.hilightScript(documentClass); } } @@ -1796,7 +1796,7 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree protected Object doInBackground() throws Exception { int cnt = 0; if (all) { - for (ABCContainerTag tag : abcPanel.list) { + for (ABCContainerTag tag : abcPanel.swf.abcList) { tag.getABC().restoreControlFlow(); } } else { @@ -1881,7 +1881,7 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree protected Object doInBackground() throws Exception { try { if (deobfuscationDialog.processAllCheckbox.isSelected()) { - for (ABCContainerTag tag : abcPanel.list) { + for (ABCContainerTag tag : abcPanel.swf.abcList) { if (deobfuscationDialog.codeProcessingLevel.getValue() == DeobfuscationDialog.LEVEL_REMOVE_DEAD_CODE) { tag.getABC().removeDeadCode(); } else if (deobfuscationDialog.codeProcessingLevel.getValue() == DeobfuscationDialog.LEVEL_REMOVE_TRAPS) { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/TagTreeModel.java b/trunk/src/com/jpexs/decompiler/flash/gui/TagTreeModel.java index c914ae711..08d472c55 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/TagTreeModel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/TagTreeModel.java @@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.FrameNode; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.StringNode; import com.jpexs.decompiler.flash.TagNode; +import com.jpexs.decompiler.flash.TreeElementItem; import com.jpexs.decompiler.flash.TreeNode; import com.jpexs.decompiler.flash.gui.abc.ClassesListTreeModel; import com.jpexs.decompiler.flash.gui.abc.TreeElement; @@ -210,18 +211,18 @@ public class TagTreeModel implements TreeModel { return ret; } - private List searchTag(Object obj, Object parent, List path) { - List ret = null; + private List searchTag(TreeElementItem obj, TreeNode parent, List path) { + List ret = null; int cnt = getChildCount(parent); for (int i = 0; i < cnt; i++) { - Object n = getChild(parent, i); - List newPath = new ArrayList<>(); + TreeNode n = getChild(parent, i); + List newPath = new ArrayList<>(); newPath.addAll(path); newPath.add(n); if (n instanceof TreeElement) { TreeElement te = (TreeElement) n; - Object it = te.getItem(); + TreeElementItem it = te.getItem(); if (obj == it) { return newPath; } @@ -240,8 +241,8 @@ public class TagTreeModel implements TreeModel { return ret; } - public TreePath getTagPath(Object obj) { - List path = new ArrayList<>(); + public TreePath getTagPath(TreeElementItem obj) { + List path = new ArrayList<>(); path.add(getRoot()); path = searchTag(obj, getRoot(), path); TreePath tp = new TreePath(path.toArray(new Object[path.size()])); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index 71d853383..5c119ae29 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -84,7 +84,6 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr public TraitsList navigator; public ClassesListTree classTree; public ABC abc; - public List list; public SWF swf; public JComboBox abcComboBox; public int listIndex = -1; @@ -143,7 +142,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr @Override public Void doInBackground() throws Exception { - decompiledTextArea.cacheScriptPack(item.value, list); + decompiledTextArea.cacheScriptPack(item.value, swf.abcList); if (pat.matcher(decompiledTextArea.getCachedText(item.value)).find()) { found.add(item.value); foundPath.add(item.key); @@ -168,7 +167,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr return false; } else { foundPos = 0; - decompiledTextArea.setScript(found.get(foundPos), list); + decompiledTextArea.setScript(found.get(foundPos), swf.abcList); searchPanel.setVisible(true); searchFor = txt; updateSearchPos(); @@ -270,7 +269,6 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr @SuppressWarnings("unchecked") public void clearSwf() { - this.list = null; this.swf = null; this.abc = null; constantTable.setModel(new DefaultTableModel()); @@ -280,17 +278,18 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr } @SuppressWarnings("unchecked") - public void setSwf(List list, SWF swf) { - this.list = list; - this.swf = swf; - listIndex = -1; - switchAbc(0); // todo honika: do we need this? - abcComboBox.setModel(new ABCComboBoxModel(list)); - if (list.size() > 0) { - this.abc = list.get(0).getABC(); - } + public void setSwf(SWF swf) { + if (this.swf != swf) { + this.swf = swf; + listIndex = -1; + switchAbc(0); // todo honika: do we need this? + abcComboBox.setModel(new ABCComboBoxModel(swf.abcList)); + if (swf.abcList.size() > 0) { + this.abc = swf.abcList.get(0).getABC(); + } - navigator.setABC(list, abc); + navigator.setABC(swf.abcList, abc); + } } public void switchAbc(int index) { @@ -298,7 +297,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr classTree.setSwf(swf); if (index != -1) { - this.abc = list.get(index).getABC(); + this.abc = swf.abcList.get(index).getABC(); } updateConstList(); } @@ -525,7 +524,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr } int multinameIndex = constantTable.convertRowIndexToModel(rowIndex); if (multinameIndex > 0) { - UsageFrame usageFrame = new UsageFrame(t.list, abc, multinameIndex, t); + UsageFrame usageFrame = new UsageFrame(t.swf.abcList, abc, multinameIndex, t); usageFrame.setVisible(true); } } @@ -602,7 +601,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr searchPos.setText((foundPos + 1) + "/" + found.size()); ScriptPack pack = found.get(foundPos); setAbc(pack.abc); - decompiledTextArea.setScript(pack, list); + decompiledTextArea.setScript(pack, swf.abcList); hilightScript(found.get(foundPos)); decompiledTextArea.setCaretPosition(0); SwingUtilities.invokeLater(new Runnable() { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTree.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTree.java index d6eb54b5a..8bf3bd471 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTree.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTree.java @@ -97,9 +97,10 @@ public final class ClassesListTree extends JTree implements TreeSelectionListene public void setSwf(SWF swf) { if (swf != this.swf) { this.swf = swf; - ClassesListTreeModel model = new ClassesListTreeModel(swf); - this.swf.classTreeModel = model; - setModel(model); + if (swf.classTreeModel == null) { + swf.classTreeModel = new ClassesListTreeModel(swf); + } + setModel(swf.classTreeModel); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java index b6d348e6d..e7a13750a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.tags.base; import com.jpexs.decompiler.flash.DisassemblyListener; +import com.jpexs.decompiler.flash.TreeElementItem; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.graph.ExportMode; @@ -27,7 +28,7 @@ import java.util.List; * * @author JPEXS */ -public interface ASMSource { +public interface ASMSource extends TreeElementItem { /** * Converts actions to ASM source