enable debugging of SWF file, from commandline

This commit is contained in:
Jindra Petřík
2015-10-24 19:13:36 +02:00
parent eab1e53e2a
commit b9c289464d
3 changed files with 202 additions and 0 deletions

View File

@@ -459,6 +459,13 @@ public class CommandLineArgumentParser {
out.println(" ...WARNING: The deobfuscation result is still probably far enough to be openable by other decompilers.");
}
if (filter == null || filter.equals("enabledebugging")) {
out.println(" " + (cnt++) + ") -enabledebugging [-injectas3] <infile> <outfile>");
out.println(" ...Enables debugging for <infile> and saves result to <outfile>");
out.println(" ...When optional -injectas3 parameter specified, debugfile and debugline instructions are injected into the code to match decompiled source.");
out.println(" ...WARNING: not everything works yet");
}
printCmdLineUsageExamples(out, filter);
}
@@ -514,6 +521,11 @@ public class CommandLineArgumentParser {
exampleFound = true;
}
if (filter == null || filter.equals("enabledebugging")) {
out.println("java -jar ffdec.jar -enabledebugging -injectas3 myas3file.swf myas3file_debug.swf");
exampleFound = true;
}
if (!exampleFound) {
out.println("Sorry, no example found for command " + filter + ", Let us know in issue tracker when you need it.");
}
@@ -664,6 +676,8 @@ public class CommandLineArgumentParser {
parseDumpAS2(args);
} else if (command.equals("dumpas3")) {
parseDumpAS3(args);
} else if (command.equals("enabledebugging")) {
parseEnableDebugging(args);
} else if (command.equals("flashpaper2pdf")) {
parseFlashPaperToPdf(selection, zoom, args);
} else if (command.equals("replace")) {
@@ -2768,6 +2782,46 @@ public class CommandLineArgumentParser {
}
}
private static void parseEnableDebugging(Stack<String> args) {
if (args.size() < 2) {
badArguments("enabledebugging");
}
boolean injectas3 = false;
String file = args.pop();
if (file.equals("-injectas3")) {
if (args.size() < 2) {
badArguments("enabledebugging");
}
file = args.pop();
injectas3 = true;
}
String outfile = args.pop();
try {
System.out.print("Working...");
FileInputStream fis = new FileInputStream(file);
SWF swf = new SWF(fis, Configuration.parallelSpeedUp.get());
fis.close();
swf.enableDebugging(injectas3);
FileOutputStream fos = new FileOutputStream(outfile);
swf.saveTo(fos);
fos.close();
System.out.println("OK");
} catch (FileNotFoundException ex) {
Logger.getLogger(CommandLineArgumentParser.class.getName()).log(Level.SEVERE, "Cannot read " + file);
System.exit(1);
} catch (IOException ex) {
Logger.getLogger(CommandLineArgumentParser.class.getName()).log(Level.SEVERE, "Reading error " + file);
System.exit(2);
} catch (InterruptedException ex) {
Logger.getLogger(CommandLineArgumentParser.class.getName()).log(Level.SEVERE, "Cancelled " + file);
System.exit(3);
}
System.out.println("Finished");
System.exit(0);
}
private static void parseDumpAS3(Stack<String> args) {
if (args.isEmpty()) {
badArguments("dumpas3");