From d2432eb6b6220c902d42978287a22192709394ad Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Sun, 13 Mar 2016 09:40:16 +0100 Subject: [PATCH] #1170 Extract from Memory in Command Line --- .../src/com/jpexs/decompiler/flash/SWF.java | 12 +-- .../decompiler/flash/abc/ScriptPack.java | 6 +- .../decompiler/flash/abc/avm2/AVM2Code.java | 30 +++---- .../flash/abc/types/MethodBody.java | 2 +- .../exporters/script/AS3ScriptExporter.java | 6 +- .../flash/helpers/SWFDecompilerPlugin.java | 4 +- .../flash/importers/AS3ScriptImporter.java | 2 +- .../flash/importers/svg/SvgStyle.java | 2 +- .../decompiler/flash/xfl/XFLConverter.java | 2 +- .../src/com/jpexs/helpers/Helper.java | 8 ++ .../console/CommandLineArgumentParser.java | 54 ++++++++++-- .../ConsoleAbortRetryIgnoreHandler.java | 2 +- .../flash/gui/LoadFromMemoryFrame.java | 55 +++--------- .../jpexs/decompiler/flash/gui/MainPanel.java | 6 +- .../decompiler/flash/gui/SearchInMemory.java | 88 +++++++++++++++++++ .../flash/gui/SearchInMemoryListener.java | 28 ++++++ .../decompiler/flash/gui/SearchListener.java | 6 +- 17 files changed, 223 insertions(+), 90 deletions(-) create mode 100644 src/com/jpexs/decompiler/flash/gui/SearchInMemory.java create mode 100644 src/com/jpexs/decompiler/flash/gui/SearchInMemoryListener.java 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 4425238f9..85c168a5f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -209,7 +209,7 @@ public final class SWF implements SWFContainerItem, Timelined { * Maximum SWF file format version Needs to be fixed when SWF versions * reaches this value */ - public static final int MAX_VERSION = 30; + public static final int MAX_VERSION = 32; /** * Tags inside of file @@ -2562,7 +2562,7 @@ public final class SWF implements SWFContainerItem, Timelined { } catch (InterruptedException ex) { throw ex; } catch (Exception ex) { - Logger.getLogger(SWF.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); return new ActionList(); } } @@ -3259,7 +3259,7 @@ public final class SWF implements SWFContainerItem, Timelined { items.add(new SWD.DebugId(dit.debugId)); } catch (Throwable t) { - Logger.getLogger(SWF.class.getName()).log(Level.SEVERE, "message", t); + logger.log(Level.SEVERE, "message", t); return false; } @@ -3309,7 +3309,7 @@ public final class SWF implements SWFContainerItem, Timelined { SWD.DebugBreakpoint dbp = new SWD.DebugBreakpoint(moduleId, bpline); items.add(dbp); } catch (IllegalArgumentException iex) { - Logger.getLogger(SWF.class.getName()).log(Level.WARNING, "Cannot generate breakpoint to SWD: {0}", iex.getMessage()); + logger.log(Level.WARNING, "Cannot generate breakpoint to SWD: {0}", iex.getMessage()); } } } @@ -3430,7 +3430,7 @@ public final class SWF implements SWFContainerItem, Timelined { SWD.DebugBreakpoint dbp = new SWD.DebugBreakpoint(moduleId, bpline); items.add(dbp); } catch (IllegalArgumentException iex) { - Logger.getLogger(SWF.class.getName()).log(Level.WARNING, "Cannot generate breakpoint to SWD: {0}", iex.getMessage()); + logger.log(Level.WARNING, "Cannot generate breakpoint to SWD: {0}", iex.getMessage()); } } } @@ -3442,7 +3442,7 @@ public final class SWF implements SWFContainerItem, Timelined { //items.addAll(swfBps); } catch (Throwable t) { - Logger.getLogger(SWF.class.getName()).log(Level.SEVERE, "message", t); + logger.log(Level.SEVERE, "message", t); return false; } SWD swd = new SWD(7, items); 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 ded918e42..2313ca712 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 @@ -430,7 +430,7 @@ public class ScriptPack extends AS3ClassTreeItem { } } catch (InterruptedException ex) { - Logger.getLogger(ScriptPack.class.getName()).log(Level.SEVERE, "Cannot decompile", ex); + logger.log(Level.SEVERE, "Cannot decompile", ex); } int scriptInitBody = abc.findBodyIndex(abc.script_info.get(scriptIndex).init_index); if (!bodyToRegToName.containsKey(scriptInitBody)) { @@ -501,7 +501,7 @@ public class ScriptPack extends AS3ClassTreeItem { continue; } addedLines.add(line); - Logger.getLogger(ScriptPack.class.getName()).log(Level.FINE, "Script " + path + ": Insert debugline(" + line + ") at pos " + i + " to body " + bodyIndex); + logger.log(Level.FINE, "Script " + path + ": Insert debugline(" + line + ") at pos " + i + " to body " + bodyIndex); b.insertInstruction(i + dpos, new AVM2Instruction(0, AVM2Instructions.DebugLine, new int[]{line})); } //remove old debug instructions @@ -565,7 +565,7 @@ public class ScriptPack extends AS3ClassTreeItem { } } } catch (InterruptedException ex) { - Logger.getLogger(ScriptPack.class.getName()).log(Level.SEVERE, "Cannot decompile", ex); + logger.log(Level.SEVERE, "Cannot decompile", ex); } int scriptInitBody = abc.findBodyIndex(abc.script_info.get(scriptIndex).init_index); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index 7425bb650..7ce9f8c42 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -292,11 +292,9 @@ import com.jpexs.decompiler.graph.SimpleValue; import com.jpexs.decompiler.graph.TranslateStack; import com.jpexs.decompiler.graph.TypeItem; import com.jpexs.decompiler.graph.model.BinaryOpItem; -import com.jpexs.decompiler.graph.model.DoWhileItem; import com.jpexs.decompiler.graph.model.ExitItem; import com.jpexs.decompiler.graph.model.IfItem; import com.jpexs.decompiler.graph.model.ScriptEndItem; -import com.jpexs.decompiler.graph.model.WhileItem; import com.jpexs.helpers.Helper; import com.jpexs.helpers.stat.Statistics; import java.io.ByteArrayInputStream; @@ -1568,7 +1566,7 @@ public class AVM2Code implements Cloneable { } }//*/ - /*if ((ip + 2 < code.size()) && (ins.definition instanceof NewCatchIns)) { // Filling local register in catch clause + /*if ((ip + 2 < code.size()) && (ins.definition instanceof NewCatchIns)) { // Filling local register in catch clause if (code.get(ip + 1).definition instanceof DupIns) { if (code.get(ip + 2).definition instanceof SetLocalTypeIns) { ins.definition.translate(isStatic, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames); @@ -2086,19 +2084,19 @@ public class AVM2Code implements Cloneable { ins.operands[k] = updater.updateOperandOffset(ins.getAddress(), target, ins.operands[k]); } } else /*for (int j = 0; j < ins.definition.operands.length; j++) { - if (ins.definition.operands[j] == AVM2Code.DAT_OFFSET) { - long target = ins.offset + ins.getBytes().length + ins.operands[j]; - ins.operands[j] = updater.updateOperandOffset(target, ins.operands[j]); - } - }*/ //Faster, but not so universal - if (ins.definition instanceof IfTypeIns) { - long target = ins.getTargetAddress(); - try { - ins.operands[0] = updater.updateOperandOffset(ins.getAddress(), target, ins.operands[0]); - } catch (ConvertException cex) { - throw new ConvertException("Invalid offset (" + ins + ")", i); - } + if (ins.definition.operands[j] == AVM2Code.DAT_OFFSET) { + long target = ins.offset + ins.getBytes().length + ins.operands[j]; + ins.operands[j] = updater.updateOperandOffset(target, ins.operands[j]); + } + }*/ //Faster, but not so universal + if (ins.definition instanceof IfTypeIns) { + long target = ins.getTargetAddress(); + try { + ins.operands[0] = updater.updateOperandOffset(ins.getAddress(), target, ins.operands[0]); + } catch (ConvertException cex) { + throw new ConvertException("Invalid offset (" + ins + ")", i); } + } ins.setAddress(updater.updateInstructionOffset(ins.getAddress())); } @@ -2141,7 +2139,7 @@ public class AVM2Code implements Cloneable { } } if (someIgnored) { - Logger.getLogger(AVM2Code.class.getName()).log(Level.WARNING, path + ": One or more invalid jump offsets found in the code. Those instructions were ignored."); + logger.log(Level.WARNING, path + ": One or more invalid jump offsets found in the code. Those instructions were ignored."); } removeIgnored(body); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java index 0164dafa8..dcfde7578 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java @@ -416,7 +416,7 @@ public final class MethodBody implements Cloneable { writer.unindent().unindent().unindent(); return writer.toString(); } catch (InterruptedException ex) { - Logger.getLogger(MethodBody.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); } return null; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS3ScriptExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS3ScriptExporter.java index 7ebf49e2d..06166ce43 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS3ScriptExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS3ScriptExporter.java @@ -170,7 +170,7 @@ public class AS3ScriptExporter { } catch (InterruptedException ex) { //? - Logger.getLogger(AS3ScriptExporter.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); } return out.toString(); } @@ -208,7 +208,7 @@ public class AS3ScriptExporter { //declaration->setlocal->(coreceavm)->NewArray[ callpropertyav ->receiver this, propName ] } catch (InterruptedException ex) { //? - Logger.getLogger(AS3ScriptExporter.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); } return out.toString(); } @@ -334,7 +334,7 @@ public class AS3ScriptExporter { } } catch (InterruptedException ex) { - Logger.getLogger(AS3ScriptExporter.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/SWFDecompilerPlugin.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/SWFDecompilerPlugin.java index ac82a2cfb..9f87ea551 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/SWFDecompilerPlugin.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/SWFDecompilerPlugin.java @@ -69,7 +69,7 @@ public class SWFDecompilerPlugin { pluginPath = new File(Path.combine(dir.getPath(), "plugins")).getCanonicalFile(); } } catch (IOException | URISyntaxException ex) { - Logger.getLogger(SWFDecompilerPlugin.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); } return pluginPath; } @@ -118,7 +118,7 @@ public class SWFDecompilerPlugin { System.out.println("Plugin loaded: " + pluginName); } catch (MalformedURLException | ClassNotFoundException | InstantiationException | IllegalAccessException ex) { - Logger.getLogger(SWFDecompilerPlugin.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/AS3ScriptImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/AS3ScriptImporter.java index 3614a8f66..c00596ff9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/AS3ScriptImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/AS3ScriptImporter.java @@ -62,7 +62,7 @@ public class AS3ScriptImporter { importCount++; } } catch (IOException ex) { - Logger.getLogger(AS3ScriptImporter.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/svg/SvgStyle.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/svg/SvgStyle.java index b9e9761d2..34a7ad70f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/svg/SvgStyle.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/svg/SvgStyle.java @@ -559,7 +559,7 @@ class SvgStyle { return bitmapFill; } catch (IOException ex) { - Logger.getLogger(ShapeImporter.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(SvgStyle.class.getName()).log(Level.SEVERE, null, ex); } } } 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 9e67260d2..1c826041e 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 @@ -853,7 +853,7 @@ public class XFLConverter { } } } catch (XMLStreamException ex) { - Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); } return ret; diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java b/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java index 1df178163..27c8f46f9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java @@ -707,6 +707,14 @@ public class Helper { } } + public static void writeFile(String file, InputStream stream) { + try (FileOutputStream fos = new FileOutputStream(file)) { + copyStream(stream, fos); + } catch (IOException ex) { + // ignore + } + } + public static String stackToString(TranslateStack stack, LocalData localData) throws InterruptedException { String ret = "["; for (int i = stack.size() - 1; i >= 0; i--) { diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index 86ae16932..c95db01d3 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -79,6 +79,9 @@ import com.jpexs.decompiler.flash.exporters.settings.SpriteExportSettings; import com.jpexs.decompiler.flash.exporters.settings.TextExportSettings; import com.jpexs.decompiler.flash.exporters.swf.SwfXmlExporter; import com.jpexs.decompiler.flash.gui.Main; +import com.jpexs.decompiler.flash.gui.SearchInMemory; +import com.jpexs.decompiler.flash.gui.SearchInMemoryListener; +import com.jpexs.decompiler.flash.gui.SwfInMemory; import com.jpexs.decompiler.flash.gui.helpers.CheckResources; import com.jpexs.decompiler.flash.helpers.FileTextWriter; import com.jpexs.decompiler.flash.helpers.SWFDecompilerPlugin; @@ -161,6 +164,7 @@ import java.util.Map.Entry; import java.util.Stack; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; +import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; import java.util.logging.Logger; @@ -368,6 +372,11 @@ public class CommandLineArgumentParser { out.println(" ...-o parameter should contain a folder path when no extaction mode or \"all\" parameter is specified"); } + if (filter == null || filter.equals("memorysearch")) { + out.println(" " + (cnt++) + ") -memorySearch (|) (|)..."); + out.println(" ...Search SWF files in the memory"); + } + if (filter == null || filter.equals("renameinvalididentifiers")) { out.println(" " + (cnt++) + ") -renameInvalidIdentifiers (typeNumber|randomWord) "); out.println(" ...Renames the invalid identifiers in and save it to "); @@ -689,6 +698,8 @@ public class CommandLineArgumentParser { parseXml2Swf(args); } else if (command.equals("extract")) { parseExtract(args); + } else if (command.equals("memorySearch")) { + parseMemorySearch(args); } else if (command.equals("deobfuscate")) { parseDeobfuscate(args); } else if (command.equals("renameinvalididentifiers")) { @@ -1649,7 +1660,7 @@ public class CommandLineArgumentParser { logger.log(Level.SEVERE, null, ex); System.exit(1); } catch (IOException ex) { - Logger.getLogger(CommandLineArgumentParser.class.getName()).log(Level.SEVERE, "Error", ex); + logger.log(Level.SEVERE, "Error", ex); System.exit(1); } finally { if (tmpFile != null && tmpFile.exists()) { @@ -1846,6 +1857,39 @@ public class CommandLineArgumentParser { System.exit(0); } + private static void parseMemorySearch(Stack args) { + if (args.size() < 1) { + badArguments("memorSearch"); + } + + AtomicInteger cnt = new AtomicInteger(); + List procs = null; + try { + new SearchInMemory(new SearchInMemoryListener() { + + @Override + public void publish(Object... chunks) { + for (Object s : chunks) { + if (s instanceof SwfInMemory) { + SwfInMemory swf = (SwfInMemory) s; + String fileName = cnt.getAndIncrement() + ".swf"; + Helper.writeFile(fileName, swf.is); + } + } + } + + @Override + public void setProgress(int progress) { + // ignore + } + }).search(procs); + } catch (Exception ex) { + logger.log(Level.SEVERE, null, ex); + } + + System.exit(0); + } + private static void parseRenameInvalidIdentifiers(Stack args) { if (args.size() < 3) { badArguments("renameinvalididentifiers"); @@ -2639,7 +2683,7 @@ public class CommandLineArgumentParser { } out = new File(args.pop()); if (out.isDirectory()) { - Logger.getLogger(CommandLineArgumentParser.class.getName()).log(Level.SEVERE, "File is a directory"); + logger.log(Level.SEVERE, "File is a directory"); System.exit(1); } else { pw = new PrintWriter(out); @@ -2903,13 +2947,13 @@ public class CommandLineArgumentParser { } System.out.println("OK"); } catch (FileNotFoundException ex) { - Logger.getLogger(CommandLineArgumentParser.class.getName()).log(Level.SEVERE, "Cannot read " + file); + logger.log(Level.SEVERE, "Cannot read {0}", file); System.exit(1); } catch (IOException ex) { - Logger.getLogger(CommandLineArgumentParser.class.getName()).log(Level.SEVERE, "Reading error " + file); + logger.log(Level.SEVERE, "Reading error {0}", file); System.exit(2); } catch (InterruptedException ex) { - Logger.getLogger(CommandLineArgumentParser.class.getName()).log(Level.SEVERE, "Cancelled " + file); + logger.log(Level.SEVERE, "Cancelled {0}", file); System.exit(3); } diff --git a/src/com/jpexs/decompiler/flash/console/ConsoleAbortRetryIgnoreHandler.java b/src/com/jpexs/decompiler/flash/console/ConsoleAbortRetryIgnoreHandler.java index 1f4447165..2e856a433 100644 --- a/src/com/jpexs/decompiler/flash/console/ConsoleAbortRetryIgnoreHandler.java +++ b/src/com/jpexs/decompiler/flash/console/ConsoleAbortRetryIgnoreHandler.java @@ -52,7 +52,7 @@ public class ConsoleAbortRetryIgnoreHandler implements AbortRetryIgnoreHandler { return result; } Scanner sc = new Scanner(System.in); - Logger.getLogger(CommandLineArgumentParser.class.getName()).log(Level.SEVERE, "Error occured", thrown); + Logger.getLogger(ConsoleAbortRetryIgnoreHandler.class.getName()).log(Level.SEVERE, "Error occured", thrown); System.out.println("Error occured: " + thrown.getLocalizedMessage()); do { System.out.print("Select action: (A)bort, (R)Retry, (I)Ignore:"); diff --git a/src/com/jpexs/decompiler/flash/gui/LoadFromMemoryFrame.java b/src/com/jpexs/decompiler/flash/gui/LoadFromMemoryFrame.java index 1a4d956ac..8f3a0d84e 100644 --- a/src/com/jpexs/decompiler/flash/gui/LoadFromMemoryFrame.java +++ b/src/com/jpexs/decompiler/flash/gui/LoadFromMemoryFrame.java @@ -16,13 +16,9 @@ */ package com.jpexs.decompiler.flash.gui; -import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFSourceInfo; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.helpers.Helper; -import com.jpexs.helpers.LimitedInputStream; -import com.jpexs.helpers.PosMarkedInputStream; -import com.jpexs.helpers.ProgressListener; import com.jpexs.helpers.ReReadableInputStream; import com.jpexs.process.ProcessTools; import java.awt.BorderLayout; @@ -41,11 +37,9 @@ import java.awt.event.WindowEvent; import java.beans.PropertyChangeEvent; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.logging.Level; import java.util.logging.Logger; @@ -120,45 +114,18 @@ public class LoadFromMemoryFrame extends AppFrame { @Override protected List doInBackground() throws Exception { - List swfStreams = new ArrayList<>(); - for (com.jpexs.process.Process proc : procs) { - publish(proc); - Map ret = proc.search(new ProgressListener() { - @Override - public void progress(int p) { - setProgress(p); - } - }, "CWS".getBytes(), "FWS".getBytes(), "ZWS".getBytes()); - int pos = 0; - for (Long addr : ret.keySet()) { - setProgress(pos * 100 / ret.size()); - pos++; - try { - PosMarkedInputStream pmi = new PosMarkedInputStream(ret.get(addr)); - ReReadableInputStream is = new ReReadableInputStream(pmi); - SWF swf = new SWF(is, null, null, null, false, true, false); - long limit = pmi.getPos(); - is.seek(0); - is = new ReReadableInputStream(new LimitedInputStream(is, limit)); - if (swf.fileSize > 0 && swf.version > 0 && !swf.getTags().isEmpty() && swf.version < 25/*Needs to be fixed when SWF versions reaches this value*/) { - SwfInMemory s = new SwfInMemory(is, swf.version, swf.fileSize, proc); - String p = translate("swfitem").replace("%version%", Integer.toString(swf.version)).replace("%size%", Long.toString(swf.fileSize)); - publish(s); - swfStreams.add(s); - } - - } catch (OutOfMemoryError ome) { - Helper.freeMem(); - } catch (Exception | Error ex) { - } + return new SearchInMemory(new SearchInMemoryListener() { + @Override + public void publish(Object... chunks) { + SelectProcessWorker.this.publish(chunks); } - setProgress(100); - } - if (swfStreams.isEmpty()) { - return null; - } - return swfStreams; + + @Override + public void setProgress(int progress) { + SelectProcessWorker.this.setProgress(progress); + } + }).search(procs); } } @@ -293,7 +260,7 @@ public class LoadFromMemoryFrame extends AppFrame { list.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == 10) { //Enter pressed + if (e.getKeyCode() == KeyEvent.VK_ENTER) { //Enter pressed selectProcess(); } } diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 7b1e7ccc8..6324001d1 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -590,7 +590,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se try { files = exportSelection(new GuiAbortRetryIgnoreHandler(), tempDir, exd); } catch (InterruptedException ex) { - Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex); + logger.log(Level.SEVERE, null, ex); return null; } @@ -2027,7 +2027,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se swf.exportXfl(errorHandler, selfile.getAbsolutePath(), new File(swf.getFile()).getName(), ApplicationInfo.APPLICATION_NAME, ApplicationInfo.applicationVerName, ApplicationInfo.version, Configuration.parallelSpeedUp.get(), selectedVersion); } } catch (Exception ex) { - Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, "FLA export error", ex); + logger.log(Level.SEVERE, "FLA export error", ex); View.showMessageDialog(null, translate("error.export") + ": " + ex.getClass().getName() + " " + ex.getLocalizedMessage(), translate("error"), JOptionPane.ERROR_MESSAGE); } Helper.freeMem(); @@ -3280,7 +3280,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se } catch (CancellationException ex) { getABCPanel().decompiledTextArea.setText("// " + AppStrings.translate("work.canceled")); } catch (Exception ex) { - Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, "Error", ex); + logger.log(Level.SEVERE, "Error", ex); getABCPanel().decompiledTextArea.setText("// " + AppStrings.translate("decompilationError") + ": " + ex); } diff --git a/src/com/jpexs/decompiler/flash/gui/SearchInMemory.java b/src/com/jpexs/decompiler/flash/gui/SearchInMemory.java new file mode 100644 index 000000000..e79b0200e --- /dev/null +++ b/src/com/jpexs/decompiler/flash/gui/SearchInMemory.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2010-2016 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.gui; + +import com.jpexs.decompiler.flash.SWF; +import com.jpexs.helpers.Helper; +import com.jpexs.helpers.LimitedInputStream; +import com.jpexs.helpers.PosMarkedInputStream; +import com.jpexs.helpers.ReReadableInputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * + * @author JPEXS + */ +public class SearchInMemory { + + private final SearchInMemoryListener listener; + + public SearchInMemory(SearchInMemoryListener listener) { + this.listener = listener; + } + + private void publish(Object... chunks) { + if (listener != null) { + listener.publish(chunks); + } + } + + private void setProgress(int progress) { + if (listener != null) { + listener.setProgress(progress); + } + } + + public List search(List procs) throws Exception { + List swfStreams = new ArrayList<>(); + for (com.jpexs.process.Process proc : procs) { + publish(proc); + Map ret = proc.search(this::setProgress, "CWS".getBytes(), "FWS".getBytes(), "ZWS".getBytes()); + int pos = 0; + for (Long addr : ret.keySet()) { + setProgress(pos * 100 / ret.size()); + pos++; + try { + PosMarkedInputStream pmi = new PosMarkedInputStream(ret.get(addr)); + ReReadableInputStream is = new ReReadableInputStream(pmi); + SWF swf = new SWF(is, null, null, null, false, true, false); + long limit = pmi.getPos(); + is.seek(0); + is = new ReReadableInputStream(new LimitedInputStream(is, limit)); + if (swf.fileSize > 0 && swf.version > 0 && !swf.getTags().isEmpty() && swf.version <= SWF.MAX_VERSION) { + SwfInMemory s = new SwfInMemory(is, swf.version, swf.fileSize, proc); + publish(s); + swfStreams.add(s); + } + + } catch (OutOfMemoryError ome) { + Helper.freeMem(); + } catch (Exception | Error ex) { + } + + } + setProgress(100); + } + if (swfStreams.isEmpty()) { + return null; + } + return swfStreams; + } +} diff --git a/src/com/jpexs/decompiler/flash/gui/SearchInMemoryListener.java b/src/com/jpexs/decompiler/flash/gui/SearchInMemoryListener.java new file mode 100644 index 000000000..76715b099 --- /dev/null +++ b/src/com/jpexs/decompiler/flash/gui/SearchInMemoryListener.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2010-2016 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.gui; + +/** + * + * @author JPEXS + */ +public interface SearchInMemoryListener { + + public void publish(Object... chunks); + + public void setProgress(int progress); +} diff --git a/src/com/jpexs/decompiler/flash/gui/SearchListener.java b/src/com/jpexs/decompiler/flash/gui/SearchListener.java index e918761af..8ef395ddb 100644 --- a/src/com/jpexs/decompiler/flash/gui/SearchListener.java +++ b/src/com/jpexs/decompiler/flash/gui/SearchListener.java @@ -1,16 +1,16 @@ /* * Copyright (C) 2010-2016 JPEXS - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program 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 General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */