Exemple #1
0
        /// <summary>
        /// Task for disassembling one individual file.
        /// </summary>
        /// <param name="logger">The logging implementation to log errors/info to.</param>
        /// <param name="options">The options to use while disassembling.</param>
        /// <returns>True if the disassembler could successfully disassemble the file; otherwise returns false.</returns>
        public bool DisassembleFile(ILogger logger, DisassemblerOptions options)
        {
            bool success = true;

            logger.Log(LogLevel.Info, "Invoking disassembler for file " + options.InputFileName);
            try
            {
                ICompiledFileReader  fileParser = m_FileParserFac.GetFileParser(options.InputFileName);
                DisassembledFileBase fileBase   = fileParser.ParseFile(options.InputFileName, logger);
                IAssemblyFileWriter  fileWriter = fileBase.AssemblyTextFileWriter;
                fileWriter.GenerateOutputFile(options.OutputFileName);
            }
            catch (IOException ex)
            {
                logger.Log(LogLevel.Critical, ex.Message);
                success = false;
            }
            catch (Exception ex)
            {
                logger.Log(LogLevel.Critical, "In file " + options.InputFileName + ":");
                logger.Log(LogLevel.Critical, ex.Message);
                success = false;
            }

            return(success);
        }
Exemple #2
0
        private string DisassembleToTemporaryFile(string inputFileName, ILogger logger)
        {
            string outputFileName = Path.GetTempFileName();

            logger.Log(LogLevel.Info, "Invoking disassembler for file " + inputFileName);
            try
            {
                ICompiledFileReader  fileParser = m_FileParserFac.GetFileParser(inputFileName);
                DisassembledFileBase fileBase   = fileParser.ParseFile(inputFileName, logger);
                IAssemblyFileWriter  fileWriter = fileBase.AssemblyTextFileWriter;
                fileWriter.GenerateOutputFile(outputFileName);
            }
            catch (IOException ex)
            {
                logger.Log(LogLevel.Critical, ex.Message);
                throw;
            }
            catch (Exception ex)
            {
                logger.Log(LogLevel.Critical, "In file " + inputFileName + ":");
                logger.Log(LogLevel.Critical, ex.Message);
                throw;
            }

            return(outputFileName);
        }
        public ConsoleSimulation(string inputFileName, CommandInterpreter interpreter)
        {
            m_Terminal       = new ConsoleEmulator(interpreter);
            m_Logger         = new ConsoleLogger();
            m_TerminationMgr = new TerminationManager(inputFileName);

            var fileParserFac = new FileReaderFactory();
            ICompiledFileReader  fileParser = fileParserFac.GetFileParser(inputFileName);
            DisassembledFileBase file       = fileParser.ParseFile(inputFileName, m_Logger);

            m_Terminal.PrintString("Successfully loaded " + inputFileName +
                                   " (source file: " + file.SourceInformation.SourceFilePath + "; " + file.TotalFileSize + " bytes)\n");

            m_ExecCtx = new RuntimeProcess(file, m_Terminal);

            IEnumerable <InstructionData> programInstructions =
                DisassemblerServices.GenerateInstructionData(file.SymbolTable, file.TextSegment, file.SourceInformation);

            m_SrcMapping = new Dictionary <int, SourceLineInformation>();

            foreach (InstructionData instructionElem in programInstructions)
            {
                m_SrcMapping.Add(instructionElem.ProgramCounterLocation, new SourceLineInformation(instructionElem));
            }

            m_CmdTable = new CommandTable(m_SrcMapping, m_ExecCtx, m_Terminal, m_TerminationMgr);

            m_Terminal.AddAvailableCommands(m_CmdTable.AllCommands);
        }