From 24bfd5f5ee6f5e33f139796fde2b180fa01ee14b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sun, 23 Jun 2013 19:06:56 +0200 Subject: [PATCH] Issue #134 Goto document class --- .../decompiler/flash/abc/ScriptPack.java | 2 +- .../decompiler/flash/abc/gui/ABCPanel.java | 20 +++++++++++--- .../flash/abc/gui/ClassesListTreeModel.java | 4 +-- .../flash/abc/types/ScriptInfo.java | 2 +- .../jpexs/decompiler/flash/gui/MainFrame.java | 26 +++++++++++++++++++ 5 files changed, 46 insertions(+), 8 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java b/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java index 2fed410bc..0586c42ff 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java @@ -77,7 +77,7 @@ public class ScriptPack { scriptName = name.getName(abc.constants, new ArrayList()); } } - return packageName + "." + scriptName; + return packageName.equals("") ? scriptName : packageName + "." + scriptName; } private static String makeDirPath(String packageName) { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/gui/ABCPanel.java b/trunk/src/com/jpexs/decompiler/flash/abc/gui/ABCPanel.java index fd61b32b2..54dd7129d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/gui/ABCPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/gui/ABCPanel.java @@ -446,13 +446,25 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener { setVisible(true); } + public void hilightScript(String name) { + ClassesListTreeModel clModel = (ClassesListTreeModel) classTree.getModel(); + ScriptPack pack = clModel.getList().get(name); + if (pack != null) { + hilightScript(pack); + } + } + + public void hilightScript(ScriptPack pack) { + TagTreeModel ttm = (TagTreeModel) Main.mainFrame.tagTree.getModel(); + TreePath tp = ttm.getTagPath(pack); + Main.mainFrame.tagTree.setSelectionPath(tp); + Main.mainFrame.tagTree.scrollPathToVisible(tp); + } + public void updateSearchPos() { searchPos.setText((foundPos + 1) + "/" + found.size()); decompiledTextArea.setScript(found.get(foundPos), list); - TagTreeModel ttm = (TagTreeModel) Main.mainFrame.tagTree.getModel(); - TreePath tp = ttm.getTagPath(found.get(foundPos)); - Main.mainFrame.tagTree.setSelectionPath(tp); - Main.mainFrame.tagTree.scrollPathToVisible(tp); + hilightScript(found.get(foundPos)); decompiledTextArea.setCaretPosition(0); java.util.Timer t = new java.util.Timer(); t.schedule(new TimerTask() { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/gui/ClassesListTreeModel.java b/trunk/src/com/jpexs/decompiler/flash/abc/gui/ClassesListTreeModel.java index cde87024c..91052bc32 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/gui/ClassesListTreeModel.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/gui/ClassesListTreeModel.java @@ -94,8 +94,8 @@ public class ClassesListTreeModel implements TreeModel { } } } - String nsName = path.substring(path.lastIndexOf(".") + 1); - String packageName = path.substring(0, path.lastIndexOf(".")); + String nsName = path.contains(".") ? path.substring(path.lastIndexOf(".") + 1) : path; + String packageName = path.contains(".") ? path.substring(0, path.lastIndexOf(".")) : ""; classTree.add(nsName, packageName, list.get(path)); } this.list = list; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java index 4a4a983ae..03a10bd46 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java @@ -52,7 +52,7 @@ public class ScriptInfo { || (ns.kind == Namespace.KIND_PACKAGE)) { String packageName = ns.getName(abc.constants); String objectName = name.getName(abc.constants, new ArrayList()); - String path = packageName + "." + objectName; + String path = packageName.equals("") ? objectName : packageName + "." + objectName; List traitIndices = new ArrayList<>(); traitIndices.add(j); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java index 0519b346c..23fabb6cd 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java @@ -72,6 +72,7 @@ import com.jpexs.decompiler.flash.tags.SoundStreamBlockTag; import com.jpexs.decompiler.flash.tags.SoundStreamHead2Tag; import com.jpexs.decompiler.flash.tags.SoundStreamHeadTag; import com.jpexs.decompiler.flash.tags.SoundStreamHeadTypeTag; +import com.jpexs.decompiler.flash.tags.SymbolClassTag; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.ASMSource; import com.jpexs.decompiler.flash.tags.base.AloneTag; @@ -403,6 +404,13 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi //menuTools.add(menuDeobfuscation); menuTools.add(menuDeobfuscation); + + JMenuItem miGotoDocumentClass = new JMenuItem("Go to document class"); + miGotoDocumentClass.setActionCommand("GOTODOCUMENTCLASS"); + miGotoDocumentClass.addActionListener(this); + if (swf.fileAttributes.actionScript3) { + menuTools.add(miGotoDocumentClass); + } menuBar.add(menuTools); JMenu menuHelp = new JMenu("Help"); @@ -1239,6 +1247,24 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi @Override public void actionPerformed(ActionEvent e) { switch (e.getActionCommand()) { + case "GOTODOCUMENTCLASS": + String documentClass = null; + loopdc: + for (Tag t : swf.tags) { + if (t instanceof SymbolClassTag) { + SymbolClassTag sc = (SymbolClassTag) t; + for (int i = 0; i < sc.tagIDs.length; i++) { + if (sc.tagIDs[i] == 0) { + documentClass = sc.classNames[i]; + break loopdc; + } + } + } + } + if (documentClass != null) { + abcPanel.hilightScript(documentClass); + } + break; case "PARALLELSPEEDUP": String confStr = "Parallelism can speed up loading and decompilation but uses more memory.\r\n"; if (miParallelSpeedUp.isSelected()) {