diff --git a/CHANGELOG.md b/CHANGELOG.md index 868787491..4ad305eb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file. - #1311, #1313 actionScript source font size - Display warning when library version and GUI version mismatch - Changelog file +- #1308 Search by all P-code files (AS 1/2 only) ### Changed - #1189 AS3 - sort imports to have same order always diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index 38a38aa45..6ec2550ed 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -20,7 +20,6 @@ import SevenZip.Compression.LZMA.Decoder; import SevenZip.Compression.LZMA.Encoder; import com.jpexs.debugger.flash.SWD; import com.jpexs.decompiler.flash.abc.ABC; -import com.jpexs.decompiler.flash.abc.CachedDecompilation; import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.RenameType; import com.jpexs.decompiler.flash.abc.ScriptPack; @@ -46,7 +45,6 @@ import com.jpexs.decompiler.flash.action.ActionGraphSource; import com.jpexs.decompiler.flash.action.ActionList; import com.jpexs.decompiler.flash.action.ActionListReader; import com.jpexs.decompiler.flash.action.ActionLocalData; -import com.jpexs.decompiler.flash.action.CachedScript; import com.jpexs.decompiler.flash.action.model.ConstantPool; import com.jpexs.decompiler.flash.action.model.DirectValueActionItem; import com.jpexs.decompiler.flash.action.model.FunctionActionItem; @@ -343,10 +341,10 @@ public final class SWF implements SWFContainerItem, Timelined { private final Cache as2PcodeCache = Cache.getInstance(true, true, "as2pcode"); @Internal - private final Cache as2Cache = Cache.getInstance(true, false, "as2"); + private final Cache as2Cache = Cache.getInstance(true, false, "as2"); @Internal - private final Cache as3Cache = Cache.getInstance(true, false, "as3"); + private final Cache as3Cache = Cache.getInstance(true, false, "as3"); public static List swfSignatures = Arrays.asList( "FWS", // Uncompressed Flash @@ -2640,7 +2638,7 @@ public final class SWF implements SWFContainerItem, Timelined { } } - public static CachedScript getFromCache(ASMSource src) { + public static HighlightedText getFromCache(ASMSource src) { SWF swf = src.getSwf(); if (swf.as2Cache.contains(src)) { return swf.as2Cache.get(src); @@ -2649,32 +2647,23 @@ public final class SWF implements SWFContainerItem, Timelined { return null; } - public static CachedScript getCached(ASMSource src, ActionList actions) throws InterruptedException { + public static HighlightedText getCached(ASMSource src, ActionList actions) throws InterruptedException { SWF swf = src.getSwf(); if (swf.as2Cache.contains(src)) { return swf.as2Cache.get(src); } - if (actions == null) { - actions = src.getActions(); - } - HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true); writer.startFunction("!script"); - Action.actionsToSource(src, actions, src.toString()/*FIXME?*/, writer); + src.getActionScriptSource(writer, actions); writer.endFunction(); - List hilights = writer.instructionHilights; - List methodHilights = writer.methodHilights; - List classHilights = writer.classHilights; - List specialHilights = writer.specialHilights; - String srcNoHex = writer.toString(); - CachedScript res = new CachedScript(srcNoHex, hilights, methodHilights, classHilights, specialHilights); + HighlightedText res = new HighlightedText(writer); swf.as2Cache.put(src, res); return res; } - public static CachedDecompilation getCached(ScriptPack pack) throws InterruptedException { + public static HighlightedText getCached(ScriptPack pack) throws InterruptedException { SWF swf = pack.getSwf(); if (swf.as3Cache.contains(pack)) { return swf.as3Cache.get(pack); @@ -2688,8 +2677,7 @@ public final class SWF implements SWFContainerItem, Timelined { boolean parallel = Configuration.parallelSpeedUp.get(); HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true); pack.toSource(writer, script == null ? null : script.traits.traits, new ConvertData(), ScriptExportMode.AS, parallel); - HighlightedText hilightedCode = new HighlightedText(writer); - CachedDecompilation res = new CachedDecompilation(hilightedCode); + HighlightedText res = new HighlightedText(writer); swf.as3Cache.put(pack, res); return res; @@ -2910,8 +2898,7 @@ public final class SWF implements SWFContainerItem, Timelined { timelined.setModified(true); timelined.resetTimeline(); } else // timeline should be always the swf here - { - if (removeDependencies) { + if (removeDependencies) { removeTagWithDependenciesFromTimeline(tag, timelined.getTimeline()); timelined.setModified(true); } else { @@ -2920,7 +2907,6 @@ public final class SWF implements SWFContainerItem, Timelined { timelined.setModified(true); } } - } } @Override @@ -3333,7 +3319,7 @@ public final class SWF implements SWFContainerItem, Timelined { HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true); try { - asms.get(name).getASMSource(ScriptExportMode.PCODE, writer, asms.get(name).getActions()); + asms.get(name).getASMSource(ScriptExportMode.PCODE, writer, null); } catch (InterruptedException ex) { logger.log(Level.SEVERE, null, ex); } @@ -3399,9 +3385,9 @@ public final class SWF implements SWFContainerItem, Timelined { for (String name : names) { List regitems = new ArrayList<>(); moduleId++; - CachedScript cs; + HighlightedText cs; try { - cs = SWF.getCached(asms.get(name), asms.get(name).getActions()); + cs = SWF.getCached(asms.get(name), null); } catch (InterruptedException ex) { return false; } @@ -3411,7 +3397,7 @@ public final class SWF implements SWFContainerItem, Timelined { Map regNames = new HashMap<>(); for (int pos = 0; pos < txt.length(); pos++) { - Highlighting h = Highlighting.searchPos(cs.hilights, pos); + Highlighting h = Highlighting.searchPos(cs.getInstructionHighlights(), pos); if (h != null) { int firstLineOffset = (int) h.getProperties().firstLineOffset; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/CachedDecompilation.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/CachedDecompilation.java deleted file mode 100644 index 532017905..000000000 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/CachedDecompilation.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2010-2016 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. - */ -package com.jpexs.decompiler.flash.abc; - -import com.jpexs.decompiler.flash.helpers.HighlightedText; -import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; -import java.io.Serializable; -import java.util.List; - -/** - * - * @author JPEXS - */ -public class CachedDecompilation implements Serializable { - - public String text; - - public List traitHilights; - - public List classHilights; - - public List methodHilights; - - public List instructionHilights; - - public List specialHilights; - - public List getInstructionHighlights() { - return instructionHilights; - } - - public List getTraitHighlights() { - return traitHilights; - } - - public List getMethodHighlights() { - return methodHilights; - } - - public List getClassHighlights() { - return classHilights; - } - - public List getSpecialHighligths() { - return specialHilights; - } - - public CachedDecompilation(HighlightedText highlightedText) { - this.text = highlightedText.text; - this.traitHilights = highlightedText.traitHilights; - this.classHilights = highlightedText.classHilights; - this.methodHilights = highlightedText.methodHilights; - this.instructionHilights = highlightedText.instructionHilights; - this.specialHilights = highlightedText.specialHilights; - } -} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java index cb19d825a..3d56fce27 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java @@ -37,6 +37,7 @@ import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; import com.jpexs.decompiler.flash.exporters.settings.ScriptExportSettings; import com.jpexs.decompiler.flash.helpers.FileTextWriter; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; +import com.jpexs.decompiler.flash.helpers.HighlightedText; import com.jpexs.decompiler.flash.helpers.NulWriter; import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; import com.jpexs.decompiler.flash.tags.Tag; @@ -337,7 +338,7 @@ public class ScriptPack extends AS3ClassTreeItem { Set lonelyBody = new HashSet<>(); try { - CachedDecompilation decompiled = SWF.getCached(this); + HighlightedText decompiled = SWF.getCached(this); int line = 1; String txt = decompiled.text; txt = txt.replace("\r", ""); @@ -345,21 +346,21 @@ public class ScriptPack extends AS3ClassTreeItem { for (int i = 0; i < txt.length(); i++) { blk: { - Highlighting sh = Highlighting.searchPos(decompiled.specialHilights, i); + Highlighting sh = Highlighting.searchPos(decompiled.getSpecialHighlights(), i); - Highlighting cls = Highlighting.searchPos(decompiled.classHilights, i); + Highlighting cls = Highlighting.searchPos(decompiled.getClassHighlights(), i); /*if (cls == null) { continue; }*/ - Highlighting trt = Highlighting.searchPos(decompiled.traitHilights, i); + Highlighting trt = Highlighting.searchPos(decompiled.getTraitHighlights(), i); /*if (trt == null) { continue; }*/ - Highlighting method = Highlighting.searchPos(decompiled.methodHilights, i); + Highlighting method = Highlighting.searchPos(decompiled.getMethodHighlights(), i); if (method == null) { break blk; } - Highlighting instr = Highlighting.searchPos(decompiled.instructionHilights, i); //h + Highlighting instr = Highlighting.searchPos(decompiled.getInstructionHighlights(), i); //h /*if (instr == null) { continue; }*/ @@ -531,18 +532,18 @@ public class ScriptPack extends AS3ClassTreeItem { Map bodyToIdentifier = new HashMap<>(); try { - CachedDecompilation decompiled = SWF.getCached(this); + HighlightedText decompiled = SWF.getCached(this); String txt = decompiled.text; txt = txt.replace("\r", ""); for (int i = 0; i < txt.length(); i++) { blk: { - Highlighting sh = Highlighting.searchPos(decompiled.specialHilights, i); + Highlighting sh = Highlighting.searchPos(decompiled.getSpecialHighlights(), i); - Highlighting cls = Highlighting.searchPos(decompiled.classHilights, i); - Highlighting trt = Highlighting.searchPos(decompiled.traitHilights, i); - Highlighting method = Highlighting.searchPos(decompiled.methodHilights, i); + Highlighting cls = Highlighting.searchPos(decompiled.getClassHighlights(), i); + Highlighting trt = Highlighting.searchPos(decompiled.getTraitHighlights(), i); + Highlighting method = Highlighting.searchPos(decompiled.getMethodHighlights(), i); if (method == null) { break blk; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java index 53b0bc1bc..fc67baa8c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java @@ -62,9 +62,7 @@ import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.ecma.Null; import com.jpexs.decompiler.flash.ecma.Undefined; import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; -import com.jpexs.decompiler.flash.helpers.CodeFormatting; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; -import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter; import com.jpexs.decompiler.flash.helpers.NulWriter; import com.jpexs.decompiler.flash.helpers.SWFDecompilerPlugin; import com.jpexs.decompiler.flash.helpers.collections.MyEntry; @@ -475,23 +473,6 @@ public abstract class Action implements GraphSourceItem { } } - /** - * Converts list of actions to ASM source - * - * @param listeners - * @param address - * @param list List of actions - * @param version SWF version - * @param exportMode PCode or hex? - * @return source ASM - * - */ - public static String actionsToString(List listeners, long address, ActionList list, int version, ScriptExportMode exportMode) { - HighlightedTextWriter writer = new HighlightedTextWriter(new CodeFormatting(), false); - actionsToString(listeners, address, list, version, exportMode, writer); - return writer.toString(); - } - private static void informListeners(List listeners, int pos, int count) { if (pos % INFORM_LISTENER_RESOLUTION == 0) { DisassemblyListener[] listenersArray = listeners.toArray(new DisassemblyListener[listeners.size()]); @@ -855,21 +836,6 @@ public abstract class Action implements GraphSourceItem { return actionsToTree(new HashMap<>(), new HashMap<>(), new HashMap<>(), actions, version, staticOperation, path); } - /** - * Converts list of actions to ActionScript source code - * - * @param asm - * @param actions List of actions - * @param path - * @return source - * @throws java.lang.InterruptedException - */ - public static String actionsToSource(final ASMSource asm, final List actions, final String path) throws InterruptedException { - HighlightedTextWriter writer = new HighlightedTextWriter(new CodeFormatting(), false); - actionsToSource(asm, actions, path, writer); - return writer.toString(); - } - /** * Converts list of actions to ActionScript source code * @@ -877,9 +843,10 @@ public abstract class Action implements GraphSourceItem { * @param actions List of actions * @param path * @param writer + * @return * @throws java.lang.InterruptedException */ - public static void actionsToSource(final ASMSource asm, final List actions, final String path, GraphTextWriter writer) throws InterruptedException { + public static GraphTextWriter actionsToSource(final ASMSource asm, final List actions, final String path, GraphTextWriter writer) throws InterruptedException { writer.suspendMeasure(); List tree = null; Throwable convertException = null; @@ -932,6 +899,8 @@ public abstract class Action implements GraphSourceItem { if (asm != null) { asm.getActionSourceSuffix(writer); } + + return writer; } /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionList.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionList.java index 5bb863a3b..be2034c25 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionList.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionList.java @@ -17,6 +17,8 @@ package com.jpexs.decompiler.flash.action; import com.jpexs.decompiler.flash.SWF; +import static com.jpexs.decompiler.flash.action.Action.actionsToSource; +import static com.jpexs.decompiler.flash.action.Action.actionsToString; import com.jpexs.decompiler.flash.action.special.ActionNop; import com.jpexs.decompiler.flash.action.special.ActionStore; import com.jpexs.decompiler.flash.action.swf4.ActionIf; @@ -26,7 +28,9 @@ import com.jpexs.decompiler.flash.action.swf4.ConstantIndex; import com.jpexs.decompiler.flash.action.swf5.ActionConstantPool; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; +import com.jpexs.decompiler.flash.helpers.CodeFormatting; import com.jpexs.decompiler.flash.helpers.FileTextWriter; +import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter; import com.jpexs.decompiler.graph.GraphSourceItemContainer; import java.io.File; import java.io.FileOutputStream; @@ -97,7 +101,6 @@ public class ActionList extends ArrayList { public Iterator getReferencesFor(final Action target) { return new Iterator() { - private final Iterator iterator = ActionList.this.iterator(); private Action action = getNext(); @@ -160,7 +163,6 @@ public class ActionList extends ArrayList { public Iterable getConstantPools() { return () -> new Iterator() { - private final Iterator iterator = ActionList.this.iterator(); private ActionConstantPool action = getNext(); @@ -197,7 +199,6 @@ public class ActionList extends ArrayList { public Iterable getPushes() { return () -> new Iterator() { - private final Iterator iterator = ActionList.this.iterator(); private ActionPush action = getNext(); @@ -547,12 +548,16 @@ public class ActionList extends ArrayList { @Override public String toString() { - return Action.actionsToString(new ArrayList<>(), 0, this, SWF.DEFAULT_VERSION, ScriptExportMode.PCODE); + HighlightedTextWriter writer = new HighlightedTextWriter(new CodeFormatting(), false); + actionsToString(new ArrayList<>(), 0, this, SWF.DEFAULT_VERSION, ScriptExportMode.PCODE, writer); + return writer.toString(); } public String toSource() { try { - return Action.actionsToSource(null, this, ""); + HighlightedTextWriter writer = new HighlightedTextWriter(new CodeFormatting(), false); + actionsToSource(null, this, "", writer); + return writer.toString(); } catch (InterruptedException ex) { Logger.getLogger(ActionList.class.getName()).log(Level.SEVERE, null, ex); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/CachedScript.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/CachedScript.java deleted file mode 100644 index 9655aecf5..000000000 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/CachedScript.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2010-2016 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. - */ -package com.jpexs.decompiler.flash.action; - -import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; -import java.io.Serializable; -import java.util.List; - -/** - * - * @author JPEXS - */ -public class CachedScript implements Serializable { - - public String text; - - public List hilights; - - public List methodHilights; - - public List classHilights; - - public List specialHilights; - - public CachedScript(String text, List hilights, List methodHilights, List classHilights, List specialHilights) { - this.text = text; - this.hilights = hilights; - this.methodHilights = methodHilights; - this.classHilights = classHilights; - this.specialHilights = specialHilights; - } -} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportScriptTask.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportScriptTask.java index 618f1fc84..d1528d56e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportScriptTask.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportScriptTask.java @@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.EventListener; import com.jpexs.decompiler.flash.RetryTask; import com.jpexs.decompiler.flash.RunnableIOExResult; import com.jpexs.decompiler.flash.action.Action; +import com.jpexs.decompiler.flash.action.ActionList; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; import com.jpexs.decompiler.flash.exporters.settings.ScriptExportSettings; @@ -32,7 +33,6 @@ import com.jpexs.helpers.stat.Statistics; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.util.List; import java.util.concurrent.Callable; import java.util.logging.Logger; @@ -104,14 +104,15 @@ public class ExportScriptTask implements Callable { asm.getASMSource(exportMode, writer2, null); asm.getActionSourceSuffix(writer2); } else { - List as; + ActionList as; try (Statistics s = new Statistics("ASMSource.getActions")) { as = asm.getActions(); } + Action.setActionsAddresses(as, 0); try (Statistics s = new Statistics("Action.actionsToSource")) { - Action.actionsToSource(asm, as, asm.toString()/*FIXME?*/, writer2); + asm.getActionScriptSource(writer2, as); } } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/HighlightedText.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/HighlightedText.java index 31413c804..220cabde6 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/HighlightedText.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/HighlightedText.java @@ -30,47 +30,55 @@ public class HighlightedText implements Serializable { public String text; - public List traitHilights; + private final List traitHighlights; - public List classHilights; + private final List classHighlights; - public List methodHilights; + private final List methodHighlights; - public List instructionHilights; + private final List instructionHighlights; - public List specialHilights; + private final List specialHighlights; public List getTraitHighlights() { - return traitHilights; + return traitHighlights; } public List getMethodHighlights() { - return methodHilights; + return methodHighlights; } public List getClassHighlights() { - return classHilights; + return classHighlights; } - public List getSpecialHighligths() { - return specialHilights; + public List getInstructionHighlights() { + return instructionHighlights; + } + + public List getSpecialHighlights() { + return specialHighlights; } public HighlightedText(HighlightedTextWriter writer) { this.text = writer.toString(); - this.traitHilights = writer.traitHilights; - this.classHilights = writer.classHilights; - this.methodHilights = writer.methodHilights; - this.instructionHilights = writer.instructionHilights; - this.specialHilights = writer.specialHilights; + this.traitHighlights = writer.traitHilights; + this.classHighlights = writer.classHilights; + this.methodHighlights = writer.methodHilights; + this.instructionHighlights = writer.instructionHilights; + this.specialHighlights = writer.specialHilights; + } + + public HighlightedText() { + this(""); } public HighlightedText(String text) { this.text = text; - this.traitHilights = new ArrayList<>(); - this.classHilights = new ArrayList<>(); - this.methodHilights = new ArrayList<>(); - this.instructionHilights = new ArrayList<>(); - this.specialHilights = new ArrayList<>(); + this.traitHighlights = new ArrayList<>(); + this.classHighlights = new ArrayList<>(); + this.methodHighlights = new ArrayList<>(); + this.instructionHighlights = new ArrayList<>(); + this.specialHighlights = new ArrayList<>(); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoActionTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoActionTag.java index d1560f1b9..e150b62c0 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoActionTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoActionTag.java @@ -135,6 +135,15 @@ public class DoActionTag extends Tag implements ASMSource { return Action.actionsToString(listeners, 0, actions, swf.version, exportMode, writer); } + @Override + public GraphTextWriter getActionScriptSource(GraphTextWriter writer, ActionList actions) throws InterruptedException { + if (actions == null) { + actions = getActions(); + } + + return Action.actionsToSource(this, actions, toString()/*FIXME?*/, writer); + } + /** * Whether or not this object contains ASM source * diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java index 890b9a70c..af9444e63 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java @@ -143,6 +143,15 @@ public class DoInitActionTag extends Tag implements CharacterIdTag, ASMSource { return Action.actionsToString(listeners, 0, actions, swf.version, exportMode, writer); } + @Override + public GraphTextWriter getActionScriptSource(GraphTextWriter writer, ActionList actions) throws InterruptedException { + if (actions == null) { + actions = getActions(); + } + + return Action.actionsToSource(this, actions, toString()/*FIXME?*/, writer); + } + @Override public ActionList getActions() throws InterruptedException { return SWF.getCachedActionList(this, listeners); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java index 7877a2d48..8e6c8025e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java @@ -44,6 +44,16 @@ public interface ASMSource extends Exportable { */ public GraphTextWriter getASMSource(ScriptExportMode exportMode, GraphTextWriter writer, ActionList actions) throws InterruptedException; + /** + * Converts actions to ActionScript source + * + * @param writer + * @param actions + * @return ASM source + * @throws java.lang.InterruptedException + */ + public GraphTextWriter getActionScriptSource(GraphTextWriter writer, ActionList actions) throws InterruptedException; + /** * Whether or not this object contains ASM source * diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ButtonAction.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ButtonAction.java index 65c4e2f8b..dd5b542fd 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ButtonAction.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ButtonAction.java @@ -65,6 +65,15 @@ public class ButtonAction implements ASMSource { return Action.actionsToString(listeners, 0, actions, getSwf().version, exportMode, writer); } + @Override + public GraphTextWriter getActionScriptSource(GraphTextWriter writer, ActionList actions) throws InterruptedException { + if (actions == null) { + actions = getActions(); + } + + return Action.actionsToSource(this, actions, toString()/*FIXME?*/, writer); + } + /** * Whether or not this object contains ASM source * diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java index 9815b305c..787d1c8ca 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java @@ -190,6 +190,15 @@ public class BUTTONCONDACTION implements ASMSource, Serializable { return Action.actionsToString(listeners, 0, actions, swf.version, exportMode, writer); } + @Override + public GraphTextWriter getActionScriptSource(GraphTextWriter writer, ActionList actions) throws InterruptedException { + if (actions == null) { + actions = getActions(); + } + + return Action.actionsToSource(this, actions, toString()/*FIXME?*/, writer); + } + /** * Whether or not this object contains ASM source * diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java index 2fcfd6740..d8476f2cb 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java @@ -192,6 +192,15 @@ public class CLIPACTIONRECORD implements ASMSource, Serializable { return Action.actionsToString(listeners, 0, actions, swf.version, exportMode, writer); } + @Override + public GraphTextWriter getActionScriptSource(GraphTextWriter writer, ActionList actions) throws InterruptedException { + if (actions == null) { + actions = getActions(); + } + + return Action.actionsToSource(this, actions, toString()/*FIXME?*/, writer); + } + /** * Whether or not this object contains ASM source * diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java index ab2908583..8e130c6b1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java @@ -37,7 +37,6 @@ import com.jpexs.decompiler.flash.abc.types.ScriptInfo; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.abc.types.traits.TraitClass; import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter; -import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.amf.amf3.Amf3Value; import com.jpexs.decompiler.flash.amf.amf3.types.ObjectType; import com.jpexs.decompiler.flash.configuration.Configuration; @@ -1434,7 +1433,7 @@ public class XFLConverter { private static String convertActionScript12(ASMSource as) { HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false); try { - Action.actionsToSource(as, as.getActions(), as.toString()/*FIXME?*/, writer); + as.getActionScriptSource(writer, null); } catch (InterruptedException ex) { logger.log(Level.SEVERE, null, ex); } diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2CompilerTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2CompilerTest.java index b0651009a..c061e1c1b 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2CompilerTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2CompilerTest.java @@ -50,7 +50,7 @@ public class ActionScript2CompilerTest extends ActionScript2TestBase { asm.setActionBytes(Action.actionsToBytes(asm.getActions(), true, swf.version)); HighlightedTextWriter writer = new HighlightedTextWriter(new CodeFormatting(), false); - asm.getASMSource(ScriptExportMode.PCODE, writer, asm.getActions()); + asm.getASMSource(ScriptExportMode.PCODE, writer, null); String actualResult = normalizeLabels(writer.toString()); actualResult = cleanPCode(actualResult); String expectedResult = cleanPCode(expectedPCode); diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2ModificationTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2ModificationTest.java index 0d7c5370c..40efb64bd 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2ModificationTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2ModificationTest.java @@ -79,7 +79,7 @@ public class ActionScript2ModificationTest extends ActionScript2TestBase { DoActionTag doa = getFirstActionTag(); doa.setActionBytes(Action.actionsToBytes(actions, true, swf.version)); HighlightedTextWriter writer = new HighlightedTextWriter(new CodeFormatting(), false); - doa.getASMSource(ScriptExportMode.PCODE, writer, doa.getActions()); + doa.getASMSource(ScriptExportMode.PCODE, writer, null); String actualResult = normalizeLabels(writer.toString()); actualResult = cleanPCode(actualResult); @@ -105,7 +105,7 @@ public class ActionScript2ModificationTest extends ActionScript2TestBase { DoActionTag doa = getFirstActionTag(); doa.setActionBytes(Action.actionsToBytes(actions, true, swf.version)); HighlightedTextWriter writer = new HighlightedTextWriter(new CodeFormatting(), false); - doa.getASMSource(ScriptExportMode.PCODE, writer, doa.getActions()); + doa.getASMSource(ScriptExportMode.PCODE, writer, null); String actualResult = normalizeLabels(writer.toString()); actualResult = cleanPCode(actualResult); @@ -131,7 +131,7 @@ public class ActionScript2ModificationTest extends ActionScript2TestBase { DoActionTag doa = getFirstActionTag(); doa.setActionBytes(Action.actionsToBytes(actions, true, swf.version)); HighlightedTextWriter writer = new HighlightedTextWriter(new CodeFormatting(), false); - doa.getASMSource(ScriptExportMode.PCODE, writer, doa.getActions()); + doa.getASMSource(ScriptExportMode.PCODE, writer, null); String actualResult = normalizeLabels(writer.toString()); actualResult = cleanPCode(actualResult); @@ -154,7 +154,7 @@ public class ActionScript2ModificationTest extends ActionScript2TestBase { DoActionTag doa = getFirstActionTag(); doa.setActionBytes(Action.actionsToBytes(actions, true, swf.version)); HighlightedTextWriter writer = new HighlightedTextWriter(new CodeFormatting(), false); - doa.getASMSource(ScriptExportMode.PCODE, writer, doa.getActions()); + doa.getASMSource(ScriptExportMode.PCODE, writer, null); String actualResult = normalizeLabels(writer.toString()); actualResult = cleanPCode(actualResult); diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/DirectEditingTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/DirectEditingTest.java index 542846084..91aee6049 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/DirectEditingTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/DirectEditingTest.java @@ -20,7 +20,6 @@ import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.abc.avm2.parser.AVM2ParseException; import com.jpexs.decompiler.flash.abc.types.ConvertData; -import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.parser.ActionParseException; import com.jpexs.decompiler.flash.action.parser.script.ActionScript2Parser; import com.jpexs.decompiler.flash.configuration.Configuration; @@ -108,7 +107,7 @@ public class DirectEditingTest extends FileTestBase { for (ASMSource asm : asms.values()) { try { HighlightedTextWriter writer = new HighlightedTextWriter(new CodeFormatting(), false); - Action.actionsToSource(asm, asm.getActions(), asm.toString()/*FIXME?*/, writer); + asm.getActionScriptSource(writer, null); String as = writer.toString(); as = asm.removePrefixAndSuffix(as); ActionScript2Parser par = new ActionScript2Parser(swf.version); @@ -118,7 +117,7 @@ public class DirectEditingTest extends FileTestBase { fail("Unable to parse: " + as + "/" + asm.toString(), ex); } writer = new HighlightedTextWriter(new CodeFormatting(), false); - Action.actionsToSource(asm, asm.getActions(), asm.toString()/*FIXME?*/, writer); + asm.getActionScriptSource(writer, null); String as2 = writer.toString(); as2 = asm.removePrefixAndSuffix(as2); try { @@ -127,7 +126,7 @@ public class DirectEditingTest extends FileTestBase { fail("Unable to parse: " + asm.getSwf().getShortFileName() + "/" + asm.toString(), ex); } writer = new HighlightedTextWriter(new CodeFormatting(), false); - Action.actionsToSource(asm, asm.getActions(), asm.toString()/*FIXME?*/, writer); + asm.getActionScriptSource(writer, null); String as3 = writer.toString(); as3 = asm.removePrefixAndSuffix(as3); if (!as3.equals(as2)) { diff --git a/src/com/jpexs/decompiler/flash/gui/SearchDialog.java b/src/com/jpexs/decompiler/flash/gui/SearchDialog.java index ac054e406..38b9cf04f 100644 --- a/src/com/jpexs/decompiler/flash/gui/SearchDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/SearchDialog.java @@ -109,7 +109,7 @@ public class SearchDialog extends AppDialog { searchInPCodeRadioButton.setSelected(false); searchInTextsRadioButton.setSelected(false); rbPanel.add(searchInASRadioButton); - // todo: honfika rbPanel.add(searchInPCodeRadioButton); + rbPanel.add(searchInPCodeRadioButton); rbPanel.add(searchInTextsRadioButton); cnt.add(rbPanel); } diff --git a/src/com/jpexs/decompiler/flash/gui/SearchResultsDialog.java b/src/com/jpexs/decompiler/flash/gui/SearchResultsDialog.java index 0123ab998..2ccf5b295 100644 --- a/src/com/jpexs/decompiler/flash/gui/SearchResultsDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/SearchResultsDialog.java @@ -66,7 +66,6 @@ public class SearchResultsDialog extends AppDialog { buttonsPanel.add(gotoButton); buttonsPanel.add(closeButton); resultsList.addKeyListener(new KeyAdapter() { - @Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { @@ -76,7 +75,6 @@ public class SearchResultsDialog extends AppDialog { }); resultsList.addMouseListener(new MouseAdapter() { - @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { diff --git a/src/com/jpexs/decompiler/flash/gui/TextPanel.java b/src/com/jpexs/decompiler/flash/gui/TextPanel.java index 7ae120be2..573a3f490 100644 --- a/src/com/jpexs/decompiler/flash/gui/TextPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/TextPanel.java @@ -211,7 +211,7 @@ public class TextPanel extends JPanel implements TagEditorPanel { textValue.requestFocusInWindow(); if (textTag != null && !isModified()) { HighlightedText text = textTag.getFormattedText(false); - for (Highlighting highlight : text.specialHilights) { + for (Highlighting highlight : text.getSpecialHighlights()) { if (highlight.getProperties().subtype == HighlightSpecialType.TEXT) { textValue.select(highlight.startPos, highlight.startPos + highlight.len); break; @@ -229,7 +229,7 @@ public class TextPanel extends JPanel implements TagEditorPanel { HighlightedText text = textTag.getFormattedText(false); boolean allUpper = true; - for (Highlighting highlight : text.specialHilights) { + for (Highlighting highlight : text.getSpecialHighlights()) { if (highlight.getProperties().subtype == HighlightSpecialType.TEXT) { int hStart = highlight.startPos; int hEnd = highlight.startPos + highlight.len; @@ -250,7 +250,7 @@ public class TextPanel extends JPanel implements TagEditorPanel { } } - for (Highlighting highlight : text.specialHilights) { + for (Highlighting highlight : text.getSpecialHighlights()) { if (highlight.getProperties().subtype == HighlightSpecialType.TEXT) { int hStart = highlight.startPos; int hEnd = highlight.startPos + highlight.len; diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java index 115d6fa89..ab4982613 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ASMSourceEditorPane.java @@ -76,9 +76,7 @@ public class ASMSourceEditorPane extends DebuggableEditorPane implements CaretLi return scriptIndex; } - private List disassembledHilights = new ArrayList<>(); - - private List specialHilights = new ArrayList<>(); + private HighlightedText highlightedText = new HighlightedText(); private final List docsListeners = new ArrayList<>(); @@ -176,7 +174,7 @@ public class ASMSourceEditorPane extends DebuggableEditorPane implements CaretLi public void hilighSpecial(HighlightSpecialType type, String specialValue) { Highlighting h2 = null; - for (Highlighting sh : specialHilights) { + for (Highlighting sh : highlightedText.getSpecialHighlights()) { if (type.equals(sh.getProperties().subtype)) { if (sh.getProperties().specialValue.equals(specialValue)) { h2 = sh; @@ -198,7 +196,7 @@ public class ASMSourceEditorPane extends DebuggableEditorPane implements CaretLi if (isEditable()) { return; } - Highlighting h2 = Highlighting.searchOffset(disassembledHilights, offset); + Highlighting h2 = Highlighting.searchOffset(highlightedText.getInstructionHighlights(), offset); if (h2 != null) { ignoreCarret = true; if (h2.startPos <= getDocument().getLength()) { @@ -304,7 +302,6 @@ public class ASMSourceEditorPane extends DebuggableEditorPane implements CaretLi public boolean missingFloat4(Float4 value) { return true; } - }, abc.bodies.get(bodyIndex), abc.method_info.get(abc.bodies.get(bodyIndex).method_info)); //acode.getBytes(abc.bodies.get(bodyIndex).getCodeBytes()); abc.bodies.get(bodyIndex).setCode(acode); @@ -328,16 +325,13 @@ public class ASMSourceEditorPane extends DebuggableEditorPane implements CaretLi @Override public void setText(String t) { - disassembledHilights = new ArrayList<>(); - specialHilights = new ArrayList<>(); - super.setText(t); - setCaretPosition(0); + setText(new HighlightedText(t)); } public void setText(HighlightedText highlightedText) { - disassembledHilights = highlightedText.instructionHilights; - if (!disassembledHilights.isEmpty()) { - int firstPos = disassembledHilights.get(0).startPos; + this.highlightedText = highlightedText; + if (!highlightedText.getInstructionHighlights().isEmpty()) { + int firstPos = highlightedText.getInstructionHighlights().get(0).startPos; String txt = highlightedText.text; txt = txt.replace("\r", ""); int line = 0; @@ -348,7 +342,7 @@ public class ASMSourceEditorPane extends DebuggableEditorPane implements CaretLi } firstInstrLine = line; } - specialHilights = highlightedText.specialHilights; + super.setText(highlightedText.text); setCaretPosition(0); } @@ -401,13 +395,13 @@ public class ASMSourceEditorPane extends DebuggableEditorPane implements CaretLi } public Highlighting getSelectedSpecial() { - return Highlighting.searchPos(specialHilights, getCaretPosition()); + return Highlighting.searchPos(highlightedText.getSpecialHighlights(), getCaretPosition()); } public long getSelectedOffset() { int pos = getCaretPosition(); Highlighting lastH = null; - for (Highlighting h : disassembledHilights) { + for (Highlighting h : highlightedText.getInstructionHighlights()) { if (pos < h.startPos) { break; } diff --git a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java index 9a1ead655..b1a688f75 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java @@ -18,7 +18,6 @@ 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.CachedDecompilation; import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; @@ -38,6 +37,7 @@ import com.jpexs.decompiler.flash.gui.AppStrings; import com.jpexs.decompiler.flash.gui.View; import com.jpexs.decompiler.flash.gui.editor.DebuggableEditorPane; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; +import com.jpexs.decompiler.flash.helpers.HighlightedText; import com.jpexs.decompiler.flash.helpers.hilight.HighlightData; import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType; import com.jpexs.decompiler.flash.helpers.hilight.Highlighting; @@ -60,15 +60,7 @@ import jsyntaxpane.TokenType; */ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretListener { - private List highlights = new ArrayList<>(); - - private List specialHighlights = new ArrayList<>(); - - private List traitHighlights = new ArrayList<>(); - - private List methodHighlights = new ArrayList<>(); - - private List classHighlights = new ArrayList<>(); + private HighlightedText highlightedText = new HighlightedText(); private Highlighting currentMethodHighlight; @@ -140,9 +132,9 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL } List allh = new ArrayList<>(); - for (Highlighting h : traitHighlights) { + for (Highlighting h : highlightedText.getTraitHighlights()) { if (h.getProperties().index == lastTraitIndex) { - for (Highlighting sh : specialHighlights) { + for (Highlighting sh : highlightedText.getSpecialHighlights()) { if (sh.startPos >= h.startPos && (sh.startPos + sh.len < h.startPos + h.len)) { allh.add(sh); } @@ -150,7 +142,7 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL } } if (currentMethodHighlight != null) { - for (Highlighting h : specialHighlights) { + for (Highlighting h : highlightedText.getSpecialHighlights()) { if (h.startPos >= startPos && (h.startPos + h.len < endPos)) { allh.add(h); } @@ -173,9 +165,9 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL if (currentMethodHighlight == null) { return; } - for (Highlighting h : traitHighlights) { + for (Highlighting h : highlightedText.getTraitHighlights()) { if (h.getProperties().index == lastTraitIndex) { - Highlighting h2 = Highlighting.searchOffset(highlights, offset, h.startPos, h.startPos + h.len); + Highlighting h2 = Highlighting.searchOffset(highlightedText.getInstructionHighlights(), offset, h.startPos, h.startPos + h.len); if (h2 != null) { ignoreCarret = true; if (h2.startPos <= getDocument().getLength()) { @@ -224,12 +216,12 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL this.isStatic = isStatic; } boolean success = false; - Highlighting h = Highlighting.searchPos(highlights, pos); + Highlighting h = Highlighting.searchPos(highlightedText.getInstructionHighlights(), pos); if (h != null) { methodCodePanel.hilighOffset(h.getProperties().offset); success = true; } - Highlighting sh = Highlighting.searchPos(specialHighlights, pos); + Highlighting sh = Highlighting.searchPos(highlightedText.getSpecialHighlights(), pos); if (sh != null) { methodCodePanel.hilighSpecial(sh.getProperties().subtype, sh.getProperties().specialValue); success = true; @@ -258,20 +250,20 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL } public int getLocalDeclarationOfPos(int pos, Reference type) { - Highlighting sh = Highlighting.searchPos(specialHighlights, pos); - Highlighting h = Highlighting.searchPos(highlights, pos); + Highlighting sh = Highlighting.searchPos(highlightedText.getSpecialHighlights(), pos); + Highlighting h = Highlighting.searchPos(highlightedText.getInstructionHighlights(), pos); if (h == null) { return -1; } - List tms = Highlighting.searchAllPos(methodHighlights, pos); + List tms = Highlighting.searchAllPos(highlightedText.getMethodHighlights(), pos); if (tms.isEmpty()) { return -1; } for (Highlighting tm : tms) { - List tm_tms = Highlighting.searchAllIndexes(methodHighlights, tm.getProperties().index); + List tm_tms = Highlighting.searchAllIndexes(highlightedText.getMethodHighlights(), tm.getProperties().index); //is it already declaration? if (h.getProperties().declaration || (sh != null && sh.getProperties().declaration)) { return -1; //no jump @@ -279,7 +271,7 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL String lname = h.getProperties().localName; if ("this".equals(lname)) { - Highlighting ch = Highlighting.searchPos(classHighlights, pos); + Highlighting ch = Highlighting.searchPos(highlightedText.getClassHighlights(), pos); int cindex = (int) ch.getProperties().index; ABC abc = getABC(); type.setVal(abc.instance_info.get(cindex).getName(abc.constants).getNameWithNamespace(abc.constants, true)); @@ -298,9 +290,9 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL search.declaration = true; for (Highlighting tm1 : tm_tms) { - Highlighting rh = Highlighting.search(highlights, search, tm1.startPos, tm1.startPos + tm1.len); + Highlighting rh = Highlighting.search(highlightedText.getInstructionHighlights(), search, tm1.startPos, tm1.startPos + tm1.len); if (rh == null) { - rh = Highlighting.search(specialHighlights, search, tm1.startPos, tm1.startPos + tm1.len); + rh = Highlighting.search(highlightedText.getSpecialHighlights(), search, tm1.startPos, tm1.startPos + tm1.len); } if (rh != null) { type.setVal(rh.getProperties().declaredType); @@ -414,7 +406,7 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL } public int _getMultinameAtPos(int pos, boolean codeOnly) { - Highlighting tm = Highlighting.searchPos(methodHighlights, pos); + Highlighting tm = Highlighting.searchPos(highlightedText.getMethodHighlights(), pos); Trait currentTrait = null; int currentMethod = -1; ABC abc = getABC(); @@ -423,7 +415,7 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL int mi = (int) tm.getProperties().index; currentMethod = mi; int bi = abc.findBodyIndex(mi); - Highlighting h = Highlighting.searchPos(highlights, pos); + Highlighting h = Highlighting.searchPos(highlightedText.getInstructionHighlights(), pos); if (h != null) { long highlightOffset = h.getProperties().offset; List list = abc.bodies.get(bi).getCode().code; @@ -443,7 +435,7 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL if (selIns != null) { //long inspos = highlightOffset - selIns.offset; if (!codeOnly && ((selIns.definition instanceof ConstructSuperIns) || (selIns.definition instanceof CallSuperIns) || (selIns.definition instanceof CallSuperVoidIns))) { - Highlighting tc = Highlighting.searchPos(classHighlights, pos); + Highlighting tc = Highlighting.searchPos(highlightedText.getClassHighlights(), pos); if (tc != null) { int cindex = (int) tc.getProperties().index; if (cindex > -1) { @@ -465,9 +457,9 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL return -1; } - Highlighting ch = Highlighting.searchPos(classHighlights, pos); + Highlighting ch = Highlighting.searchPos(highlightedText.getClassHighlights(), pos); if (ch != null) { - Highlighting th = Highlighting.searchPos(traitHighlights, pos); + Highlighting th = Highlighting.searchPos(highlightedText.getTraitHighlights(), pos); if (th != null) { currentTrait = abc.findTraitByTraitId((int) ch.getProperties().index, (int) th.getProperties().index); } @@ -476,7 +468,7 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL if (currentTrait instanceof TraitMethodGetterSetter) { currentMethod = ((TraitMethodGetterSetter) currentTrait).method_info; } - Highlighting sh = Highlighting.searchPos(specialHighlights, pos); + Highlighting sh = Highlighting.searchPos(highlightedText.getSpecialHighlights(), pos); if (sh != null) { switch (sh.getProperties().subtype) { case TYPE_NAME: @@ -530,12 +522,12 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL abcPanel.detailPanel.methodTraitPanel.methodCodePanel.setIgnoreCarret(true); try { classIndex = -1; - Highlighting cm = Highlighting.searchPos(classHighlights, pos); + Highlighting cm = Highlighting.searchPos(highlightedText.getClassHighlights(), pos); if (cm != null) { classIndex = (int) cm.getProperties().index; } displayClass(classIndex, script.scriptIndex); - Highlighting tm = Highlighting.searchPos(methodHighlights, pos); + Highlighting tm = Highlighting.searchPos(highlightedText.getMethodHighlights(), pos); if (tm != null) { String name = ""; if (classIndex > -1) { @@ -543,7 +535,7 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL } Trait currentTrait = null; - currentTraitHighlight = Highlighting.searchPos(traitHighlights, pos); + currentTraitHighlight = Highlighting.searchPos(highlightedText.getTraitHighlights(), pos); if (currentTraitHighlight != null) { lastTraitIndex = (int) currentTraitHighlight.getProperties().index; if (classIndex != -1) { @@ -566,7 +558,7 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL return; } Trait currentTrait; - currentTraitHighlight = Highlighting.searchPos(traitHighlights, pos); + currentTraitHighlight = Highlighting.searchPos(highlightedText.getTraitHighlights(), pos); if (currentTraitHighlight != null) { lastTraitIndex = (int) currentTraitHighlight.getProperties().index; currentTrait = getCurrentTrait(); @@ -581,7 +573,7 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL }); abcPanel.detailPanel.setEditMode(false); currentMethodHighlight = null; - Highlighting spec = Highlighting.searchPos(specialHighlights, pos, currentTraitHighlight.startPos, currentTraitHighlight.startPos + currentTraitHighlight.len); + Highlighting spec = Highlighting.searchPos(highlightedText.getSpecialHighlights(), pos, currentTraitHighlight.startPos, currentTraitHighlight.startPos + currentTraitHighlight.len); if (spec != null) { abcPanel.detailPanel.slotConstTraitPanel.hilightSpecial(spec); } @@ -614,9 +606,9 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL public void gotoTrait(int traitId) { boolean isScriptInit = traitId == GraphTextWriter.TRAIT_SCRIPT_INITIALIZER; - Highlighting tc = Highlighting.searchIndex(classHighlights, classIndex); + Highlighting tc = Highlighting.searchIndex(highlightedText.getClassHighlights(), classIndex); if (tc != null || isScriptInit) { - Highlighting th = Highlighting.searchIndex(traitHighlights, traitId, isScriptInit || tc == null ? 0 : tc.startPos, isScriptInit || tc == null ? -1 : tc.startPos + tc.len); + Highlighting th = Highlighting.searchIndex(highlightedText.getTraitHighlights(), traitId, isScriptInit || tc == null ? 0 : tc.startPos, isScriptInit || tc == null ? -1 : tc.startPos + tc.len); int pos = 0; if (th != null) { if (th.len > 1) { @@ -670,17 +662,14 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL nscript = abc.script_info.get(scriptIndex); } if (nscript == null) { - highlights = new ArrayList<>(); - specialHighlights = new ArrayList<>(); - traitHighlights = new ArrayList<>(); - methodHighlights = new ArrayList<>(); + highlightedText = new HighlightedText(); this.script = scriptLeaf; return; } setText("// " + AppStrings.translate("pleasewait") + "..."); this.script = scriptLeaf; - CachedDecompilation cd = null; + HighlightedText cd = null; try { cd = SWF.getCached(scriptLeaf); } catch (InterruptedException ex) { @@ -688,16 +677,12 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL if (cd != null) { String hilightedCode = cd.text; - highlights = cd.getInstructionHighlights(); - specialHighlights = cd.getSpecialHighligths(); - traitHighlights = cd.getTraitHighlights(); - methodHighlights = cd.getMethodHighlights(); - classHighlights = cd.getClassHighlights(); + highlightedText = cd; setText(hilightedCode); - if (classHighlights.size() > 0) { + if (highlightedText.getClassHighlights().size() > 0) { try { - setCaretPosition(classHighlights.get(0).startPos); + setCaretPosition(highlightedText.getClassHighlights().get(0).startPos); } catch (Exception ex) { //sometimes happens //ignore } diff --git a/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java b/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java index 56ddc7c5d..ed1be7ae2 100644 --- a/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java @@ -21,7 +21,6 @@ import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.ActionGraph; import com.jpexs.decompiler.flash.action.ActionList; -import com.jpexs.decompiler.flash.action.CachedScript; import com.jpexs.decompiler.flash.action.ConstantPoolTooBigException; import com.jpexs.decompiler.flash.action.parser.ActionParseException; import com.jpexs.decompiler.flash.action.parser.pcode.ASMParser; @@ -138,16 +137,6 @@ public class ActionPanel extends JPanel implements SearchListener decompiledHilights = new ArrayList<>(); - - public List specialHighlights = new ArrayList<>(); - - public List classHighlights = new ArrayList<>(); - - public List methodHighlights = new ArrayList<>(); - - public List disassembledHilights = new ArrayList<>(); - private boolean ignoreCarret = false; private boolean editMode = false; @@ -168,7 +157,9 @@ public class ActionPanel extends JPanel implements SearchListener list = lastCode; Action lastIns = null; @@ -271,14 +262,21 @@ public class ActionPanel extends JPanel implements SearchListener { int pos = editor.getCaretPosition(); Highlighting lastH = null; - for (Highlighting h : disassembledHilights) { + for (Highlighting h : disassembledText.getInstructionHighlights()) { if (pos < h.startPos) { break; } lastH = h; } Long offset = lastH == null ? 0 : lastH.getProperties().offset; - disassembledHilights = text.instructionHilights; - String stripped = text.text; - setEditorText(scriptName, stripped, contentType); - Highlighting h = Highlighting.searchOffset(disassembledHilights, offset); + disassembledText = text; + setEditorText(scriptName, text.text, contentType); + Highlighting h = Highlighting.searchOffset(disassembledText.getInstructionHighlights(), offset); if (h != null) { if (h.startPos <= editor.getDocument().getLength()) { editor.setCaretPosition(h.startPos); @@ -445,19 +442,15 @@ public class ActionPanel extends JPanel implements SearchListener tms = Highlighting.searchAllPos(methodHighlights, pos); + List tms = Highlighting.searchAllPos(lastDecompiled.getMethodHighlights(), pos); if (tms.isEmpty()) { return -1; } for (Highlighting tm : tms) { - List tm_tms = Highlighting.searchAllLocalNames(methodHighlights, tm.getProperties().localName); + List tm_tms = Highlighting.searchAllLocalNames(lastDecompiled.getMethodHighlights(), tm.getProperties().localName); //is it already declaration? if (h.getProperties().declaration || (sh != null && sh.getProperties().declaration)) { return -1; //no jump @@ -549,7 +538,7 @@ public class ActionPanel extends JPanel implements SearchListener 0 && h2.startPos < editor.getText().length()) { @@ -888,7 +877,7 @@ public class ActionPanel extends JPanel implements SearchListener -1) { if (lastLine - prefLines >= 0) { @@ -896,8 +885,7 @@ public class ActionPanel extends JPanel implements SearchListener -1) { decompiledEditor.gotoLine(lastLine + prefLines + 1); } @@ -1060,7 +1048,11 @@ public class ActionPanel extends JPanel implements SearchListener { - searchPanel.showQuickFindDialog(decompiledEditor); + if (item.isPcode()) { + searchPanel.showQuickFindDialog(editor); + } else { + searchPanel.showQuickFindDialog(decompiledEditor); + } }); } diff --git a/src/com/jpexs/decompiler/flash/gui/action/ActionSearchResult.java b/src/com/jpexs/decompiler/flash/gui/action/ActionSearchResult.java index bdf71f7cb..92726b12b 100644 --- a/src/com/jpexs/decompiler/flash/gui/action/ActionSearchResult.java +++ b/src/com/jpexs/decompiler/flash/gui/action/ActionSearchResult.java @@ -26,10 +26,13 @@ public class ActionSearchResult { private final ASMSource src; + private final boolean pcode; + private final String path; - public ActionSearchResult(ASMSource src, String path) { + public ActionSearchResult(ASMSource src, boolean pcode, String path) { this.src = src; + this.pcode = pcode; this.path = path; } @@ -37,6 +40,10 @@ public class ActionSearchResult { return src; } + public boolean isPcode() { + return pcode; + } + @Override public String toString() { return path; diff --git a/src/com/jpexs/decompiler/flash/gui/generictageditors/EnumEditor.java b/src/com/jpexs/decompiler/flash/gui/generictageditors/EnumEditor.java index 77d606399..3956e16a0 100644 --- a/src/com/jpexs/decompiler/flash/gui/generictageditors/EnumEditor.java +++ b/src/com/jpexs/decompiler/flash/gui/generictageditors/EnumEditor.java @@ -213,6 +213,7 @@ public class EnumEditor extends JComboBox> implements Gene @Override public Object getChangedValue() { + @SuppressWarnings("unchecked") ComboBoxItem item = (ComboBoxItem) getSelectedItem(); int value = item.getValue(); return value;