From de2b4739c870f1addc0fe9e9a5ec46358805c024 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Wed, 18 May 2016 15:56:54 +0200 Subject: [PATCH] hide memory search on non windows platform + show warning on command-line memory search on non-windows platform --- .../console/CommandLineArgumentParser.java | 122 ++++++++++-------- .../decompiler/flash/gui/MainFrameMenu.java | 6 +- 2 files changed, 69 insertions(+), 59 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index f8c1c38b2..2c0491e9b 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -1922,75 +1922,83 @@ public class CommandLineArgumentParser { badArguments("memorysearch"); } - AtomicInteger cnt = new AtomicInteger(); - List procs = new ArrayList<>(); - List processList = ProcessTools.listProcesses(); - while (args.size() > 0) { - String arg = args.pop(); - if (arg.matches("\\d+")) { - int processId = 0; - try { - processId = Integer.parseInt(arg); - } catch (NumberFormatException nfe) { - System.err.println("ProcessId should be integer"); - badArguments("memorysearch"); - } - - boolean found = false; - for (Process process : processList) { - if (process.getPid() == processId) { - if (!procs.contains(process)) { - procs.add(process); - } - - found = true; - break; // only 1 process can have this process id + if (Platform.isWindows()) { + AtomicInteger cnt = new AtomicInteger(); + List procs = new ArrayList<>(); + List processList = ProcessTools.listProcesses(); + while (args.size() > 0) { + String arg = args.pop(); + if (arg.matches("\\d+")) { + int processId = 0; + try { + processId = Integer.parseInt(arg); + } catch (NumberFormatException nfe) { + System.err.println("ProcessId should be integer"); + badArguments("memorysearch"); } - } - if (!found) { - System.out.println("Process id=" + processId + " was not found."); - } - } else { - boolean found = false; - for (Process process : processList) { - if (process.getFileName().equals(arg)) { - if (!procs.contains(process)) { - procs.add(process); + boolean found = false; + if (processList != null) { + for (Process process : processList) { + if (process.getPid() == processId) { + if (!procs.contains(process)) { + procs.add(process); + } + + found = true; + break; // only 1 process can have this process id + } } - - found = true; } - } - if (!found) { - System.out.println("Process name=" + arg + " was not found."); + if (!found) { + System.out.println("Process id=" + processId + " was not found."); + } + } else { + boolean found = false; + if (processList != null) { + for (Process process : processList) { + if (process.getFileName().equals(arg)) { + if (!procs.contains(process)) { + procs.add(process); + } + + found = true; + } + } + } + + if (!found) { + System.out.println("Process name=" + arg + " was not found."); + } } } - } - try { - new SearchInMemory(new SearchInMemoryListener() { + 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"; - System.out.println("SWF found (" + fileName + "). Version: " + swf.version + ", file size: " + swf.fileSize + ", address: " + swf.address); - Helper.writeFile(fileName, swf.is); + @Override + public void publish(Object... chunks) { + for (Object s : chunks) { + if (s instanceof SwfInMemory) { + SwfInMemory swf = (SwfInMemory) s; + String fileName = cnt.getAndIncrement() + ".swf"; + System.out.println("SWF found (" + fileName + "). Version: " + swf.version + ", file size: " + swf.fileSize + ", address: " + swf.address); + Helper.writeFile(fileName, swf.is); + } } } - } - @Override - public void setProgress(int progress) { - // ignore - } - }).search(procs); - } catch (Exception ex) { - logger.log(Level.SEVERE, null, ex); + @Override + public void setProgress(int progress) { + // ignore + } + }).search(procs); + } catch (Exception ex) { + logger.log(Level.SEVERE, null, ex); + } + } else { + System.err.println("Memory search is only available on Windows platform."); } System.exit(0); diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java index 978640bd3..93efd3cff 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java @@ -882,9 +882,11 @@ public abstract class MainFrameMenu implements MenuBuilder { addToggleMenuItem("/tools/timeline", translate("menu.tools.timeline"), null, "timeline32", this::timelineActionPerformed, PRIORITY_TOP, null); addMenuItem("/tools/showProxy", translate("menu.tools.proxy"), "proxy16", this::showProxyActionPerformed, PRIORITY_MEDIUM, null, true, null, false); - addMenuItem("/tools/searchMemory", translate("menu.tools.searchMemory"), "loadmemory16", this::searchMemoryActionPerformed, PRIORITY_MEDIUM, null, true, null, false); - //addMenuItem("/tools/searchCache", translate("menu.tools.searchCache"), "loadcache16", this::searchCacheActionPerformed, PRIORITY_MEDIUM, null, true, null); + if (Platform.isWindows()) { + addMenuItem("/tools/searchMemory", translate("menu.tools.searchMemory"), "loadmemory16", this::searchMemoryActionPerformed, PRIORITY_MEDIUM, null, true, null, false); + } + //addMenuItem("/tools/searchCache", translate("menu.tools.searchCache"), "loadcache16", this::searchCacheActionPerformed, PRIORITY_MEDIUM, null, true, null); addMenuItem("/tools/deobfuscation", translate("menu.tools.deobfuscation"), "deobfuscate16", null, 0, null, false, null, false); addMenuItem("/tools/deobfuscation/renameOneIdentifier", translate("menu.tools.deobfuscation.globalrename"), "rename16", this::renameOneIdentifier, PRIORITY_MEDIUM, null, true, null, false); addMenuItem("/tools/deobfuscation/renameInvalidIdentifiers", translate("menu.tools.deobfuscation.renameinvalid"), "renameall16", this::renameInvalidIdentifiers, PRIORITY_MEDIUM, null, true, null, false);