From 0f835dd0f58ea1d308d90666b88ceda990d04bd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Mon, 4 Jan 2016 21:59:55 +0100 Subject: [PATCH] Issue #1118 running file with importassets Correct checking the autloLoadSwfs checkbox in settings --- .../src/com/jpexs/decompiler/flash/SWF.java | 4 + .../flash/tags/ImportAssets2Tag.java | 6 ++ .../flash/tags/ImportAssetsTag.java | 6 ++ .../decompiler/flash/tags/base/ImportTag.java | 2 + src/com/jpexs/decompiler/flash/gui/Main.java | 85 ++++++++++++------- .../decompiler/flash/gui/MainFrameMenu.java | 20 +++-- 6 files changed, 87 insertions(+), 36 deletions(-) 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 73ba8bb9a..8fac1d6a2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -3228,6 +3228,8 @@ public final class SWF implements SWFContainerItem, Timelined { public void addTag(Tag tag) { setModified(true); tags.add(tag); + readOnlyTags = null; + readOnlyLocalTags = null; } /** @@ -3240,6 +3242,8 @@ public final class SWF implements SWFContainerItem, Timelined { public void addTag(int index, Tag tag) { setModified(true); tags.add(index, tag); + readOnlyTags = null; + readOnlyLocalTags = null; } /** diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ImportAssets2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ImportAssets2Tag.java index 8dc6b51c7..012bf1282 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ImportAssets2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ImportAssets2Tag.java @@ -57,6 +57,12 @@ public class ImportAssets2Tag extends Tag implements ImportTag { @Conditional(value = "hasDigest", options = {1}) String sha1 = ""; + @Override + public void setUrl(String url) { + this.url = url; + setModified(true); + } + /** * HashMap with assets */ diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ImportAssetsTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ImportAssetsTag.java index dbd21ac20..2622194f7 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ImportAssetsTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/ImportAssetsTag.java @@ -69,6 +69,12 @@ public class ImportAssetsTag extends Tag implements ImportTag { tags = new ArrayList<>(); } + @Override + public void setUrl(String url) { + this.url = url; + setModified(true); + } + /** * Constructor * diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ImportTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ImportTag.java index 2255ed3e3..aedd90256 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ImportTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ImportTag.java @@ -26,5 +26,7 @@ public interface ImportTag { public String getUrl(); + public void setUrl(String url); + public Map getAssets(); } diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index a0086f15d..97abf8143 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -40,7 +40,9 @@ import com.jpexs.decompiler.flash.gui.debugger.DebuggerTools; import com.jpexs.decompiler.flash.gui.pipes.FirstInstance; import com.jpexs.decompiler.flash.gui.proxy.ProxyFrame; import com.jpexs.decompiler.flash.helpers.SWFDecompilerPlugin; +import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.FontTag; +import com.jpexs.decompiler.flash.tags.base.ImportTag; import com.jpexs.decompiler.flash.treeitems.SWFList; import com.jpexs.helpers.Cache; import com.jpexs.helpers.CancellableWorker; @@ -80,6 +82,8 @@ import java.net.InetSocketAddress; import java.net.Proxy; import java.net.URL; import java.net.URLConnection; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; @@ -160,6 +164,7 @@ public class Main { private static boolean inited = false; private static File runTempFile; + private static List runTempFiles = new ArrayList<>(); public static void freeRun() { synchronized (Main.class) { @@ -167,6 +172,10 @@ public class Main { runTempFile.delete(); runTempFile = null; } + for (File f : runTempFiles) { + f.delete(); + } + runTempFiles.clear(); runProcess = null; } @@ -204,13 +213,12 @@ public class Main { } public static void runPlayer(String title, final String exePath, String file, String flashVars) { - if (flashVars != null && !flashVars.isEmpty()) { - file += "?" + flashVars; - } if (!new File(file).exists()) { return; } - + if (flashVars != null && !flashVars.isEmpty()) { + file += "?" + flashVars; + } final String ffile = file; CancellableWorker runWorker = new CancellableWorker() { @@ -218,8 +226,9 @@ public class Main { @Override protected Object doInBackground() throws Exception { Process proc; + String runStr = "\"" + exePath + "\" \"" + ffile + "\""; try { - proc = Runtime.getRuntime().exec("\"" + exePath + "\" \"file://" + ffile + "\""); + proc = Runtime.getRuntime().exec(runStr); } catch (IOException ex) { Logger.getLogger(MainFrameMenu.class.getName()).log(Level.SEVERE, null, ex); @@ -294,6 +303,40 @@ public class Main { mainFrame.getMenu().updateComponents(); } + private static void prepareFile(File toPrepareFile, File origFile, List tempFiles) throws IOException { + SWF instrSWF = null; + try (FileInputStream fis = new FileInputStream(toPrepareFile)) { + instrSWF = new SWF(fis, false, false); + } catch (InterruptedException ex) { + Logger.getLogger(MainFrameMenu.class.getName()).log(Level.SEVERE, null, ex); + } + if (instrSWF != null) { + for (Tag t : instrSWF.getLocalTags()) { + if (t instanceof ImportTag) { + ImportTag it = (ImportTag) t; + String url = it.getUrl(); + File importedFile = new File(origFile.getParentFile(), url); + if (importedFile.exists()) { + File newTempFile = File.createTempFile("ffdec_run_import_", ".swf"); + it.setUrl("./" + newTempFile.getName()); + byte[] impData = Helper.readFile(importedFile.getAbsolutePath()); + Helper.writeFile(newTempFile.getAbsolutePath(), impData); + tempFiles.add(newTempFile); + } + } + } + if (Configuration.autoOpenLoadedSWFs.get()) { + if (!DebuggerTools.hasDebugger(instrSWF)) { + DebuggerTools.switchDebugger(instrSWF); + } + DebuggerTools.injectDebugLoader(instrSWF); + } + try (FileOutputStream fos = new FileOutputStream(toPrepareFile)) { + instrSWF.saveTo(fos); + } + } + } + public static void run(SWF swf) { String flashVars = "";//key=val&key2=val2 String playerLocation = Configuration.playerLocation.get(); @@ -306,30 +349,16 @@ public class Main { return; } File tempFile; + List tempFiles = new ArrayList<>(); try { tempFile = File.createTempFile("ffdec_run_", ".swf"); - try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(tempFile))) { + try (FileOutputStream fos = new FileOutputStream(tempFile)) { swf.saveTo(fos); } - if (swf.isAS3() && Configuration.autoOpenLoadedSWFs.get()) { - SWF instrSWF = null; - try (FileInputStream fis = new FileInputStream(tempFile)) { - instrSWF = new SWF(fis, false, false); - } catch (InterruptedException ex) { - Logger.getLogger(MainFrameMenu.class.getName()).log(Level.SEVERE, null, ex); - } - if (instrSWF != null) { - if (!DebuggerTools.hasDebugger(instrSWF)) { - DebuggerTools.switchDebugger(instrSWF); - } - DebuggerTools.injectDebugLoader(instrSWF); - try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(tempFile))) { - instrSWF.saveTo(fos); - } - } - } + prepareFile(tempFile, new File(swf.getFile()), tempFiles); + } catch (IOException ex) { return; @@ -337,6 +366,7 @@ public class Main { if (tempFile != null) { synchronized (Main.class) { runTempFile = tempFile; + runTempFiles = tempFiles; runProcessDebug = false; } runPlayer(AppStrings.translate("work.running"), playerLocation, tempFile.getAbsolutePath(), flashVars); @@ -364,6 +394,7 @@ public class Main { if (tempFile != null) { final File fTempFile = tempFile; + final List tempFiles = new ArrayList<>(); CancellableWorker instrumentWorker = new CancellableWorker() { @Override @@ -372,6 +403,7 @@ public class Main { try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(fTempFile))) { swf.saveTo(fos); } + prepareFile(fTempFile, new File(swf.getFile()), tempFiles); SWF instrSWF = null; try (FileInputStream fis = new FileInputStream(fTempFile)) { instrSWF = new SWF(fis, false, false); @@ -379,12 +411,6 @@ public class Main { Logger.getLogger(MainFrameMenu.class.getName()).log(Level.SEVERE, null, ex); } if (instrSWF != null) { - if (instrSWF.isAS3() && Configuration.autoOpenLoadedSWFs.get()) { - if (!DebuggerTools.hasDebugger(instrSWF)) { - DebuggerTools.switchDebugger(instrSWF); - } - DebuggerTools.injectDebugLoader(instrSWF); - } instrSWF.enableDebugging(true, new File("."), true, doPCode); try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(fTempFile))) { instrSWF.saveTo(fos); @@ -428,6 +454,7 @@ public class Main { runTempFile = fTempFile; runProcessDebug = true; runProcessDebugPCode = doPCode; + runTempFiles = tempFiles; } Main.stopWork(); Main.startDebugger(); diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java index 8ebb55c5f..ddfdf00ab 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java @@ -87,6 +87,8 @@ public abstract class MainFrameMenu implements MenuBuilder { private ConfigurationItemChangeListener configListenerAutoRenameIdentifiers; + private ConfigurationItemChangeListener configListenerAutoOpenLoadedSWFs; + protected final Map menuHotkeys = new HashMap<>(); @Override @@ -944,6 +946,11 @@ public abstract class MainFrameMenu implements MenuBuilder { setMenuChecked("/settings/autoRenameIdentifiers", newValue); }); + setMenuChecked("/settings/autoOpenLoadedSWFs", Configuration.autoOpenLoadedSWFs.get()); + Configuration.autoOpenLoadedSWFs.addListener(configListenerAutoOpenLoadedSWFs = (Boolean newValue) -> { + setMenuChecked("/settings/autoOpenLoadedSWFs", newValue); + }); + if (externalFlashPlayerUnavailable) { setMenuEnabled("/settings/internalViewer", false); setMenuEnabled("/settings/autoOpenLoadedSWFs", false); @@ -1064,14 +1071,12 @@ public abstract class MainFrameMenu implements MenuBuilder { } else { setGroupSelection("view", null); } + } else if (Configuration.dumpView.get()) { + setGroupSelection("view", "/file/view/viewHex"); + mainFrame.getPanel().showView(MainPanel.VIEW_DUMP); } else { - if (Configuration.dumpView.get()) { - setGroupSelection("view", "/file/view/viewHex"); - mainFrame.getPanel().showView(MainPanel.VIEW_DUMP); - } else { - setGroupSelection("view", "/file/view/viewResources"); - mainFrame.getPanel().showView(MainPanel.VIEW_RESOURCES); - } + setGroupSelection("view", "/file/view/viewResources"); + mainFrame.getPanel().showView(MainPanel.VIEW_RESOURCES); } } @@ -1108,6 +1113,7 @@ public abstract class MainFrameMenu implements MenuBuilder { Configuration.cacheOnDisk.removeListener(configListenerCacheOnDisk); Configuration.gotoMainClassOnStartup.removeListener(configListenerGotoMainClassOnStartup); Configuration.autoRenameIdentifiers.removeListener(configListenerAutoRenameIdentifiers); + Configuration.autoOpenLoadedSWFs.removeListener(configListenerAutoOpenLoadedSWFs); Main.stopRun(); }