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;
                    var image = program.Image;
                    var dasm = program.CreateDisassembler(StartAddress).GetEnumerator();
                    while (dasm.MoveNext())
                    {
                        var instr = dasm.Current;
                        if (lines <= 0)
                            break;
                        dumper.DumpAssemblerLine(image, instr, writer);
                        --lines;
                    }
                    txtDisassembly.Text = writer.ToString();
                }
            }
        }
Exemplo n.º 2
0
        private void RenderResult(Program prog, string outputFile)
        {
            foreach (var item in asm.ImportReferences)
            {
                prog.ImportReferences.Add(item.Key, item.Value);
            }

            using (FileUnitTester fut = new FileUnitTester(outputFile))
            {
                Dumper dumper = new Dumper(prog.Architecture);
                dumper.ShowAddresses = true;
                dumper.ShowCodeBytes = true;
                var mem = prog.SegmentMap.Segments.Values.First().MemoryArea;
                var formatter = new TextFormatter(fut.TextWriter);
                dumper.DumpData(prog.SegmentMap, mem.BaseAddress, mem.Bytes.Length, formatter);
                fut.TextWriter.WriteLine();
                dumper.DumpAssembler(prog.SegmentMap, mem.BaseAddress, mem.EndAddress, formatter);
                if (prog.ImportReferences.Count > 0)
                {
                    var list = new SortedList<Address, ImportReference>(prog.ImportReferences);
                    foreach (var de in list)
                    {
                        fut.TextWriter.WriteLine("{0}: {1}", de, de.Value);
                    }
                }
                fut.AssertFilesEqual();
            }
        }
Exemplo n.º 3
0
        protected void RunTest(string sourceFile, string outputFile, Address addrBase)
        {
            Program program;
            using (var rdr = new StreamReader(FileUnitTester.MapTestPath(sourceFile)))
            {
                program = asm.Assemble(addrBase, rdr);
            }
            foreach (var item in asm.ImportReferences)
            {
                program.ImportReferences.Add(item.Key, item.Value);
            }

            using (FileUnitTester fut = new FileUnitTester(outputFile))
            {
                Dumper dumper = new Dumper(program.Architecture);
                dumper.ShowAddresses = true;
                dumper.ShowCodeBytes = true;
                dumper.DumpData(program.Image, program.Image.BaseAddress, program.Image.Length, fut.TextWriter);
                fut.TextWriter.WriteLine();
                dumper.DumpAssembler(program.Image, program.Image.BaseAddress, program.Image.BaseAddress + (uint)program.Image.Length, fut.TextWriter);
                if (program.ImportReferences.Count > 0)
                {
                    foreach (var de in program.ImportReferences.OrderBy(d => d.Key))
                    {
                        fut.TextWriter.WriteLine("{0:X8}: {1}", de.Key, de.Value);
                    }
                }
                fut.AssertFilesEqual();
            }
        }
Exemplo n.º 4
0
        private void RunTest(string sourceFile, string outputFile)
        {
            Program program;
            using (var rdr = new StreamReader(FileUnitTester.MapTestPath(sourceFile)))
            {
                program = asm.Assemble(Address.SegPtr(0x0C00, 0), rdr);
            }
            using (FileUnitTester fut = new FileUnitTester(outputFile))
            {
                Dumper dump = new Dumper(asm.Architecture);
                dump.DumpData(program.Image, program.Image.BaseAddress, program.Image.Bytes.Length, fut.TextWriter);
                fut.TextWriter.WriteLine();
                dump.ShowAddresses = true;
                dump.ShowCodeBytes = true;
                dump.DumpAssembler(program.Image, program.Image.BaseAddress, program.Image.BaseAddress + program.Image.Bytes.Length, fut.TextWriter);

                fut.AssertFilesEqual();
            }
        }
Exemplo n.º 5
0
 public void AsFragment()
 {
     var program = asm.AssembleFragment(
         Address.SegPtr(0xC00, 0),
     @"		.i86
     hello	proc
     mov	ax,0x30
     mov	bx,0x40
     hello	endp
     ");
     LoadedImage img = program.Image;
     using (FileUnitTester fut = new FileUnitTester("Intel/AsFragment.txt"))
     {
         var arch = new IntelArchitecture(ProcessorMode.Real);
         var d = new Dumper(arch);
         d.DumpData(img, img.BaseAddress, img.Bytes.Length, fut.TextWriter);
         fut.AssertFilesEqual();
     }
 }
Exemplo n.º 6
0
 public void AsCarryInstructions()
 {
     Program program;
     using (var rdr = new StreamReader(FileUnitTester.MapTestPath("Fragments/carryinsts.asm")))
     {
         program = asm.Assemble(Address.SegPtr(0xBAC, 0), rdr);
     }
     using (FileUnitTester fut = new FileUnitTester("Intel/AsCarryInstructions.txt"))
     {
         Dumper dump = new Dumper(arch);
         dump.DumpData(program.Image, program.Image.BaseAddress, program.Image.Length, fut.TextWriter);
         fut.AssertFilesEqual();
     }
 }
Exemplo n.º 7
0
		public void X86Rw_CallTable()
		{
			DoRewriteFile("Fragments/multiple/calltables.asm");
			using (FileUnitTester fut = new FileUnitTester("Intel/RwCallTable.txt"))
			{
				Dumper dump = new Dumper(prog.Architecture);
				dump.Dump(prog, prog.ImageMap, fut.TextWriter);
				fut.TextWriter.WriteLine();
				prog.CallGraph.Write(fut.TextWriter);

				fut.AssertFilesEqual();
			}
		}
Exemplo n.º 8
0
 /// <summary>
 /// Copies the selected range of bytes into the clipboard.
 /// </summary>
 /// <returns></returns>
 private bool CopySelectionToClipboard()
 {
     AddressRange range;
     if (!TryGetSelectedAddressRange(out range))
         return true;
     if (control.MemoryView.Focused)
     {
          var decompiler = services.GetService<IDecompilerService>().Decompiler;
          var dumper = new Dumper(decompiler.Project.Programs.First().Architecture);
         var sb = new StringWriter();
         dumper.DumpData(control.MemoryView.ProgramImage, range, sb);
         Clipboard.SetText(sb.ToString());       //$TODO: abstract this.
     }
     return true;
 }
Exemplo n.º 9
0
 public void DumpAssembler(Program program, TextWriter wr)
 {
     if (wr == null || program.Architecture == null)
         return;
     Dumper dump = new Dumper(program.Architecture);
     dump.Dump(program, program.ImageMap, wr);
 }
Exemplo n.º 10
0
 public void DumpAssembler(Program program, Formatter wr)
 {
     if (wr == null || program.Architecture == null)
         return;
     Dumper dump = new Dumper(program.Architecture);
     dump.Dump(program, wr);
 }
Exemplo n.º 11
0
		private void RunTest(string sourceFile, string outputFile)
		{
            Program program;
            using (var rdr = new StreamReader(FileUnitTester.MapTestPath(sourceFile)))
            {
                program = asm.Assemble(Address.SegPtr(0x0C00, 0), rdr);
            }
			using (FileUnitTester fut = new FileUnitTester(outputFile))
			{
				Dumper dump = new Dumper(asm.Architecture);
                var mem = program.SegmentMap.Segments.Values.First().MemoryArea;
                var formatter = new TextFormatter(fut.TextWriter);
				dump.DumpData(program.SegmentMap, mem.BaseAddress, mem.Bytes.Length, formatter);
				fut.TextWriter.WriteLine();
				dump.ShowAddresses = true;
				dump.ShowCodeBytes = true;
				dump.DumpAssembler(program.SegmentMap, mem.BaseAddress, mem.EndAddress, formatter);

				fut.AssertFilesEqual();
			}	
		}
Exemplo n.º 12
0
		public void AsCarryInstructions()
		{
            Program program;
            using (var rdr = new StreamReader(FileUnitTester.MapTestPath("Fragments/carryinsts.asm")))
            {
			    program = asm.Assemble(Address.SegPtr(0xBAC, 0), rdr);
            }
			using (FileUnitTester fut = new FileUnitTester("Intel/AsCarryInstructions.txt"))
			{
				Dumper dump = new Dumper(arch);
                var mem = program.SegmentMap.Segments.Values.First().MemoryArea;
				dump.DumpData(program.SegmentMap, mem.BaseAddress, mem.Length, new TextFormatter(fut.TextWriter));
				fut.AssertFilesEqual();
			}
		}
Exemplo n.º 13
0
		public void AsFragment()
		{
			 AssembleFragment(
@"		.i86
hello	proc
		mov	ax,0x30
		mov	bx,0x40
hello	endp
");
            var segment = program.SegmentMap.Segments.Values.First();
			using (FileUnitTester fut = new FileUnitTester("Intel/AsFragment.txt"))
			{
				var arch = new X86ArchitectureReal();
				var d = new Dumper(arch);
				d.DumpData(program.SegmentMap, segment.Address, segment.ContentSize, new TextFormatter(fut.TextWriter));
				fut.AssertFilesEqual();
			}
		}
Exemplo n.º 14
0
        public void Dumper_Structure()
        {
            var str = new StructureType
            {
                Fields =
                {
                    { 0, PrimitiveType.Byte  },
                    { 2, PrimitiveType.Word16 },
                    { 8, PrimitiveType.Word32 }
                }
            };
            Given_32bit_Program();
            program.ImageMap.AddItemWithSize(
                Address.Ptr32(0x10004),
                new ImageMapItem
                {
                    Address = Address.Ptr32(0x10004),
                    DataType = str,
                    Size = 12,
                });
            mr.ReplayAll();

            var dmp = new Dumper(program.Architecture);

            var sw = new StringWriter();
            dmp.Dump(program, new TextFormatter(sw));

            string sExp =
            #region Expected
@";;; Segment .text (00010000)
00010000 00 01 02 03                                     ....           
l00010004		db	0x04
	db	0x05	; padding
	dw	0x0706
	db	0x08,0x09,0x0A,0x0B	; padding
	dd	0x0F0E0D0C
00010010 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F ................
";
            #endregion
            AssertOutput(sExp, sw);
            mr.VerifyAll();
        }
Exemplo n.º 15
0
        public void Dumper_Word32()
        {
            Given_32bit_Program();
            program.ImageMap.AddItemWithSize(
                Address.Ptr32(0x10004),
                new ImageMapItem
                {
                    Address = Address.Ptr32(0x10004),
                    DataType = PrimitiveType.Word32,
                    Size = 4,
                });
            mr.ReplayAll();

            var dmp = new Dumper(program.Architecture);

            var sw = new StringWriter();
            dmp.Dump(program, new TextFormatter(sw));

            string sExp =
            #region Expected
@";;; Segment .text (00010000)
00010000 00 01 02 03                                     ....           
l00010004	dd	0x07060504
00010008                         08 09 0A 0B 0C 0D 0E 0F         ........
00010010 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F ................
";
            #endregion
            AssertOutput(sExp, sw);
            mr.VerifyAll();
        }
Exemplo n.º 16
0
        public void Dumper_NamedProc()
        {
            Given_32bit_Program();
            var proc = Given_ProcedureAt(Address.Ptr32(0x10010));
            proc.Name = "__foo@8";
            mr.ReplayAll();

            var dmp = new Dumper(program.Architecture);

            var sw = new StringWriter();
            dmp.Dump(program, new TextFormatter(sw));

            string sExp =
            #region Expected
@";;; Segment .text (00010000)
00010000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ................

;; __foo@8: 00010010
__foo@8 proc
	add
	mul
	add
	ret
00010018                         18 19 1A 1B 1C 1D 1E 1F         ........
";
            #endregion
            AssertOutput(sExp, sw);
            mr.VerifyAll();
        }