Exemple #1
0
        public void Setup()
        {
            mr            = new MockRepository();
            eventListener = new FakeDecompilerEventListener();
            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 => RekoConfigurationService.MakeInstallationRelativePath(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(eventListener);
            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("x86-protected-32");
            win32 = new Reko.Environments.Windows.Win32Platform(services, arch);
        }
        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)));
        }
Exemple #3
0
        public void Setup()
        {
            eventListener = new FakeDecompilerEventListener();
            this.services = new ServiceContainer();
            var tlSvc     = new TypeLibraryLoaderServiceImpl(services);
            var configSvc = new Mock <IConfigurationService>();
            var win32env  = new OperatingEnvironmentElement
            {
                TypeLibraries =
                {
                    new TypeLibraryElement {
                        Name = "msvcrt.xml"
                    },
                    new TypeLibraryElement {
                        Name = "windows32.xml"
                    },
                }
            };

            configSvc.Setup(c => c.GetEnvironment("win32")).Returns(win32env);
            configSvc.Setup(c => c.GetInstallationRelativePath(It.IsAny <string>()))
            .Returns((string[] s) => RekoConfigurationService.MakeInstallationRelativePath(s));
            services.AddService(typeof(ITypeLibraryLoaderService), tlSvc);
            services.AddService(typeof(IConfigurationService), configSvc.Object);
            services.AddService(typeof(DecompilerEventListener), eventListener);
            services.AddService(typeof(CancellationTokenSource), new CancellationTokenSource());
            services.AddService(typeof(IFileSystemService), new FileSystemServiceImpl());
            services.AddService(typeof(IDiagnosticsService), new FakeDiagnosticsService());
            arch  = new X86ArchitectureFlat32("x86-protected-32");
            win32 = new Reko.Environments.Windows.Win32Platform(services, arch);
        }
Exemple #4
0
        public void SysV_LoadTrashedRegisters()
        {
            arch.Setup(a => a.Name).Returns("mmix");
            arch.Setup(a => a.GetRegister(It.IsAny <string>()))
            .Returns((string r) => new RegisterStorage(r, (int)r[1], 0, PrimitiveType.Word32));
            var env = new OperatingEnvironmentElement
            {
                Architectures =
                {
                    new PlatformArchitectureElement()
                    {
                        Name             = "mmix",
                        TrashedRegisters =
                        {
                            "r2", "r3"
                        }
                    }
                }
            };

            Given_EnvironmentConfiguration(env);

            var sysv = new SysVPlatform(sc, arch.Object);
            var regs = sysv.CreateTrashedRegisters();

            Assert.AreEqual(2, regs.Count);
            Assert.AreEqual("r2,r3", string.Join(",", regs.Select(r => r.Name)));
        }
Exemple #5
0
        private void Given_MachineCode(string hex)
        {
            var bytes = OperatingEnvironmentElement.LoadHexBytes(hex)
                        .ToArray();

            this.image = new MemoryArea(LoadAddress, bytes);
        }
Exemple #6
0
        protected override MemoryArea RewriteCode(string hexBytes)
        {
            var bytes = OperatingEnvironmentElement.LoadHexBytes(hexBytes)
                        .ToArray();

            this.image = new MemoryArea(LoadAddress, bytes);
            return(image);
        }
        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.");
        }
Exemple #8
0
        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);
        }
Exemple #9
0
        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);
        }
Exemple #10
0
        private void Given_Configuration_With_Win32_Element()
        {
            var dcSvc = mr.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 => string.Join("/", s)));

            sc.AddService <IConfigurationService>(dcSvc);
        }
Exemple #11
0
        private void Given_Configuration_With_Win32_Element()
        {
            var dcSvc = new Mock <IConfigurationService>();
            var opEnv = new OperatingEnvironmentElement
            {
                TypeLibraries =
                {
                    new TypeLibraryElement
                    {
                        Name = "windows.xml"
                    }
                }
            };

            dcSvc.Setup(d => d.GetEnvironment("win32")).Returns(opEnv);
            dcSvc.Setup(c => c.GetInstallationRelativePath(
                            It.IsAny <string[]>()))
            .Returns((string [] s) => string.Join("/", s));

            sc.AddService <IConfigurationService>(dcSvc.Object);
        }
Exemple #12
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 <Platform, string, TypeLibrary>((p, n) =>
            {
                var lib = TypeLibrary.Load(p, 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);
        }
 private void Given_EnvironmentConfiguration(OperatingEnvironmentElement env)
 {
     cfgSvc.Stub(c => c.GetEnvironment(null))
     .IgnoreArguments()
     .Return(env);
 }
Exemple #14
0
 public byte[] ParseHexPattern(string hexPattern)
 {
     return(OperatingEnvironmentElement.LoadHexBytes(hexPattern)
            .ToArray());
 }
Exemple #15
0
 private void Given_EnvironmentConfiguration(OperatingEnvironmentElement env)
 {
     cfgSvc.Setup(c => c.GetEnvironment(It.IsAny <string>()))
     .Returns(env);
 }