From 591e47b964c8dab8b2078549fb0cca5e5248e869 Mon Sep 17 00:00:00 2001 From: Honfika Date: Sun, 8 Sep 2013 23:13:35 +0200 Subject: [PATCH] faster disassembling --- .../src/com/jpexs/decompiler/flash/TagNode.java | 2 +- .../decompiler/flash/abc/ABCInputStream.java | 8 ++++++-- .../abc/avm2/instructions/AVM2Instruction.java | 2 +- .../flash/action/swf4/ActionPush.java | 3 ++- .../flash/gui/action/ActionPanel.java | 17 ++++++++++------- .../decompiler/flash/tags/DefineButtonTag.java | 7 +++++-- .../decompiler/flash/tags/DoActionTag.java | 7 +++++-- .../decompiler/flash/tags/DoInitActionTag.java | 7 +++++-- .../decompiler/flash/tags/base/ASMSource.java | 2 +- .../flash/types/BUTTONCONDACTION.java | 7 +++++-- .../flash/types/CLIPACTIONRECORD.java | 7 +++++-- 11 files changed, 46 insertions(+), 23 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/TagNode.java b/trunk/src/com/jpexs/decompiler/flash/TagNode.java index 81fb3cbd6..9db157480 100644 --- a/trunk/src/com/jpexs/decompiler/flash/TagNode.java +++ b/trunk/src/com/jpexs/decompiler/flash/TagNode.java @@ -299,7 +299,7 @@ public class TagNode { String res; ASMSource asm = ((ASMSource) node.tag); if (isPcode) { - res = asm.getActionSourcePrefix() + Helper.indentRows(asm.getActionSourceIndent(), asm.getASMSource(SWF.DEFAULT_VERSION, false, false), Graph.INDENT_STRING) + asm.getActionSourceSuffix(); + res = asm.getActionSourcePrefix() + Helper.indentRows(asm.getActionSourceIndent(), asm.getASMSource(SWF.DEFAULT_VERSION, false, false, null), Graph.INDENT_STRING) + asm.getActionSourceSuffix(); } else { List as = asm.getActions(SWF.DEFAULT_VERSION); Action.setActionsAddresses(as, 0, SWF.DEFAULT_VERSION); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/ABCInputStream.java b/trunk/src/com/jpexs/decompiler/flash/abc/ABCInputStream.java index 868cf2162..56bdf94e7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/ABCInputStream.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/ABCInputStream.java @@ -34,7 +34,11 @@ public class ABCInputStream extends InputStream { public static final boolean DEBUG_READ = false; public void startBuffer() { - bufferOs = new ByteArrayOutputStream(); + if (bufferOs == null) { + bufferOs = new ByteArrayOutputStream(); + } else { + bufferOs.reset(); + } } public byte[] stopBuffer() { @@ -42,7 +46,7 @@ public class ABCInputStream extends InputStream { return new byte[0]; } byte ret[] = bufferOs.toByteArray(); - bufferOs = null; + bufferOs.reset(); return ret; } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java index 1fe6919fd..2e7ed1fe9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java @@ -52,7 +52,7 @@ public class AVM2Instruction implements Serializable, GraphSourceItem { public long mappedOffset = -1; public int changeJumpTo = -1; - public AVM2Instruction(long offset, InstructionDefinition definition, int[] operands, byte bytes[]) { + public AVM2Instruction(long offset, InstructionDefinition definition, int[] operands, byte[] bytes) { this.definition = definition; this.operands = operands; this.offset = offset; diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java index 4df87c827..72d0a8723 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java @@ -78,7 +78,8 @@ public class ActionPush extends Action { values = new ArrayList<>(); sis = new SWFInputStream(new ByteArrayInputStream(sis.readBytes(actionLength)), version); try { - while ((type = sis.readUI8()) > -1) { + while (sis.available() > 0) { + type = sis.readUI8(); switch (type) { case 0: values.add(sis.readString()); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java index 718edd20a..4cedb78d8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java @@ -168,10 +168,12 @@ public class ActionPanel extends JPanel implements ActionListener { return cache.contains(src); } - private void cacheScript(ASMSource src) { + private void cacheScript(ASMSource src, List actions) { if (!cache.contains(src)) { - List as = src.getActions(SWF.DEFAULT_VERSION); - String s = Action.actionsToSource(as, SWF.DEFAULT_VERSION, src.toString()/*FIXME?*/, true); + if (actions == null) { + actions = src.getActions(SWF.DEFAULT_VERSION); + } + String s = Action.actionsToSource(actions, SWF.DEFAULT_VERSION, src.toString()/*FIXME?*/, true); List hilights = Highlighting.getInstrHighlights(s); String srcNoHex = Highlighting.stripHilights(s); cache.put(src, new CachedScript(srcNoHex, hilights)); @@ -221,7 +223,7 @@ public class ActionPanel extends JPanel implements ActionListener { } Main.startWork(workText + " \"" + txt + "\"" + decAdd + " - (" + pos + "/" + asms.size() + ") " + item.getKey() + "... "); - cacheScript(item.getValue()); + cacheScript(item.getValue(), null); if (pat.matcher(getCached(item.getValue()).text).find()) { found.add(item.getValue()); } @@ -307,7 +309,9 @@ public class ActionPanel extends JPanel implements ActionListener { } }; asm.addDisassemblyListener(listener); - lastDisasm = asm.getASMSource(SWF.DEFAULT_VERSION, true, true); + List actions = asm.getActions(SWF.DEFAULT_VERSION); + lastCode = actions; + lastDisasm = asm.getASMSource(SWF.DEFAULT_VERSION, true, true, actions); asm.removeDisassemblyListener(listener); srcWithHex = Helper.hexToComments(lastDisasm); srcNoHex = Helper.stripComments(lastDisasm); @@ -319,9 +323,8 @@ public class ActionPanel extends JPanel implements ActionListener { if (!useCache) { uncache(asm); } - cacheScript(asm); + cacheScript(asm, actions); CachedScript sc = getCached(asm); - lastCode = asm.getActions(SWF.DEFAULT_VERSION); decompiledHilights = sc.hilights; lastDecompiled = sc.text; lastASM = asm; diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java index 27dd534f9..c864e896a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java @@ -136,8 +136,11 @@ public class DefineButtonTag extends CharacterTag implements ASMSource, BoundedT * @return ASM source */ @Override - public String getASMSource(int version, boolean hex, boolean highlight) { - return Action.actionsToString(listeners, 0, getActions(version), null, version, hex, highlight, getPos() + hdrSize, toString()/*FIXME?*/); + public String getASMSource(int version, boolean hex, boolean highlight, List actions) { + if (actions == null) { + actions = getActions(version); + } + return Action.actionsToString(listeners, 0, actions, null, version, hex, highlight, getPos() + hdrSize, toString()/*FIXME?*/); } /** diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DoActionTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DoActionTag.java index 3c7d1d759..bfe827c57 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DoActionTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DoActionTag.java @@ -76,8 +76,11 @@ public class DoActionTag extends Tag implements ASMSource { * @return ASM source */ @Override - public String getASMSource(int version, boolean hex, boolean highlight) { - return Action.actionsToString(listeners, 0, getActions(version), null, version, hex, highlight, getPos(), toString()/*FIXME?*/); + public String getASMSource(int version, boolean hex, boolean highlight, List actions) { + if (actions == null) { + actions = getActions(version); + } + return Action.actionsToString(listeners, 0, actions, null, version, hex, highlight, getPos(), toString()/*FIXME?*/); } /** diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java index 88804ef60..ffa85fbc0 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java @@ -102,8 +102,11 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource { * @return ASM source */ @Override - public String getASMSource(int version, boolean hex, boolean highlight) { - return Action.actionsToString(listeners, 0, getActions(version), null, version, hex, highlight, getPos() + 2, toString()/*FIXME?*/); + public String getASMSource(int version, boolean hex, boolean highlight, List actions) { + if (actions == null) { + actions = getActions(version); + } + return Action.actionsToString(listeners, 0, actions, null, version, hex, highlight, getPos() + 2, toString()/*FIXME?*/); } @Override 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 d0e226f17..2f1b88e46 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java @@ -34,7 +34,7 @@ public interface ASMSource { * @param hex Add hexadecimal? * @return ASM source */ - public String getASMSource(int version, boolean hex, boolean highlight); + public String getASMSource(int version, boolean hex, boolean highlight, List actions); /** * Whether or not this object contains ASM source diff --git a/trunk/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java b/trunk/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java index 921ae089f..59b5e2962 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java @@ -148,8 +148,11 @@ public class BUTTONCONDACTION implements ASMSource, Exportable, ContainerItem { * @return ASM source */ @Override - public String getASMSource(int version, boolean hex, boolean highlight) { - return Action.actionsToString(listeners, 0, getActions(version), null, version, hex, highlight, getPos() + 4, toString()/*FIXME?*/); + public String getASMSource(int version, boolean hex, boolean highlight, List actions) { + if (actions == null) { + actions = getActions(version); + } + return Action.actionsToString(listeners, 0, actions, null, version, hex, highlight, getPos() + 4, toString()/*FIXME?*/); } /** diff --git a/trunk/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java b/trunk/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java index 9e87a75f8..b04f90a2a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java @@ -152,8 +152,11 @@ public class CLIPACTIONRECORD implements ASMSource, Exportable, ContainerItem { * @return ASM source */ @Override - public String getASMSource(int version, boolean hex, boolean highlight) { - return Action.actionsToString(listeners, 0, getActions(version), null, version, hex, highlight, getPos() + hdrPos, toString()/*FIXME?*/); + public String getASMSource(int version, boolean hex, boolean highlight, List actions) { + if (actions == null) { + actions = getActions(version); + } + return Action.actionsToString(listeners, 0, actions, null, version, hex, highlight, getPos() + hdrPos, toString()/*FIXME?*/); } /**