public bool Decompile(byte[] block, out string readSourceCode) { readSourceCode = string.Empty; try { var compiler = new Compiler(); compiler.DisassemblyBlock(block, out readSourceCode); } catch (System.Exception) { return false; } return true; }
static void disasm(string[] args) { string f = null, o = null; bool u = false; string port = "COM6", baud = "9600"; char parity = 'E'; int address = 2; var p = new OptionSet() { { "f|file=", v => f = v }, { "o|output=", v => o = v }, { "c|comport=", v => port = v }, { "b|baud=", v => baud = v }, { "p|parity=", v => parity = v[0] }, { "a|address=", v => address = int.Parse(v) }, { "u|upload", v => u = (v != null) }, }; List<string> extra = p.Parse(args); if (!u && f == null) p.WriteOptionDescriptions(Console.Out); byte[] block = null; if (!u) { using (var binReader = new BinaryReader( File.Open(f, FileMode.Open))) { block = binReader.ReadBytes((int)binReader.BaseStream.Length); } } else { UploadProgramBlock(port, baud, parity, address, out block); } var compiler = new Compiler(); string awlContent; compiler.DisassemblyBlock(block, out awlContent); using (var streamWriter = new StreamWriter(o, false)) { streamWriter.Write(awlContent); } }