Exemplo n.º 1
0
        private void RenderResult(Program program, string outputFile)
        {
            foreach (var item in asm.ImportReferences)
            {
                program.ImportReferences.Add(item.Key, item.Value);
            }

            using (FileUnitTester fut = new FileUnitTester(outputFile))
            {
                Dumper dumper = new Dumper(program);
                dumper.ShowAddresses = true;
                dumper.ShowCodeBytes = true;
                var mem       = program.SegmentMap.Segments.Values.First().MemoryArea;
                var formatter = new TextFormatter(fut.TextWriter);
                dumper.DumpData(program.SegmentMap, program.Architecture, mem.BaseAddress, mem.Bytes.Length, formatter);
                fut.TextWriter.WriteLine();
                dumper.DumpAssembler(program.SegmentMap, program.Architecture, mem.BaseAddress, mem.EndAddress, formatter);
                if (program.ImportReferences.Count > 0)
                {
                    var list = new SortedList <Address, ImportReference>(program.ImportReferences);
                    foreach (var de in list)
                    {
                        fut.TextWriter.WriteLine("{0}: {1}", de, de.Value);
                    }
                }
                fut.AssertFilesEqual();
            }
        }
Exemplo n.º 2
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.º 3
0
        public void Dumper_AlmostFullSpan()
        {
            Given_32bit_Program_Zeros(110);
            arch.Setup(a => a.CreateImageReader(
                           It.IsAny <ByteMemoryArea>(),
                           It.IsAny <Address>(),
                           It.IsAny <long>()))
            .Returns(
                (ByteMemoryArea m, Address a, long b) => new LeImageReader(m, a, b));

            var dmp = new Dumper(program);
            var sw  = new StringWriter();

            dmp.DumpData(
                program.SegmentMap,
                program.Architecture,
                program.ImageMap.BaseAddress + 1,
                14,
                new TextFormatter(sw));

            var sExp =
                #region Expected
                @"00010001    00 00 00 00 00 00 00 00 00 00 00 00 00 00     .............. 
";

            #endregion
            AssertOutput(sExp, sw);
        }
Exemplo n.º 4
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;
                dumper.DumpData(prog.Image, prog.Image.BaseAddress, prog.Image.Bytes.Length, fut.TextWriter);
                fut.TextWriter.WriteLine();
                dumper.DumpAssembler(prog.Image, prog.Image.BaseAddress, prog.Image.BaseAddress + prog.Image.Bytes.Length, fut.TextWriter);
                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.º 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();
            }
        }
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(program);
                var    mem  = program.SegmentMap.Segments.Values.First().MemoryArea;
                dump.DumpData(program.SegmentMap, mem.BaseAddress, mem.Length, new TextFormatter(fut.TextWriter));
                fut.AssertFilesEqual();
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 8
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(sc, "x86-real-16");
                var d    = new Dumper(program);
                d.DumpData(program.SegmentMap, arch, segment.Address, segment.ContentSize, new TextFormatter(fut.TextWriter));
                fut.AssertFilesEqual();
            }
        }
Exemplo n.º 9
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.º 10
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.º 11
0
 /// <summary>
 /// Copies the selected range of bytes into the clipboard.
 /// </summary>
 /// <returns></returns>
 private bool CopySelectionToClipboard()
 {
     if (!TryGetSelectedAddressRange(out var range))
     {
         return(true);
     }
     if (control.MemoryView.Focused)
     {
         var decompiler = services.GetService <IDecompilerService>().Decompiler;
         var dumper     = new Dumper(decompiler.Project.Programs.First());
         var sb         = new StringWriter();
         dumper.DumpData(control.MemoryView.SegmentMap, program.Architecture, range, new TextFormatter(sb));
         var text = sb.ToString();
         if (text.Length > 0)
         {
             Clipboard.SetText(text);       //$TODO: abstract this.
         }
     }
     return(true);
 }
Exemplo n.º 12
0
        public void Dumper_Word16_Units()
        {
            program = new Program();
            var arch = new Mock <IProcessorArchitecture>();

            arch.Setup(a => a.CreateImageReader(
                           It.IsAny <ByteMemoryArea>(),
                           It.IsAny <Address>(),
                           It.IsAny <long>()))
            .Returns(
                (ByteMemoryArea m, Address a, long b) => new LeImageReader(m, a, b));

            var mem = new ByteMemoryArea(Address.Ptr32(0x0001_0000), new byte[]
            {
                0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
                0x07, 0x08, 0xFF, 0xFF, 0x48, 0x69, 0x42, 0x49,
                0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
                0x07, 0x08, 0xFF, 0xFF, 0x48, 0x69, 0x42, 0x41
            });

            mem.Formatter = new MemoryFormatter(PrimitiveType.Word16, 16, 1);
            var dmp = new Dumper(program);
            var sw  = new StringWriter();

            dmp.DumpData(
                arch.Object,
                mem,
                mem.BaseAddress + 2,
                0x2C,
                new TextFormatter(sw));

            var sExp =
                #region Expected
                @"00010002      0201 0403 0605 0807 FFFF 6948 4942   ..........HiBI
00010010 0000 0201 0403 0605 0807 FFFF 6948 4142 ............HiBA
";

            #endregion
            AssertOutput(sExp, sw);
        }
Exemplo n.º 13
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(program);
                var    bmem      = (ByteMemoryArea)program.SegmentMap.Segments.Values.First().MemoryArea;
                var    formatter = new TextFormatter(fut.TextWriter);
                dump.DumpData(program.SegmentMap, program.Architecture, bmem.BaseAddress, bmem.Bytes.Length, formatter);
                fut.TextWriter.WriteLine();
                dump.ShowAddresses = true;
                dump.ShowCodeBytes = true;
                dump.DumpAssembler(program.SegmentMap, program.Architecture, bmem.BaseAddress, bmem.EndAddress, formatter);

                fut.AssertFilesEqual();
            }
        }
Exemplo n.º 14
0
        public void Dumper_Word16MemoryArea()
        {
            program = new Program();
            var arch = new Mock <IProcessorArchitecture>();

            arch.Setup(a => a.CreateImageReader(
                           It.IsAny <MemoryArea>(),
                           It.IsAny <Address>(),
                           It.IsAny <long>()))
            .Returns(
                (MemoryArea m, Address a, long b) => m.CreateBeReader(a, b));

            var mem = new Word16MemoryArea(Address.Ptr16(0x1000), new ushort[]
            {
                0x0000, 0x0102, 0x0304, 0x0506,
                0x0708, 0xFFFF, 0x4869, 0x4249,
                0x0000, 0x0102, 0x0304, 0x0506,
                0x0708, 0xFFFF, 0x4869, 0x4241
            });
            var dmp = new Dumper(program);
            var sw  = new StringWriter();

            dmp.DumpData(
                arch.Object,
                mem,
                mem.BaseAddress + 1,
                0x0D,
                new TextFormatter(sw));

            var sExp =
                #region Expected
                @"1001      0102 0304 0506 0708 FFFF 4869 4249   ..........HiBI
1008 0000 0102 0304 0506 0708 FFFF           ............    
";

            #endregion
            AssertOutput(sExp, sw);
        }
Exemplo n.º 15
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);
                dumper.ShowAddresses = true;
                dumper.ShowCodeBytes = true;
                foreach (var segment in program.SegmentMap.Segments.Values)
                {
                    var bmem      = (ByteMemoryArea)segment.MemoryArea;
                    var formatter = new TextFormatter(fut.TextWriter);
                    dumper.DumpData(program.SegmentMap, program.Architecture, bmem.BaseAddress, bmem.Length, formatter);
                    fut.TextWriter.WriteLine();
                    dumper.DumpAssembler(program.SegmentMap, program.Architecture, bmem.BaseAddress, bmem.EndAddress, formatter);
                    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();
            }
        }