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 2cc43840d..700085ec8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -2609,6 +2609,17 @@ public final class SWF implements SWFContainerItem, Timelined { return false; } + public static boolean isActionListCached(ASMSource src) { + if (src != null) { + SWF swf = src.getSwf(); + if (swf != null) { + return swf.as2Cache.isPCodeCached(src); + } + } + + return false; + } + public static boolean isCached(ScriptPack pack) { if (pack != null) { SWF swf = pack.getSwf(); @@ -2631,6 +2642,17 @@ public final class SWF implements SWFContainerItem, Timelined { return null; } + public static ActionList getActionListFromCache(ASMSource src) { + if (src != null) { + SWF swf = src.getSwf(); + if (swf != null) { + return swf.as2Cache.getPCode(src); + } + } + + return null; + } + public static HighlightedText getFromCache(ScriptPack pack) { if (pack != null) { SWF swf = pack.getSwf(); @@ -2646,8 +2668,8 @@ public final class SWF implements SWFContainerItem, Timelined { synchronized (src) { SWF swf = src.getSwf(); int deobfuscationMode = Configuration.autoDeobfuscate.get() ? 1 : 0; - if (swf != null && swf.as2Cache.isPcodeCached(src)) { - ActionList result = swf.as2Cache.getPcode(src); + if (swf != null && swf.as2Cache.isPCodeCached(src)) { + ActionList result = swf.as2Cache.getPCode(src); if (result.deobfuscationMode == deobfuscationMode) { return result; } @@ -2958,7 +2980,8 @@ 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 { @@ -2967,6 +2990,7 @@ public final class SWF implements SWFContainerItem, Timelined { timelined.setModified(true); } } + } } @Override 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 fc67baa8c..ec199ccd3 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 @@ -106,7 +106,7 @@ import java.util.logging.Logger; */ public abstract class Action implements GraphSourceItem { - private static final int INFORM_LISTENER_RESOLUTION = 100; + private static final int INFORM_LISTENER_RESOLUTION = 1000; private boolean ignored = false; @@ -474,11 +474,9 @@ public abstract class Action implements GraphSourceItem { } private static void informListeners(List listeners, int pos, int count) { - if (pos % INFORM_LISTENER_RESOLUTION == 0) { - DisassemblyListener[] listenersArray = listeners.toArray(new DisassemblyListener[listeners.size()]); - for (DisassemblyListener listener : listenersArray) { - listener.progressToString(pos + 1, count); - } + DisassemblyListener[] listenersArray = listeners.toArray(new DisassemblyListener[listeners.size()]); + for (DisassemblyListener listener : listenersArray) { + listener.progressToString(pos + 1, count); } } @@ -507,11 +505,14 @@ public abstract class Action implements GraphSourceItem { HashMap> containers = new HashMap<>(); HashMap containersPos = new HashMap<>(); offset = address; - int pos = 0; boolean lastPush = false; byte[] fileData = list.fileData; - for (Action a : list) { - informListeners(listeners, pos, list.size()); + for (int pos = 0; pos < list.size(); pos++) { + Action a = list.get(pos); + + if ((pos + 1) % INFORM_LISTENER_RESOLUTION == 0) { + informListeners(listeners, pos, list.size()); + } if (exportMode == ScriptExportMode.PCODE_HEX) { if (lastPush) { @@ -671,8 +672,8 @@ public abstract class Action implements GraphSourceItem { } offset += a.getTotalActionLength(); - pos++; } + if (lastPush) { writer.newLine(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/cache/AS2Cache.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/cache/AS2Cache.java index a5f90b90d..afce8801c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/cache/AS2Cache.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/cache/AS2Cache.java @@ -40,7 +40,7 @@ public class AS2Cache { return cache.contains(src); } - public boolean isPcodeCached(ASMSource src) { + public boolean isPCodeCached(ASMSource src) { return pcodeCache.contains(src); } @@ -48,7 +48,7 @@ public class AS2Cache { return cache.get(src); } - public ActionList getPcode(ASMSource src) { + public ActionList getPCode(ASMSource src) { return pcodeCache.get(src); } diff --git a/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java b/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java index ad4807df2..042b2badf 100644 --- a/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java @@ -169,7 +169,7 @@ public class ActionPanel extends JPanel implements SearchListener { - ignoreCarret = true; - decompiledEditor.setScriptName(scriptName); - decompiledEditor.setText(text); - ignoreCarret = false; - }); + ignoreCarret = true; + decompiledEditor.setScriptName(scriptName); + decompiledEditor.setText(text); + ignoreCarret = false; } private void setEditorText(final String scriptName, final String text, final String contentType) { - View.execInEventDispatch(() -> { - ignoreCarret = true; - editor.setScriptName("#PCODE " + scriptName); - editor.changeContentType(contentType); - editor.setText(text); - ignoreCarret = false; - }); + ignoreCarret = true; + editor.setScriptName("#PCODE " + scriptName); + editor.changeContentType(contentType); + editor.setText(text); + ignoreCarret = false; } private void setText(final HighlightedText text, final String contentType, final String scriptName) { - View.execInEventDispatch(() -> { - int pos = editor.getCaretPosition(); - Highlighting lastH = null; - for (Highlighting h : disassembledText.getInstructionHighlights()) { - if (pos < h.startPos) { - break; - } - lastH = h; + int pos = editor.getCaretPosition(); + Highlighting lastH = null; + for (Highlighting h : disassembledText.getInstructionHighlights()) { + if (pos < h.startPos) { + break; } - Long offset = lastH == null ? 0 : lastH.getProperties().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); - } + lastH = h; + } + Long offset = lastH == null ? 0 : lastH.getProperties().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); } - }); + } } - private HighlightedText getHighlightedText(ScriptExportMode exportMode) { + private HighlightedText getHighlightedText(ScriptExportMode exportMode, ActionList actions) { + if (actions == null) { + logger.log(Level.WARNING, "Action list is null"); + return new HighlightedText(); + } + ASMSource asm = (ASMSource) src; DisassemblyListener listener = getDisassemblyListener(); asm.addDisassemblyListener(listener); HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true); try { - asm.getASMSource(exportMode, writer, lastCode); + asm.getASMSource(exportMode, writer, actions); } catch (InterruptedException ex) { logger.log(Level.SEVERE, null, ex); } + asm.removeDisassemblyListener(listener); return new HighlightedText(writer); } @@ -327,20 +327,20 @@ public class ActionPanel extends JPanel implements SearchListener percent) || (!this.phase.equals(phase))) && newpercent <= 100) { percent = newpercent; this.phase = phase; + // todo: honfika: it is very slow to show every percent - setEditorText("-", "; " + AppStrings.translate("work.disassembling") + " - " + phase + " " + percent + "%...", "text/flasm"); + View.execInEventDispatch(() -> { + setEditorText("-", "; " + AppStrings.translate("work.disassembling") + " - " + phase + " " + percent + "%...", "text/flasm"); + }); } } @@ -418,49 +421,72 @@ public class ActionPanel extends JPanel implements SearchListener { + setEditorText(asm.getScriptName(), "; " + AppStrings.translate("work.disassembling") + "...", "text/flasm"); + if (decompileNeeded) { + setDecompiledText("-", "// " + AppStrings.translate("work.waitingfordissasembly") + "..."); + } + }); - HighlightedText sc = SWF.getCached(asm, actions); - lastDecompiled = sc; - lastASM = asm; - setDecompiledText(lastASM.getScriptName(), lastDecompiled.text); - setDecompiledEditMode(false); + DisassemblyListener listener = getDisassemblyListener(); + asm.addDisassemblyListener(listener); + innerActions = asm.getActions(); + asm.removeDisassemblyListener(listener); + + lastCode = innerActions; + ActionList finalActions = innerActions; + View.execInEventDispatch(() -> { + setHex(getExportMode(), asm.getScriptName(), finalActions); + }); + } + + if (decompileNeeded) { + View.execInEventDispatch(() -> { + setDecompiledText("-", "// " + AppStrings.translate("work.decompiling") + "..."); + }); + + HighlightedText htext = SWF.getCached(asm, innerActions); + lastDecompiled = htext; + lastASM = asm; + + View.execInEventDispatch(() -> { + setDecompiledText(lastASM.getScriptName(), htext.text); + }); } - setEditMode(false); return null; } @@ -480,6 +506,14 @@ public class ActionPanel extends JPanel implements SearchListener { - if (val) { - if (hexOnlyButton.isSelected()) { - setHex(ScriptExportMode.HEX, src.getScriptName()); - } else if (constantsViewButton.isSelected()) { - setHex(ScriptExportMode.CONSTANTS, src.getScriptName()); - } else { - setHex(ScriptExportMode.PCODE, src.getScriptName()); - } + if (val) { + if (hexOnlyButton.isSelected()) { + setHex(ScriptExportMode.HEX, src.getScriptName(), lastCode); + } else if (constantsViewButton.isSelected()) { + setHex(ScriptExportMode.CONSTANTS, src.getScriptName(), lastCode); + } else { + setHex(ScriptExportMode.PCODE, src.getScriptName(), lastCode); } + } - editor.setEditable(val); - saveButton.setVisible(val); - saveButton.setEnabled(false); - editButton.setVisible(!val); - cancelButton.setVisible(val); + editor.setEditable(val); + saveButton.setVisible(val); + saveButton.setEnabled(false); + editButton.setVisible(!val); + cancelButton.setVisible(val); - editor.getCaret().setVisible(true); - asmLabel.setIcon(val ? View.getIcon("editing16") : null); // this line is not working - topButtonsPan.setVisible(!val); - editMode = val; - editor.requestFocusInWindow(); - }); + editor.getCaret().setVisible(true); + asmLabel.setIcon(val ? View.getIcon("editing16") : null); // this line is not working + topButtonsPan.setVisible(!val); + editMode = val; + editor.requestFocusInWindow(); } public void setDecompiledEditMode(boolean val) { if (lastASM == null) { return; } - View.execInEventDispatch(() -> { - int lastLine = decompiledEditor.getLine(); - int prefLines = lastASM.getPrefixLineCount(); - if (val) { - String newText = lastASM.removePrefixAndSuffix(lastDecompiled.text); - setDecompiledText(lastASM.getScriptName(), newText); - if (lastLine > -1) { - if (lastLine - prefLines >= 0) { - decompiledEditor.gotoLine(lastLine - prefLines + 1); - } - } - } else { - setDecompiledText(lastASM.getScriptName(), lastDecompiled.text); - if (lastLine > -1) { - decompiledEditor.gotoLine(lastLine + prefLines + 1); + + int lastLine = decompiledEditor.getLine(); + int prefLines = lastASM.getPrefixLineCount(); + if (val) { + String newText = lastASM.removePrefixAndSuffix(lastDecompiled.text); + setDecompiledText(lastASM.getScriptName(), newText); + if (lastLine > -1) { + if (lastLine - prefLines >= 0) { + decompiledEditor.gotoLine(lastLine - prefLines + 1); } } + } else { + setDecompiledText(lastASM.getScriptName(), lastDecompiled.text); + if (lastLine > -1) { + decompiledEditor.gotoLine(lastLine + prefLines + 1); + } + } - decompiledEditor.setEditable(val); - saveDecompiledButton.setVisible(val); - saveDecompiledButton.setEnabled(false); - editDecompiledButton.setVisible(!val); - experimentalLabel.setVisible(!val); - cancelDecompiledButton.setVisible(val); + decompiledEditor.setEditable(val); + saveDecompiledButton.setVisible(val); + saveDecompiledButton.setEnabled(false); + editDecompiledButton.setVisible(!val); + experimentalLabel.setVisible(!val); + cancelDecompiledButton.setVisible(val); - decompiledEditor.getCaret().setVisible(true); - decLabel.setIcon(val ? View.getIcon("editing16") : null); - editDecompiledMode = val; - decompiledEditor.requestFocusInWindow(); - }); + decompiledEditor.getCaret().setVisible(true); + decLabel.setIcon(val ? View.getIcon("editing16") : null); + editDecompiledMode = val; + decompiledEditor.requestFocusInWindow(); } private void graphButtonActionPerformed(ActionEvent evt) { @@ -898,15 +929,15 @@ public class ActionPanel extends JPanel implements SearchListener truncateLimit) { t = t.substring(0, truncateLimit) + "\r\n" + AppStrings.translate("editorTruncateWarning").replace("%chars%", Integer.toString(truncateLimit)); } + super.setText(t); setCaretPosition(0); //scroll to top }