Example #1
0
        public void DumpAssembler()
        {
            var decSvc = sp.GetService <IDecompilerService>();

            if (decSvc == null)
            {
                throw new InvalidOperationException("Expected IDecompilerService to be available.");
            }

            if (!IsProgramLoaded(program))
            {
                txtDisassembly.Text = "";
            }
            else
            {
                int lines = CountVisibleLines();
                if (lines < 1)
                {
                    lines = 1;
                }
                using (var writer = new StringWriter())
                {
                    var arch   = program.Architecture;
                    var dumper = new Dumper(arch);
                    dumper.ShowAddresses = true;
                    dumper.ShowCodeBytes = true;
                    ImageSegment segment;
                    if (program.SegmentMap.TryFindSegment(StartAddress, out segment))
                    {
                        var formatter = new Dumper.InstrWriter(new TextFormatter(writer));
                        var dasm      = program.CreateDisassembler(StartAddress).GetEnumerator();
                        while (dasm.MoveNext())
                        {
                            var instr = dasm.Current;
                            if (lines <= 0)
                            {
                                break;
                            }
                            dumper.DumpAssemblerLine(segment.MemoryArea, instr, formatter);
                            --lines;
                        }
                    }
                    txtDisassembly.Text = writer.ToString();
                }
            }
        }