예제 #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;
                    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();
                }
            }
        }
예제 #2
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();
			}
		}
예제 #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();
			}
		}
예제 #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();
			}	
		}
예제 #5
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();
			}
		}
예제 #6
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();
			}
		}
예제 #7
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;
 }