hide memory search on non windows platform + show warning on command-line memory search on non-windows platform

This commit is contained in:
honfika@gmail.com
2016-05-18 15:56:54 +02:00
parent 048af71117
commit de2b4739c8
2 changed files with 69 additions and 59 deletions

View File

@@ -1922,75 +1922,83 @@ public class CommandLineArgumentParser {
badArguments("memorysearch");
}
AtomicInteger cnt = new AtomicInteger();
List<com.jpexs.process.Process> procs = new ArrayList<>();
List<Process> 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<com.jpexs.process.Process> procs = new ArrayList<>();
List<Process> 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);