Example #1
0
		private static void  dumpSwf(System.IO.StreamWriter out_Renamed, System.Uri url, System.String outfile)
		{
			//UPGRADE_TODO: Method 'java.io.PrintWriter.println' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioPrintWriterprintln_javalangString'"
			out_Renamed.WriteLine("<!-- Parsing swf " + url + " -->");
			System.IO.Stream in_Renamed;
			SwfxPrinter debugPrinter = new SwfxPrinter(out_Renamed);
			
			debugPrinter.showActions = showActionsOption;
			debugPrinter.showOffset = showOffsetOption;
			debugPrinter.showDebugSource = showDebugSourceOption;
			debugPrinter.glyphs = glyphsOption;
			debugPrinter.setExternal(externalOption, outfile);
			debugPrinter.decompile = decompileOption;
			debugPrinter.abc = abcOption;
			debugPrinter.defunc = defuncOption;
			debugPrinter.tabbedGlyphs = tabbedGlyphsOption;
			
			if (encodeOption)
			{
				// decode -> encode -> decode -> print
				TagEncoder encoder = new TagEncoder();
				in_Renamed = System.Net.WebRequest.Create(url).GetResponse().GetResponseStream();
				new TagDecoder(in_Renamed, url).parse(encoder);
				encoder.finish();
				in_Renamed = new System.IO.MemoryStream(SupportClass.ToByteArray(encoder.toByteArray()));
			}
			else
			{
				// decode -> print
				in_Renamed = System.Net.WebRequest.Create(url).GetResponse().GetResponseStream();
			}
			TagDecoder t = new TagDecoder(in_Renamed, url);
			t.KeepOffsets = debugPrinter.showOffset;
			t.parse(debugPrinter);
		}
Example #2
0
		// Handy dandy for dumping an action list during debugging
		public static System.String actionListToString(ActionList al, System.String[] args)
		{
			// cut and paste arg code from main() could be better but it works
			bool showActions = true;
			bool showOffset = false;
			bool showDebugSource = false;
			bool decompile = false;
			bool defunc = true;
			bool tabbedGlyphs = true;
			int index = 0;
			
			while (args != null && (index < args.Length) && (args[index].StartsWith("-")))
			{
				if (args[index].Equals("-decompile"))
				{
					decompile = true;
					++index;
				}
				else if (args[index].Equals("-nofunctions"))
				{
					defunc = false;
					++index;
				}
				else if (args[index].Equals("-asm"))
				{
					decompile = false;
					++index;
				}
				else if (args[index].Equals("-noactions"))
				{
					showActions = false;
					++index;
				}
				else if (args[index].Equals("-showoffset"))
				{
					showOffset = true;
					++index;
				}
				else if (args[index].Equals("-showdebugsource"))
				{
					showDebugSource = true;
					++index;
				}
				else if (args[index].ToUpper().Equals("-tabbedGlyphs".ToUpper()))
				{
					tabbedGlyphs = true;
					++index;
				}
			}
			
			System.IO.StringWriter sw = new System.IO.StringWriter();
			//UPGRADE_ISSUE: Constructor 'java.io.PrintWriter.PrintWriter' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioPrintWriterPrintWriter_javaioWriter'"
			System.IO.StreamWriter out_Renamed = new PrintWriter(sw);
			SwfxPrinter printer = new SwfxPrinter(out_Renamed);
			printer.showActions = showActions;
			printer.showOffset = showOffset;
			printer.showDebugSource = showDebugSource;
			printer.decompile = decompile;
			printer.defunc = defunc;
			printer.tabbedGlyphs = tabbedGlyphs;
			
			printer.printActions(al);
			out_Renamed.Flush();
			return sw.ToString();
		}
Example #3
0
		public static void  Main(System.String[] args)
		{
			if (args.Length == 0)
			{
				System.Console.Error.WriteLine("Usage: java tools.SwfxPrinter [-encode] [-asm] [-abc] [-noactions] [-showdebugsource] [-showoffset] [-noglyphs] [-external] [-save file.swf] [-nofunctions] [-out file.swfx] file1.swf ...");
				System.Environment.Exit(1);
			}
			
			int index = 0;
			System.IO.StreamWriter out_Renamed = null;
			System.String outfile = null;
			
			while ((index < args.Length) && (args[index].StartsWith("-")))
			{
				if (args[index].Equals("-encode"))
				{
					encodeOption = true;
					++index;
				}
				else if (args[index].Equals("-save"))
				{
					++index;
					saveOption = 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("-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.Console.Error.WriteLine("-out requires a filename or - for stdout");
						System.Environment.Exit(1);
					}
					if (!args[index + 1].Equals("-"))
					{
						
						outfile = args[index + 1];
						//UPGRADE_TODO: Constructor 'java.io.FileOutputStream.FileOutputStream' was converted to 'System.IO.FileStream.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioFileOutputStreamFileOutputStream_javalangString_boolean'"
						out_Renamed = new System.IO.StreamWriter(SupportClass.GetFileStream(outfile, false), System.Text.Encoding.Default);
					}
					index += 2;
				}
				else if (args[index].Equals("-external"))
				{
					externalOption = true;
					++index;
				}
				else if (args[index].ToUpper().Equals("-tabbedGlyphs".ToUpper()))
				{
					tabbedGlyphsOption = true;
					++index;
				}
				else
				{
					System.Console.Error.WriteLine("unknown argument " + args[index]);
					++index;
				}
			}
			
			if (out_Renamed == null)
			{
				System.IO.StreamWriter temp_writer;
				temp_writer = new System.IO.StreamWriter(System.Console.OpenStandardOutput(), System.Text.Encoding.Default);
				temp_writer.AutoFlush = true;
				out_Renamed = temp_writer;
			}
			
			System.IO.FileInfo f = new System.IO.FileInfo(args[index]);
			System.Uri[] urls;
			bool tmpBool;
			if (System.IO.File.Exists(f.FullName))
				tmpBool = true;
			else
				tmpBool = System.IO.Directory.Exists(f.FullName);
			if (!tmpBool)
			{
				//UPGRADE_TODO: Class 'java.net.URL' was converted to a 'System.Uri' which does not throw an exception if a URL specifies an unknown protocol. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1132'"
				urls = new System.Uri[]{new System.Uri(args[index])};
			}
			else
			{
				if (System.IO.Directory.Exists(f.FullName))
				{
					System.IO.FileInfo[] list = FileUtils.listFiles(f);
					urls = new System.Uri[list.Length];
					for (int i = 0; i < list.Length; i++)
					{
						urls[i] = FileUtils.toURL(list[i]);
					}
				}
				else
				{
					urls = new System.Uri[]{FileUtils.toURL(f)};
				}
			}
			
			for (int i = 0; i < urls.Length; i++)
			{
				try
				{
					System.Uri url = urls[i];
					if (saveOption)
					{
						System.IO.Stream in_Renamed = new System.IO.BufferedStream(System.Net.WebRequest.Create(url).GetResponse().GetResponseStream());
						try
						{
							//UPGRADE_TODO: Constructor 'java.io.FileOutputStream.FileOutputStream' was converted to 'System.IO.FileStream.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioFileOutputStreamFileOutputStream_javalangString'"
							System.IO.Stream fileOut = new System.IO.BufferedStream(new System.IO.FileStream(outfile, System.IO.FileMode.Create));
							try
							{
								int c;
								while ((c = in_Renamed.ReadByte()) != - 1)
								{
									fileOut.WriteByte((System.Byte) c);
								}
							}
							finally
							{
								fileOut.Close();
							}
						}
						finally
						{
							in_Renamed.Close();
						}
					}
					
					if (isSwf(url))
					{
						dumpSwf(out_Renamed, url, outfile);
					}
					else if (isZip(url) && !url.ToString().EndsWith(".abj"))
					{
						dumpZip(out_Renamed, url, outfile);
					}
					else
					{
						//UPGRADE_TODO: Method 'java.io.PrintWriter.println' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioPrintWriterprintln_javalangString'"
						out_Renamed.WriteLine("<!-- Parsing actions from " + url + " -->");
						// we have no way of knowing the swf version, so assume latest
						System.Net.HttpWebRequest connection = (System.Net.HttpWebRequest) System.Net.WebRequest.Create(url);
						ActionDecoder actionDecoder = new ActionDecoder(new SwfDecoder(connection.GetResponse().GetResponseStream(), 7));
						actionDecoder.KeepOffsets = true;
						int ContentLength;
						try
						{
							ContentLength = System.Int32.Parse(connection.GetResponse().Headers.Get("Content-Length"));
						}
						catch (System.IO.IOException e)
						{
							ContentLength = -1;
						}
						ActionList actions = actionDecoder.decode(ContentLength);
						SwfxPrinter printer = new SwfxPrinter(out_Renamed);
						printer.decompile = decompileOption;
						printer.defunc = defuncOption;
						printer.printActions(actions);
					}
					out_Renamed.Flush();
				}
				catch (System.ApplicationException e)
				{
					if (Trace.error)
						SupportClass.WriteStackTrace(e, Console.Error);
					
					System.Console.Error.WriteLine("");
					System.Console.Error.WriteLine("An unrecoverable error occurred.  The given file " + urls[i] + " may not be");
					System.Console.Error.WriteLine("a valid swf.");
				}
				catch (System.IO.FileNotFoundException e)
				{
					//UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
					System.Console.Error.WriteLine("Error: " + e.Message);
					System.Environment.Exit(1);
				}
			}
		}