protected Program RewriteProgram32(string sourceFilename, Address addrBase) { var sc = new ServiceContainer(); sc.AddService <IConfigurationService>(new FakeDecompilerConfiguration()); var ldr = new Loader(sc); var arch = new X86ArchitectureFlat32(); program = ldr.AssembleExecutable( FileUnitTester.MapTestPath(sourceFilename), new X86TextAssembler(arch) { Platform = new DefaultPlatform(null, arch) }, addrBase); return(RewriteProgram()); }
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 arch = program.Architecture; var mem = program.SegmentMap.Segments.Values.First().MemoryArea; dump.DumpData(program.SegmentMap, arch, mem.BaseAddress, mem.Length, new TextFormatter(fut.TextWriter)); fut.AssertFilesEqual(); } }
public void SsigReadAxBxCl() { SerializedSignature ssig; var fsSvc = sc.RequireService <IFileSystemService>(); using (Stream stm = fsSvc.CreateFileStream( FileUnitTester.MapTestPath("Core/AxBxCl.xml"), FileMode.Open, FileAccess.Read)) { XmlTextReader rdr = new XmlTextReader(stm); XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(typeof(SerializedSignature)); ssig = (SerializedSignature)ser.Deserialize(rdr); } Given_X86ProcedureSerializer(); Assert.AreEqual("Register word16 AxBxCl(Register word16 bx, Register byte cl)", sser.Deserialize(ssig, arch.CreateFrame()).ToString("AxBxCl")); }
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 Project LoadProject() { Project project = null; if (configFile != null) { var absFile = FileUnitTester.MapTestPath(configFile); using (Stream stm = new FileStream(absFile, FileMode.Open, FileAccess.Read, FileShare.Read)) { project = new ProjectLoader(new Loader(new ServiceContainer())).LoadProject(stm); } } else { project = new Project(); } return(project); }
public void SlibReadOneProcedure() { XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(typeof(SerializedLibrary)); SerializedLibrary lib; using (Stream stm = fsSvc.CreateFileStream( FileUnitTester.MapTestPath("Core/SlibOneProcedure.xml"), FileMode.Open, FileAccess.Read)) { lib = (SerializedLibrary)ser.Deserialize(stm); } Assert.AreEqual(1, lib.Procedures.Count); Procedure_v1 proc = (Procedure_v1)lib.Procedures[0]; Assert.AreEqual("malloc", proc.Name); Assert.AreEqual(1, proc.Signature.Arguments.Length); Assert.AreEqual("int", proc.Signature.Arguments[0].Type.ToString()); }
private Project LoadProject() { Project project = null; if (configFile != null) { var absFile = FileUnitTester.MapTestPath(configFile); var fsSvc = sc.RequireService <IFileSystemService>(); using (Stream stm = fsSvc.CreateFileStream(absFile, FileMode.Open, FileAccess.Read, FileShare.Read)) { project = new ProjectLoader(null, new Loader(sc)).LoadProject(absFile, stm); } } else { project = new Project(); } return(project); }
private Program AssembleFile(string sourceFile, Address addr) { var ldr = new Loader(new ServiceContainer()); var arch = new X86ArchitectureReal(); Program program = ldr.AssembleExecutable( FileUnitTester.MapTestPath(sourceFile), new X86TextAssembler(arch), addr); var project = new Project { Programs = { program } }; var scan = new Scanner(program, new Dictionary <Address, ProcedureSignature>(), new ImportResolver(project), null); foreach (EntryPoint ep in program.EntryPoints) { scan.EnqueueEntryPoint(ep); } scan.ScanImage(); return(program); }
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(); } }
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; }
protected Program RewriteFile( string relativePath, Address addrBase, Func <IServiceProvider, IProcessorArchitecture, IPlatform> mkPlatform) { sc = new ServiceContainer(); var config = new FakeDecompilerConfiguration(); var eventListener = new FakeDecompilerEventListener(); sc.AddService <IConfigurationService>(config); sc.AddService <IDecompiledFileService>(new FakeDecompiledFileService()); sc.AddService <DecompilerEventListener>(eventListener); sc.AddService <IFileSystemService>(new FileSystemServiceImpl()); var arch = new X86ArchitectureReal(sc, "x86-real-16"); ILoader ldr = new Loader(sc); var program = ldr.AssembleExecutable( FileUnitTester.MapTestPath(relativePath), new X86TextAssembler(arch), null, addrBase); program.Platform = mkPlatform(sc, program.Architecture); var ep = ImageSymbol.Procedure(arch, program.SegmentMap.BaseAddress); var project = new Project { Programs = { program } }; var scan = new Scanner( program, new DynamicLinker(project, program, eventListener), sc); scan.EnqueueImageSymbol(ep, true); scan.ScanImage(); var dynamicLinker = new DynamicLinker(project, program, eventListener); var dfa = new DataFlowAnalysis(program, dynamicLinker, eventListener); dfa.AnalyzeProgram(); 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; 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(); } }
private Program AssembleFile(string sourceFile, Address addr) { var ldr = new Loader(new ServiceContainer()); var arch = new X86ArchitectureReal("x86-real-16"); Program program = ldr.AssembleExecutable( FileUnitTester.MapTestPath(sourceFile), new X86TextAssembler(sc, arch), addr); var project = new Project { Programs = { program } }; var scan = new Scanner( program, new ImportResolver(project, program, null), null); foreach (ImageSymbol ep in program.EntryPoints.Values) { scan.EnqueueImageSymbol(ep, true); } scan.ScanImage(); return(program); }
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 Project LoadProject() { Project project = null; if (configFile != null) { var absFile = FileUnitTester.MapTestPath(configFile); var fsSvc = sc.RequireService <IFileSystemService>(); using Stream stm = fsSvc.CreateFileStream(absFile, FileMode.Open, FileAccess.Read, FileShare.Read); project = new ProjectLoader( null, new Loader(sc), ImageLocation.FromUri(absFile), new FakeDecompilerEventListener()) .LoadProject(stm); } else { project = new Project(); } return(project); }
protected Program RewriteMsdosAssembler(string relativePath, Action <Program> postLoad) { var arch = new X86ArchitectureReal(sc, "x86-real-16"); 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 <IConfigurationService>(cfgSvc.Object); sc.AddService <ITypeLibraryLoaderService>(tlSvc.Object); Program program; IAssembler asm = new X86TextAssembler(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, postLoad); return(program); }
private Program AssembleFile(string sourceFile, Address addr) { var ldr = new Loader(sc); var arch = new X86ArchitectureReal(sc, "x86-real-16", new Dictionary <string, object>()); Program program = ldr.AssembleExecutable( FileUnitTester.MapTestPath(sourceFile), new X86TextAssembler(arch), new DefaultPlatform(sc, arch), addr); var project = new Project { Programs = { program } }; var scan = new Scanner( program, new DynamicLinker(project, program, null), null); foreach (ImageSymbol ep in program.EntryPoints.Values) { scan.EnqueueImageSymbol(ep, true); } scan.ScanImage(); return(program); }
protected Program RewriteFile( string relativePath, Address addrBase, Func <IServiceProvider, IProcessorArchitecture, IPlatform> mkPlatform) { var sc = new ServiceContainer(); PopulateServiceContainer(sc); var arch = new X86ArchitectureReal(sc, "x86-real-16", new Dictionary <string, object>()); ILoader ldr = new Loader(sc); var program = ldr.AssembleExecutable( ImageLocation.FromUri(FileUnitTester.MapTestPath(relativePath)), new X86TextAssembler(arch), null, addrBase); program.Platform = mkPlatform(sc, program.Architecture); var ep = ImageSymbol.Procedure(arch, program.SegmentMap.BaseAddress); var project = new Project { Programs = { program } }; var scan = new Scanner( program, project.LoadedMetadata, new DynamicLinker(project, program, eventListener), sc); scan.EnqueueImageSymbol(ep, true); scan.ScanImage(); var dynamicLinker = new DynamicLinker(project, program, eventListener); var dfa = new DataFlowAnalysis(program, dynamicLinker, sc); dfa.AnalyzeProgram(); return(program); }
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(); } }
protected void RunHexTest(string hexFile, string outputFile) { var svc = new ServiceContainer(); var cfg = new FakeDecompilerConfiguration(); svc.AddService <IConfigurationService>(cfg); ILoader ldr = new Loader(svc); var imgLoader = new DchexLoader(FileUnitTester.MapTestPath(hexFile), svc, null); var img = imgLoader.Load(null); var program = new Program(img.Image, img.Image.CreateImageMap(), img.Architecture, img.Platform); var project = new Project { Programs = { program } }; var ep = new EntryPoint(program.Image.BaseAddress, program.Architecture.CreateProcessorState()); var scan = new Scanner(program, new Dictionary <Address, ProcedureSignature>(), new ImportResolver(project), new FakeDecompilerEventListener()); scan.EnqueueEntryPoint(ep); scan.ScanImage(); var dfa = new DataFlowAnalysis(program, new FakeDecompilerEventListener()); dfa.AnalyzeProgram(); RunTest(program, outputFile); }