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(); } }
private void RunFileTestx86_32(string relativePath, string outputFile) { Program program; var sc = new ServiceContainer(); var fsSvc = new FileSystemServiceImpl(); var el = new FakeDecompilerEventListener(); sc.AddService <IFileSystemService>(fsSvc); sc.AddService <DecompilerEventListener>(el); var arch = new X86ArchitectureFlat32("x86-protected-32"); var asm = new X86TextAssembler(sc, arch); using (var rdr = new StreamReader(FileUnitTester.MapTestPath(relativePath))) { var platform = new DefaultPlatform(sc, arch); asm.Platform = platform; program = asm.Assemble(Address.Ptr32(0x10000000), rdr); } var scanner = new Scanner(program, null, sc); scanner.EnqueueImageSymbol(ImageSymbol.Procedure(program.Architecture, program.ImageMap.BaseAddress), true); scanner.ScanImage(); using (var fut = new FileUnitTester(outputFile)) { foreach (var proc in program.Procedures.Values) { proc.Write(false, fut.TextWriter); } fut.AssertFilesEqual(); } }
protected static Program RewriteMsdosAssembler(string relativePath, string configFile) { var arch = new X86ArchitectureReal(); var sc = new ServiceContainer(); var cfgSvc = MockRepository.GenerateStub <IConfigurationService>(); var env = MockRepository.GenerateStub <OperatingEnvironment>(); var tlSvc = MockRepository.GenerateStub <ITypeLibraryLoaderService>(); cfgSvc.Stub(c => c.GetEnvironment("ms-dos")).Return(env); cfgSvc.Replay(); env.Stub(e => e.TypeLibraries).Return(new List <ITypeLibraryElement>()); env.Stub(e => e.CharacteristicsLibraries).Return(new List <ITypeLibraryElement>()); env.Replay(); tlSvc.Replay(); sc.AddService <IFileSystemService>(new FileSystemServiceImpl()); sc.AddService <IConfigurationService>(cfgSvc); sc.AddService <ITypeLibraryLoaderService>(tlSvc); Program program; Assembler asm = new X86TextAssembler(sc, arch); using (var rdr = new StreamReader(FileUnitTester.MapTestPath(relativePath))) { program = asm.Assemble(Address.SegPtr(0xC00, 0), rdr); program.Platform = new MsdosPlatform(sc, arch); } Rewrite(program, asm, configFile); return(program); }
protected static Program RewriteMsdosAssembler(string relativePath, Action <Program> postLoad) { var arch = new X86ArchitectureReal("x86-real-16"); var sc = new ServiceContainer(); var cfgSvc = new Mock <IConfigurationService>(); var env = new Mock <PlatformDefinition>(); var tlSvc = new Mock <ITypeLibraryLoaderService>(); cfgSvc.Setup(c => c.GetEnvironment("ms-dos")).Returns(env.Object); env.Setup(e => e.TypeLibraries).Returns(new List <TypeLibraryDefinition>()); env.Setup(e => e.CharacteristicsLibraries).Returns(new List <TypeLibraryDefinition>()); sc.AddService <IFileSystemService>(new FileSystemServiceImpl()); sc.AddService <IConfigurationService>(cfgSvc.Object); sc.AddService <ITypeLibraryLoaderService>(tlSvc.Object); Program program; Assembler asm = new X86TextAssembler(sc, arch); using (var rdr = new StreamReader(FileUnitTester.MapTestPath(relativePath))) { program = asm.Assemble(Address.SegPtr(0xC00, 0), rdr); program.Platform = new MsdosPlatform(sc, program.Architecture); } Rewrite(program, asm, postLoad); return(program); }
protected static Program RewriteMsdosAssembler(string relativePath, string configFile) { var arch = new IntelArchitecture(ProcessorMode.Real); Program program; Assembler asm = new X86TextAssembler(arch); using (var rdr = new StreamReader(FileUnitTester.MapTestPath(relativePath))) { program = asm.Assemble(Address.SegPtr(0xC00, 0), rdr); program.Platform = new MsdosPlatform(null, arch); } Rewrite(program, asm, configFile); return(program); }
public void DisFpuInstructions() { using (FileUnitTester fut = new FileUnitTester("Intel/DisFpuInstructions.txt")) { X86TextAssembler asm = new X86TextAssembler(sc, new X86ArchitectureReal()); Program lr; using (var rdr = new StreamReader(FileUnitTester.MapTestPath("Fragments/fpuops.asm"))) { lr = asm.Assemble(Address.SegPtr(0xC32, 0), rdr); } CreateDisassembler16(lr.ImageMap.Segments.Values.First().MemoryArea); foreach (X86Instruction instr in dasm) { fut.TextWriter.WriteLine("{0}", instr.ToString()); } fut.AssertFilesEqual(); } }
private Program RewriteFile32(string relativePath, string configFile) { Program program; var asm = new X86TextAssembler(sc, new X86ArchitectureReal()); using (var rdr = new StreamReader(FileUnitTester.MapTestPath(relativePath))) { if (this.platform == null) { this.platform = new Reko.Environments.Windows.Win32Platform(sc, new X86ArchitectureFlat32()); } asm.Platform = this.platform; program = asm.Assemble(Address.Ptr32(0x10000000), rdr); } foreach (var item in asm.ImportReferences) { program.ImportReferences.Add(item.Key, item.Value); } Rewrite(program, asm, configFile); return program; }
private void RunTest(string sourceFile, string outputFile) { Program program; var asm = new X86TextAssembler(new X86ArchitectureFlat32(services, "x86-protected-32", new Dictionary <string, object>())); using (StreamReader rdr = new StreamReader(FileUnitTester.MapTestPath(sourceFile))) { program = asm.Assemble(Address.Ptr32(0x10000000), rdr); program.Platform = new Win32Platform(services, program.Architecture); program.User.Heuristics.Add("shingle"); } foreach (var item in asm.ImportReferences) { program.ImportReferences.Add(item.Key, item.Value); } var project = new Project { Programs = { program } }; Scanner scan = new Scanner( program, project.LoadedMetadata, new DynamicLinker(project, program, eventListener), services); foreach (var ep in asm.EntryPoints) { scan.EnqueueImageSymbol(ep, true); } scan.ScanImage(); using (FileUnitTester fut = new FileUnitTester(outputFile)) { foreach (Procedure proc in program.Procedures.Values) { proc.Write(true, fut.TextWriter); fut.TextWriter.WriteLine(); } fut.AssertFilesEqual(); } }
private void RunTest(string sourceFile, string outputFile) { Program program; var asm = new X86TextAssembler(new X86ArchitectureFlat32()); using (StreamReader rdr = new StreamReader(FileUnitTester.MapTestPath(sourceFile))) { program = asm.Assemble(Address.Ptr32(0x10000000), rdr); program.Platform = win32; } foreach (var item in asm.ImportReferences) { program.ImportReferences.Add(item.Key, item.Value); } var project = new Project { Programs = { program } }; Scanner scan = new Scanner( program, new Dictionary <Address, ProcedureSignature>(), new ImportResolver(project), new FakeDecompilerEventListener()); foreach (var ep in asm.EntryPoints) { scan.EnqueueEntryPoint(ep); } scan.ScanImage(); using (FileUnitTester fut = new FileUnitTester(outputFile)) { foreach (Procedure proc in program.Procedures.Values) { proc.Write(true, fut.TextWriter); fut.TextWriter.WriteLine(); } fut.AssertFilesEqual(); } }
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(); } }
public void DisFpuInstructions() { using (FileUnitTester fut = new FileUnitTester("Intel/DisFpuInstructions.txt")) { X86TextAssembler asm = new X86TextAssembler(new X86ArchitectureReal()); Program lr; using (var rdr = new StreamReader(FileUnitTester.MapTestPath("Fragments/fpuops.asm"))) { lr = asm.Assemble(Address.SegPtr(0xC32, 0), rdr); } CreateDisassembler16(lr.Image); foreach (IntelInstruction instr in dasm) { fut.TextWriter.WriteLine("{0}", instr.ToString()); } fut.AssertFilesEqual(); } }
private void RunTest(string sourceFile, string outputFile) { Program program; var asm = new X86TextAssembler(new X86ArchitectureFlat32()); using (StreamReader rdr = new StreamReader(FileUnitTester.MapTestPath(sourceFile))) { program = asm.Assemble(Address.Ptr32(0x10000000), rdr); program.Platform = win32; } foreach (var item in asm.ImportReferences) { program.ImportReferences.Add(item.Key, item.Value); } var project = new Project { Programs = { program } }; Scanner scan = new Scanner( program, new Dictionary<Address, ProcedureSignature>(), new ImportResolver(project), new FakeDecompilerEventListener()); foreach (var ep in asm.EntryPoints) { scan.EnqueueEntryPoint(ep); } scan.ScanImage(); using (FileUnitTester fut = new FileUnitTester(outputFile)) { foreach (Procedure proc in program.Procedures.Values) { proc.Write(true, fut.TextWriter); fut.TextWriter.WriteLine(); } fut.AssertFilesEqual(); } }
private Program RewriteFile32(string relativePath, string configFile) { Program program; var asm = new X86TextAssembler(new X86ArchitectureReal()); using (var rdr = new StreamReader(FileUnitTester.MapTestPath(relativePath))) { if (this.platform == null) { this.platform = new Decompiler.Environments.Win32.Win32Platform(null, new X86ArchitectureFlat32()); } asm.Platform = this.platform; program = asm.Assemble(Address.Ptr32(0x10000000), rdr); } foreach (var item in asm.ImportReferences) { program.ImportReferences.Add(item.Key, item.Value); } Rewrite(program, asm, configFile); return program; }
protected static Program RewriteMsdosAssembler(string relativePath, string configFile) { var arch = new IntelArchitecture(ProcessorMode.Real); Program program; Assembler asm = new X86TextAssembler(arch); using (var rdr = new StreamReader(FileUnitTester.MapTestPath(relativePath))) { program = asm.Assemble(Address.SegPtr(0xC00, 0), rdr); program.Platform = new MsdosPlatform(null, arch); } Rewrite(program, asm, configFile); return program; }