Esempio n. 1
0
 /// <summary>
 /// Shut down the native disassembler interface.
 /// </summary>
 public void Dispose()
 {
     if (_disasm != IntPtr.Zero)
     {
         CoreDisTools.FinishDisasm(_disasm);
     }
 }
Esempio n. 2
0
        private int Run(string[] args)
        {
            ArgumentSyntax syntax = ParseCommandLine(args);

            if (_help)
            {
                _writer.WriteLine(syntax.GetHelpText());
                return(0);
            }

            if (_inputFilenames.Count == 0)
            {
                throw new ArgumentException("Input filename must be specified (--in <file>)");
            }

            // open output stream
            if (_outputFilename != null)
            {
                _writer = File.CreateText(_outputFilename);
            }
            else
            {
                _writer = Console.Out;
            }

            try
            {
                foreach (string filename in _inputFilenames)
                {
                    R2RReader r2r = new R2RReader(filename);
                    if (_disasm)
                    {
                        _disassembler = CoreDisTools.GetDisasm(r2r.Machine);
                    }

                    Dump(r2r);

                    if (_disasm)
                    {
                        CoreDisTools.FinishDisasm(_disassembler);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.ToString());
                return(1);
            }
            finally
            {
                // close output stream
                _writer.Close();
            }

            return(0);
        }
Esempio n. 3
0
        private int Run(string[] args)
        {
            ArgumentSyntax syntax = ParseCommandLine(args);

            // open output stream
            if (_outputFilename != null)
            {
                _writer = File.CreateText(_outputFilename);
            }
            else
            {
                _writer = Console.Out;
            }

            if (_help)
            {
                _writer.WriteLine(syntax.GetHelpText());
                return(0);
            }

            try
            {
                if (_inputFilenames.Count == 0)
                {
                    throw new ArgumentException("Input filename must be specified (--in <file>)");
                }

                foreach (string filename in _inputFilenames)
                {
                    R2RReader r2r = new R2RReader(filename);

                    if (_disasm)
                    {
                        _disassembler = CoreDisTools.GetDisasm(r2r.Machine);
                    }

                    if (_xml)
                    {
                        _dumper = new XmlDumper(_ignoreSensitive, r2r, _writer, _raw, _header, _disasm, _disassembler, _unwind, _gc, _sectionContents);
                    }
                    else
                    {
                        _dumper = new TextDumper(r2r, _writer, _raw, _header, _disasm, _disassembler, _unwind, _gc, _sectionContents);
                    }

                    Dump(r2r);

                    if (_disasm)
                    {
                        CoreDisTools.FinishDisasm(_disassembler);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.ToString());
                if (e is ArgumentException)
                {
                    Console.WriteLine();
                    Console.WriteLine(syntax.GetHelpText());
                }
                if (_xml)
                {
                    XmlDocument document = new XmlDocument();
                    XmlNode     node     = document.CreateNode("element", "Error", "");
                    node.InnerText = e.Message;
                    document.AppendChild(node);
                    if (_writer != null)
                    {
                        document.Save(_writer);
                    }
                }
                return(1);
            }
            finally
            {
                // close output stream
                _writer.Close();
            }

            return(0);
        }