Esempio n. 1
0
 public void Setup()
 {
     mr = new MockRepository();
     this.services = mr.Stub<IServiceProvider>();
     var tlSvc = new TypeLibraryLoaderServiceImpl(services);
     var configSvc = mr.StrictMock<IConfigurationService>();
     var win32env = new OperatingEnvironmentElement
     {
         TypeLibraries = 
         {
             new TypeLibraryElement {  Name= "msvcrt.xml" },
             new TypeLibraryElement {  Name= "windows32.xml" },
         }
     };
     configSvc.Stub(c => c.GetEnvironment("win32")).Return(win32env);
     configSvc.Stub(c => c.GetInstallationRelativePath(null)).IgnoreArguments()
         .Do(new Func<string[], string>(s => string.Join("/", s)));
     services.Stub(s => s.GetService(typeof(ITypeLibraryLoaderService))).Return(tlSvc);
     services.Stub(s => s.GetService(typeof(IConfigurationService))).Return(configSvc);
     services.Stub(s => s.GetService(typeof(DecompilerEventListener))).Return(new FakeDecompilerEventListener());
     services.Stub(s => s.GetService(typeof(CancellationTokenSource))).Return(null);
     services.Stub(s => s.GetService(typeof(IFileSystemService))).Return(new FileSystemServiceImpl());
     services.Stub(s => s.GetService(typeof(IDiagnosticsService))).Return(new FakeDiagnosticsService());
     services.Replay();
     configSvc.Replay();
     arch = new X86ArchitectureFlat32();
     win32 = new Reko.Environments.Windows.Win32Platform(services, arch);
 }
Esempio n. 2
0
 public void Setup()
 {
     mr = new MockRepository();
     var services = mr.Stub<IServiceProvider>();
     var tlSvc = mr.Stub<ITypeLibraryLoaderService>();
     var configSvc = mr.StrictMock<IConfigurationService>();
     var win32env = new OperatingEnvironmentElement
     {
         TypeLibraries = 
         {
             new TypeLibraryElement {  Name= "msvcrt.xml" },
             new TypeLibraryElement {  Name= "windows32.xml" },
         }
     };
     configSvc.Stub(c => c.GetEnvironment("win32")).Return(win32env);
     configSvc.Stub(c => c.GetPath(null)).IgnoreArguments()
         .Do(new Func<string, string>(s => s));
     services.Stub(s => s.GetService(typeof(ITypeLibraryLoaderService))).Return(tlSvc);
     services.Stub(s => s.GetService(typeof(IConfigurationService))).Return(configSvc);
     tlSvc.Stub(t => t.LoadLibrary(null, null)).IgnoreArguments()
         .Do(new Func<IProcessorArchitecture, string, TypeLibrary>((a, n) =>
         {
             var lib = TypeLibrary.Load(a, Path.ChangeExtension(n, ".xml"));
             return lib;
         }));
     services.Replay();
     tlSvc.Replay();
     configSvc.Replay();
     arch = new IntelArchitecture(ProcessorMode.Protected32);
     win32 = new Reko.Environments.Win32.Win32Platform(services, arch);
 }
Esempio n. 3
0
        public void SysV_TerminatingFunction()
        {
            cfgSvc.Stub(c => c.GetInstallationRelativePath("libc.xml"))
                .Return("libc.xml");

            var env = new OperatingEnvironmentElement
            {
                TypeLibraries =
                     {
                         new TypeLibraryElement
                         {
                              Name="libc.xml"
                         }
                     },
                CharacteristicsLibraries =
                     {
                         new TypeLibraryElement
                         {
                             Name="libcharacteristics.xml",
                         }
                     }
            };

            Given_EnvironmentConfiguration(env);
            tlSvc.Stub(t => t.LoadCharacteristics(null))
                .IgnoreArguments()
                .Return(new CharacteristicsLibrary
                {
                    Entries =
                    {
                        {
                            "exit",
                            new ProcedureCharacteristics {
                                Terminates = true
                            }
                        }
                    }
                });
            tlSvc.Stub(t => t.LoadMetadataIntoLibrary(null, null, null))
                .IgnoreArguments()
                .Return(new TypeLibrary
                {
                    Signatures =
                    {
                         {
                            "exit",
                            new FunctionType()
                         }
                     }
                });
            mr.ReplayAll();

            var sysv = new SysVPlatform(sc, arch);
            var proc = sysv.LookupProcedureByName(null, "exit");
            Assert.IsTrue(proc.Characteristics.Terminates, "exit should have been marked as terminating.");
        }
 public void Oee_LoadPlatform_NoHeuristics()
 {
     var element = new OperatingEnvironmentElement
     {
     };
     var platform = new DefaultPlatform(null, null);
     element.LoadSettingsFromConfiguration(null, platform);
     Assert.IsNotNull(platform.Heuristics);
     Assert.IsNotNull(platform.Heuristics.ProcedurePrologs);
     Assert.AreEqual(0, platform.Heuristics.ProcedurePrologs.Length);
 }
 public void Oee_LoadPrologPattern_WithoutMask()
 {
     var sPattern = new BytePattern_v1
     {
         Bytes = "55 3? ?2",
     };
     var element = new OperatingEnvironmentElement();
     var pattern = element.LoadBytePattern(sPattern);
     Assert.AreEqual(new byte[] { 0x55, 0x30, 0x02 }, pattern.Bytes);
     Assert.AreEqual(new byte[] { 0xFF, 0xF0, 0x0F }, pattern.Mask);
 }
Esempio n. 6
0
 private void Given_Configuration_With_Win32_Element()
 {
     var dcSvc = repository.Stub<IConfigurationService>();
     var opEnv = new OperatingEnvironmentElement 
     {
         TypeLibraries =
         {
             new TypeLibraryElement
             {
                 Name = "windows.xml"
             }
         }
     };
     dcSvc.Expect(d => d.GetEnvironment("win32")).Return(opEnv);
     dcSvc.Stub(c => c.GetInstallationRelativePath(null)).IgnoreArguments()
         .Do(new Func<string, string>(s => s));
     
     sc.AddService<IConfigurationService>(dcSvc);
 }
Esempio n. 7
0
        public void SysV_LoadTrashedRegisters()
        {
            arch.Stub(a => a.GetRegister((string)null)).IgnoreArguments()
                .Do(new Func<string, RegisterStorage>(r => new RegisterStorage(r, (int)r[1], 0, PrimitiveType.Word32)));
            var env = new OperatingEnvironmentElement
            {
                Architectures =
                {
                    new PlatformArchitectureElement
                    {
                         TrashedRegisters =
                         {
                             "r2", "r3"
                         }
                    }
                }
            };

            Given_EnvironmentConfiguration(env);

            mr.ReplayAll();

            var sysv = new SysVPlatform(sc, arch);
            var regs = sysv.CreateTrashedRegisters();
            Assert.AreEqual(2, regs.Count);
            Assert.AreEqual("r2,r3", string.Join(",", regs.Select(r => r.Name)));
        }
Esempio n. 8
0
 private void Given_EnvironmentConfiguration(OperatingEnvironmentElement env)
 {
     cfgSvc.Stub(c => c.GetEnvironment(null))
         .IgnoreArguments()
         .Return(env);
 }