in compiler/src/main/java/org/apache/royale/swf/io/SWFDump.java [2391:2631]
public static void main(String[] args) throws IOException
{
// This message should not be localized.
System.err.println("Apache Royale SWF Dump Utility");
System.err.println(VersionInfo.buildMessage());
System.err.println("");
if (args.length == 0)
{
// TODO: decide which options to implement.
// System.err.println("Usage: swfdump [-encode] [-asm] [-abc] [-showbytecode] [-showdebugsource] [-showoffset] [-noglyphs] [-save file.swf] [-nofunctions] [-out file.swfx] file1.swf ...");
System.err.println("Usage: swfdump [-abc] file1.swf");
System.exit(1);
}
int index = 0;
PrintWriter out = null;
String outfile = null;
while ((index < args.length) && (args[index].startsWith("-")))
{
if (args[index].equals("-encode"))
{
encodeOption = true;
++index;
}
else if (args[index].equals("-verbose"))
{
++index;
verboseOption = true;
}
else if (args[index].equals("-save"))
{
++index;
saveOption = true;
outfile = args[index++];
}
else if (args[index].equals("-sort"))
{
// Try to sort output by alpha-order of identifiers
// so compare of two dumps compare better.
// There is some randomness in the order of output
// of some scripts
++index;
sortOption = true;
}
else if (args[index].equals("-uncompress"))
{
++index;
uncompressOption = true;
outfile = args[index++];
}
else if (args[index].equals("-decompile"))
{
decompileOption = true;
++index;
}
else if (args[index].equals("-nofunctions"))
{
defuncOption = false;
++index;
}
else if (args[index].equals("-asm"))
{
decompileOption = false;
++index;
}
else if (args[index].equals("-abc"))
{
abcOption = true;
++index;
}
else if (args[index].equals("-noactions"))
{
showActionsOption = false;
++index;
}
else if (args[index].equals("-showoffset"))
{
showOffsetOption = true;
++index;
}
else if (args[index].equals("-showbytecode"))
{
showByteCodeOption = true;
++index;
}
else if (args[index].equals("-showdebugsource"))
{
showDebugSourceOption = true;
++index;
}
else if (args[index].equals("-noglyphs"))
{
glyphsOption = false;
++index;
}
else if (args[index].equals("-out"))
{
if (index + 1 == args.length)
{
System.err.println("-out requires a filename or - for stdout");
System.exit(1);
}
if (!args[index + 1].equals("-"))
{
outfile = args[index + 1];
out = new PrintWriter(outfile, "UTF-8");
}
index += 2;
}
else if (args[index].equals("-external"))
{
externalOption = true;
++index;
}
else if (args[index].equalsIgnoreCase("-tabbedGlyphs"))
{
tabbedGlyphsOption = true;
++index;
}
else
{
System.err.println("unknown argument " + args[index]);
++index;
}
}
if (out == null)
out = new PrintWriter(new OutputStreamWriter(System.out, "UTF-8"), true);
File f = new File(args[index]);
URL[] urls = new URL[0];
File currentFile = f;
try
{
if (!f.exists())
{
urls = new URL[] {new URL(args[index])};
}
else
{
if (f.isDirectory())
{
File[] list = listFiles(f);
urls = new URL[list.length];
for (int i = 0; i < list.length; i++)
{
currentFile = list[i];
urls[i] = toURL(list[i]);
}
}
else
{
urls = new URL[] {toURL(f)};
}
}
}
catch (MalformedURLException e)
{
System.err.println("Unable to open " + currentFile);
}
for (int i = 0; i < urls.length; i++)
{
try
{
URL url = urls[i];
if (saveOption)
{
InputStream in = new BufferedInputStream(url.openStream());
try
{
OutputStream fileOut = new BufferedOutputStream(new FileOutputStream(outfile));
try
{
int c;
while ((c = in.read()) != -1)
{
fileOut.write(c);
}
}
finally
{
fileOut.close();
}
}
finally
{
in.close();
}
}
if (uncompressOption)
{
final SWFReader swfReader = new SWFReader();
final String path = url.getPath();
try
{
SWF swf = (SWF)swfReader.readFrom(
new BufferedInputStream(url.openStream()),
path);
ProblemQuery problemQuery = new ProblemQuery();
problemQuery.addAll(swfReader.getProblems());
if (!problemQuery.hasErrors())
{
OutputStream fileOut = new BufferedOutputStream(new FileOutputStream(outfile));
SWFWriter swfWriter = new SWFWriter(swf, Header.Compression.NONE);
swfWriter.writeTo(fileOut);
swfWriter.close();
}
}
finally
{
IOUtils.closeQuietly(swfReader);
}
}
if (!uncompressOption)
dumpSwf(out, url, outfile);
out.flush();
}
catch (Error e)
{
if (Trace.error)
e.printStackTrace();
System.err.println("");
System.err.println("An unrecoverable error occurred. The given file " + urls[i] + " may not be");
System.err.println("a valid swf.");
}
catch (FileNotFoundException e)
{
System.err.println("Error: " + e.getMessage());
System.exit(1);
}
}
}