public void SudLoadMetadata()
        {
            var sProject = new Project_v2 {
                Inputs =
                {
                    new MetadataFile_v2
                    {
                        Filename = "c:\\tmp\\foo.def"
                    }
                }
            };
            var loader = mr.Stub<ILoader>();
            var typelib = new TypeLibrary();
            loader.Stub(l => l.LoadMetadata("", null)).IgnoreArguments().Return(typelib);
            mr.ReplayAll();

            var ploader = new ProjectLoader(sc, loader);
            var project = ploader.LoadProject(sProject);
            Assert.AreEqual(1, project.MetadataFiles.Count);
            Assert.AreEqual("c:\\tmp\\foo.def", project.MetadataFiles[0].Filename);
        }
        public void Prld_LoadMetadata_NoPlatform_ShouldQuery()
        {
            var ldr = mr.Stub<ILoader>();
            var oracle = mr.StrictMock<IOracleService>();
            var arch = mr.Stub<IProcessorArchitecture>();
            var platform = mockFactory.CreatePlatform();
            var typeLib = new TypeLibrary();
            ldr.Stub(l => l.LoadMetadata(Arg<string>.Is.NotNull, Arg<IPlatform>.Is.Equal(platform), Arg<TypeLibrary>.Is.NotNull)).Return(typeLib);
            oracle.Expect(o => o.QueryPlatform(Arg<string>.Is.NotNull)).Return(platform);
            sc.AddService<IOracleService>(oracle);
            mr.ReplayAll();

            var prld = new ProjectLoader(sc, ldr);
            prld.LoadProject(new Project_v2
            {
                Inputs = {
                        new MetadataFile_v2 {
                            Filename = "foo",
                        }
                    }
            });
            mr.VerifyAll();
        }
        public void SudLoadMetadata()
        {
            var sProject = new Project_v2 {
                Inputs =
                {
                    new MetadataFile_v2
                    {
                        Filename = "c:\\tmp\\foo.def"
                    }
                }
            };
            var loader = mr.Stub<ILoader>();
            var typelib = new TypeLibrary();
            loader.Stub(l => l.LoadMetadata("", null, null)).IgnoreArguments().Return(typelib);
            var oracle = mr.Stub<IOracleService>();
            oracle.Stub(o => o.QueryPlatform(Arg<string>.Is.NotNull)).Return(mockFactory.CreatePlatform());
            sc.AddService<IOracleService>(oracle);
            mr.ReplayAll();

            var ploader = new ProjectLoader(sc, loader);
            var project = ploader.LoadProject("c:\\bar\\bar.dcproj", sProject);
            Assert.AreEqual(1, project.MetadataFiles.Count);
            Assert.AreEqual("c:\\tmp\\foo.def", project.MetadataFiles[0].Filename);
        }
Exemple #4
0
        public void Prld_LoadGlobalUserData()
        {
            var sproject = new Project_v4
            {
                ArchitectureName = "testArch",
                PlatformName = "testOS",
                Inputs =
                {
                    new DecompilerInput_v4
                    {
                        User = new UserData_v4
                        {
                            GlobalData =
                            {
                                new GlobalDataItem_v2
                                {
                                    Address = "10000010",
                                    Name = "testVar",
                                    DataType = new ArrayType_v1
                                    {
                                        ElementType = new TypeReference_v1
                                        {
                                             TypeName = "Blob"
                                        },
                                        Length = 10
                                    }
                                }
                            }
                        }
                    },
                   
                }
            };
            var ldr = mockFactory.CreateLoader();
            Given_TestArch();
            Given_TestOS();
            mr.ReplayAll();

            var prld = new ProjectLoader(sc, ldr);
            var project = prld.LoadProject(
                @"c:\foo\global_user.proj",
                sproject);

            Assert.AreEqual(1, project.Programs.Count);
            Assert.AreEqual(1, project.Programs[0].User.Globals.Count);
            var globalVariable = project.Programs[0].User.Globals.Values[0];
            Assert.AreEqual("10000010", globalVariable.Address);
            Assert.AreEqual("testVar", globalVariable.Name);
            Assert.AreEqual("arr(Blob,10)", globalVariable.DataType.ToString());
        }
Exemple #5
0
        public void Prld_v2()
        {
            var sExp =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<project xmlns=""http://schemata.jklnet.org/Decompiler/v2"">
  <input>
  </input>
</project>";
            var ldr = mr.Stub<ILoader>();
            var platform = new TestPlatform(sc);
            Given_Binary(ldr, platform);
            mr.ReplayAll();

            var prld = new ProjectLoader(sc, ldr);
            var project = prld.LoadProject("/foo/bar", new MemoryStream(Encoding.UTF8.GetBytes(sExp)));

            Assert.AreEqual(1, project.Programs.Count);
        }
Exemple #6
0
        public void Prld_MakePathsAbsolute()
        {
            var sProject = new Project_v4
            {
                ArchitectureName = "testArch",
                PlatformName = "testOS",
                Inputs =
                {
                    new DecompilerInput_v4
                    {
                        Filename = "foo.exe",
                    }
                }
            };
            Given_TestArch();
            Given_TestOS();
            var ldr = mr.Stub<ILoader>();
            ldr.Stub(l => l.LoadExecutable(null, null, null)).IgnoreArguments().Return(new Program());
            ldr.Stub(l => l.LoadImageBytes(null, 0)).IgnoreArguments().Return(new byte[1000]);
            mr.ReplayAll();

            var prld = new ProjectLoader(sc, ldr);
            var project = prld.LoadProject(OsPath.Absolute("users", "bob", "projects", "foo.project"), sProject);
            Assert.AreEqual(OsPath.Absolute("users", "bob", "projects", "foo.exe"), project.Programs[0].Filename);
        }
Exemple #7
0
        public void Prld_PlatformOptions_List()
        {
            var sExp =
    @"<?xml version=""1.0"" encoding=""utf-8""?>
<project xmlns=""http://schemata.jklnet.org/Reko/v4"">
  <arch>testArch</arch>
  <platform>testOS</platform>
  <input>
    <user>
      <platform>
        <list key=""Names"">
          <item>Adam</item>
          <item>Bob</item>
          <item>Cecil</item>
        </list>
        <item key=""Name2"">Sue</item>
      </platform>
    </user>
  </input>
</project>";
            var ldr = mr.Stub<ILoader>();
            Given_TestArch();
            Given_TestOS();
            Given_Binary(ldr, platform);
            Expect_LoadOptions();
            mr.ReplayAll();

            var prld = new ProjectLoader(sc, ldr);
            prld.LoadProject("/ff/b/foo.proj", new MemoryStream(Encoding.UTF8.GetBytes(sExp)));

            var list = (IList)loadedOptions["Names"];
            Assert.AreEqual(3, list.Count);
        }
        public void SudLoadProgramOptions()
        {
            var sProject = new Project_v3
            {
                Inputs =
                {
                    new DecompilerInput_v3
                    {
                        User = new UserData_v3
                        {
                            Heuristics = { new Heuristic_v3 { Name="HeuristicScanning" } }
                        }
                    }
                }
            };
            var loader = mr.Stub<ILoader>();
            loader.Stub(l => l.LoadImageBytes(null, 0))
                .IgnoreArguments()
                .Return(new byte[10]);
            loader.Stub(l => l.LoadExecutable(null, null, null))
                .IgnoreArguments()
                .Return(new Program());
            mr.ReplayAll();

            var ploader = new ProjectLoader(sc, loader);
            var project = ploader.LoadProject(sProject);
            Assert.IsTrue(project.Programs[0].User.Heuristics.Contains("HeuristicScanning"));
        }
        public void Sud_LoadProject_Inputs_v2()
        {
            Given_Loader();
            Given_Architecture();
            Expect_Arch_ParseAddress("1000:0400", Address.SegPtr(0x1000, 0x0400));
            Given_ExecutableProgram("foo.exe", Address.SegPtr(0x1000, 0x0000));
            Given_BinaryFile("foo.bin", Address.SegPtr(0x1000, 0x0000));

            var sProject = new Project_v2
            {
                Inputs = {
                    new DecompilerInput_v2 {
                        Filename = "foo.exe",
                        Address = "1000:0000",
                        Comment = "main file",
                        UserGlobalData = new List<GlobalDataItem_v2>
                        {
                            new GlobalDataItem_v2 { Address = "1000:0400", DataType = new StringType_v2 {
                                Termination=StringType_v2.ZeroTermination,
                                CharType= new PrimitiveType_v1 { ByteSize = 1, Domain=Domain.Character} }
                            }
                        }
                    },
                    new DecompilerInput_v2 {
                        Filename = "foo.bin",
                        Address = "1000:D000",
                        Comment = "overlay",
                        Processor = "x86-real-16",
                    }
                }
            };
            mr.ReplayAll();

            var ps = new ProjectLoader(sc, loader);
            var project = ps.LoadProject(sProject);
            Assert.AreEqual(2, project.Programs.Count);
            var input0 = project.Programs[0];
            Assert.AreEqual(1, input0.User.Globals.Count);
            Assert.AreEqual("1000:0400", input0.User.Globals.Values[0].Address);
            var str_t = (StringType_v2)input0.User.Globals.Values[0].DataType;
            Assert.AreEqual("prim(Character,1)", str_t.CharType.ToString());
            mr.VerifyAll();
        }
        public void Prld_LoadMetadata_SingleBinary_ShouldNotQuery()
        {
            var ldr = mr.Stub<ILoader>();
            var oracle = mr.StrictMock<IOracleService>();
            var arch = mr.Stub<IProcessorArchitecture>();
            var platform = mockFactory.CreatePlatform();
            var typelibrary = new TypeLibrary();
            Given_Binary(ldr, platform);
            ldr.Stub(l => l.LoadMetadata(Arg<string>.Is.NotNull, Arg<IPlatform>.Is.Same(platform), Arg<TypeLibrary>.Is.NotNull)).Return(typelibrary);
            mr.ReplayAll();

            var prld = new ProjectLoader(sc, ldr);
            prld.LoadProject(new Project_v2
            {
                Inputs = {
                        new DecompilerInput_v2 {
                            Filename = "foo.exe",
                        },
                        new MetadataFile_v2 {
                            Filename = "foo",
                        }
                    }
            });
            mr.VerifyAll();
        }
        public void Prld_LoadUserDefinedMetadata()
        {
            var sProject = new Project_v3
            {
                Inputs =
                {
                    new DecompilerInput_v3
                    {
                        Filename = "foo.exe",
                    },
                    new MetadataFile_v3 {
                        Filename = "meta1.xml",
                    },
                    new MetadataFile_v3 {
                        Filename = "meta2.xml",
                    },
                }
            };

            var types1 = new Dictionary<string, DataType>()
            {
                {"USRTYPE1", PrimitiveType.Word16}
            };
            var types2 = new Dictionary<string, DataType>()
            {
                {"USRTYPE2", PrimitiveType.Word32}
            };

            var ldr = mockFactory.CreateLoader();
            var platform = mockFactory.CreatePlatform();

            mockFactory.CreateLoadMetadataStub(
                @"c:\meta1.xml",
                platform,
                new TypeLibrary(
                    types1, new Dictionary<string, ProcedureSignature>()
                )
            );
            mockFactory.CreateLoadMetadataStub(
                @"c:\meta2.xml",
                platform,
                new TypeLibrary(
                    types2, new Dictionary<string, ProcedureSignature>()
                )
            );

            var prld = new ProjectLoader(sc, ldr);
            var project = prld.LoadProject(@"c:\foo.project", sProject);
            Assert.AreEqual(2, project.Programs[0].Metadata.Types.Count);
            Assert.AreEqual(
                "word16",
                project.Programs[0].Metadata.Types["USRTYPE1"].ToString()
            );
            Assert.AreEqual(
                "word32",
                project.Programs[0].Metadata.Types["USRTYPE2"].ToString()
            );
        }
        public void Prld_MakePathsAbsolute()
        {
            var sProject = new Project_v3
            {
                Inputs =
                {
                    new DecompilerInput_v3
                    {
                        Filename = "foo.exe",
                    }
                }
            };

            var ldr = mr.Stub<ILoader>();
            ldr.Stub(l => l.LoadExecutable(null, null, null)).IgnoreArguments().Return(new Program());
            ldr.Stub(l => l.LoadImageBytes(null, 0)).IgnoreArguments().Return(new byte[1000]);
            mr.ReplayAll();

            var prld = new ProjectLoader(sc, ldr);
            var project = prld.LoadProject(@"c:/users/bob/projects/foo.project", sProject);
            Assert.AreEqual(@"c:\users\bob\projects\foo.exe", project.Programs[0].Filename);
        }
Exemple #13
0
        public void Prld_PlatformOptions_Dictionary()
        {
            var sExp =
            @"<?xml version=""1.0"" encoding=""utf-8""?>
            <project xmlns=""http://schemata.jklnet.org/Reko/v3"">
              <input>
            <user>
              <platform>
            <dict key=""Names"">
              <item key=""Adam"">30</item>
              <item key=""Bob"">10</item>
              <item key=""Cecil"">120</item>
            </dict>
            <item key=""Name2"">Sue</item>
              </platform>
            </user>
              </input>
            </project>";
            var ldr = mr.Stub<ILoader>();
            var platform = new TestPlatform();
            Given_Binary(ldr, platform);
            mr.ReplayAll();

            var prld = new ProjectLoader(sc, ldr);
            prld.LoadProject(new MemoryStream(Encoding.UTF8.GetBytes(sExp)));

            var list = (IDictionary)platform.Test_Options["Names"];
            Assert.AreEqual(3, list.Count);
        }
        public void SudLoadProgramOptions()
        {
            var sProject = new Project_v4
            {
                ArchitectureName = "testArch",
                PlatformName = "testOS",
                Inputs = 
                {
                    new DecompilerInput_v4
                    {
                        User = new UserData_v4
                        {
                            Heuristics = { new Heuristic_v3 { Name="HeuristicScanning" } },
                            TextEncoding = "windows-1251",
                            Calls =
                            {
                                new SerializedCall_v1
                                {
                                    InstructionAddress = "0041230",
                                    NoReturn = true, 
                                }
                            },
                            RegisterValues = new RegisterValue_v2[]
                            {
                                new RegisterValue_v2 { Address="00443210", Register="eax", Value="42" },
                                new RegisterValue_v2 { Address="00443210", Register="ecx", Value="10" },
                            }
                        }
                    }
                }
            };
            Given_Architecture();
            Given_TestOS_Platform();
            Expect_TryParseAddress("0041230", Address.Ptr32(0x0041230));
            Expect_TryParseAddress("00443210", Address.Ptr32(0x00443210));
            arch.Stub(a => a.GetRegister("eax")).Return(new RegisterStorage("eax", 0, 0, PrimitiveType.Word32));
            arch.Stub(a => a.GetRegister("ecx")).Return(new RegisterStorage("ecx", 1, 0, PrimitiveType.Word32));
            var loader = mr.Stub<ILoader>();
            loader.Stub(l => l.LoadImageBytes(null, 0))
                .IgnoreArguments()
                .Return(new byte[10]);
            loader.Stub(l => l.LoadExecutable(null, null, null))
                .IgnoreArguments()
                .Return(new Program
                {
                    Platform = this.platform,
                });
            mr.ReplayAll();

            var ploader = new ProjectLoader(sc, loader);
            var project = ploader.LoadProject("c:\\tmp\\foo\\bar.proj", sProject);
            Assert.IsTrue(project.Programs[0].User.Heuristics.Contains("HeuristicScanning"));
            Assert.AreEqual("windows-1251", project.Programs[0].User.TextEncoding.WebName);
            Assert.AreEqual(1, project.Programs[0].User.RegisterValues.Count);
            Assert.AreEqual(2, project.Programs[0].User.RegisterValues[Address.Ptr32(0x00443210)].Count);
        }
Exemple #15
0
 /// <summary>
 /// Loads (or assembles) the decompiler project. If a binary file is specified instead,
 /// we create a simple project for the file.
 /// </summary>
 /// <returns>True if what was loaded was an actual project</returns>
 /// <param name="program"></param>
 /// <param name="cfg"></param>
 public bool Load(string fileName)
 {
     eventListener.ShowStatus("Loading source program.");
     byte[] image = loader.LoadImageBytes(fileName, 0);
     var projectLoader = new ProjectLoader(this.services, loader);
     projectLoader.ProgramLoaded += (s, e) => { RunScriptOnProgramImage(e.Program, e.Program.User.OnLoadedScript); };
     Project = projectLoader.LoadProject(fileName, image);
     bool isProject;
     if (Project != null)
     {
         isProject = true;
     }
     else
     {
         var program = loader.LoadExecutable(fileName, image, null);
         Project = CreateDefaultProject(fileName, program);
         isProject = false;
     }
     eventListener.ShowStatus("Source program loaded.");
     return isProject;
 }
        public void Ps_Load_v3()
        {
            var bytes = new byte[100];
            loader.Stub(l => l.LoadImageBytes(null, 0)).IgnoreArguments().Return(bytes);
            loader.Stub(l => l.LoadExecutable(null, null, null)).IgnoreArguments().Return(
                new Program { Architecture = arch });

            mr.ReplayAll();

            var sp = new Project_v3
            {
                Inputs = {
                    new DecompilerInput_v3
                    {
                        Filename = "f.exe",
                        User = new UserData_v3
                        {
                            Procedures =
                            {
                                new Procedure_v1 {
                                    Name = "Fn",
                                    Decompile = true,
                                    Characteristics = new ProcedureCharacteristics
                                    {
                                        Terminates = true,
                                    },
                                    Address = "113300",
                                    Signature = new SerializedSignature {
                                        ReturnValue = new Argument_v1 {
                                            Type = new PrimitiveType_v1(Domain.SignedInt, 4),
                                        },
                                        Arguments = new Argument_v1[] {
                                            new Argument_v1
                                            {
                                                Name = "a",
                                                Kind = new StackVariable_v1(),
                                                Type = new PrimitiveType_v1(Domain.Character, 2)
                                            },
                                            new Argument_v1
                                            {
                                                Name = "b",
                                                Kind = new StackVariable_v1(),
                                                Type = new PointerType_v1 { DataType = new PrimitiveType_v1(Domain.Character, 2) }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };
            var ps = new ProjectLoader(sc, loader);
            var p = ps.LoadProject("c:\\tmp\\fproj.proj", sp);
            Assert.AreEqual(1, p.Programs.Count);
            var inputFile = p.Programs[0]; 
            Assert.AreEqual(1, inputFile.User.Procedures.Count);
            Assert.AreEqual("Fn", inputFile.User.Procedures.First().Value.Name);
        }
Exemple #17
0
        public void Prld_LoadUserDefinedMetadata()
        {
            var sProject = new Project_v4
            {
                ArchitectureName = "testArch",
                PlatformName = "testOS",
                Inputs =
                {
                    new DecompilerInput_v4
                    {
                        Filename = "foo.exe",
                        User = new UserData_v4
                        {
                            LoadAddress = "00123400"
                        }
                    },
                    new MetadataFile_v3 {
                        Filename = "meta1.xml",
                    },
                    new MetadataFile_v3 {
                        Filename = "meta2.xml",
                    },
                }
            };

            var types1 = new Dictionary<string, DataType>()
            {
                {"USRTYPE1", PrimitiveType.Word16}
            };
            var types2 = new Dictionary<string, DataType>()
            {
                {"USRTYPE2", PrimitiveType.Word32}
            };

            var ldr = mockFactory.CreateLoader();
            Given_TestArch();
            Given_TestOS();
            arch.Stub(a => a.TryParseAddress(
                Arg<string>.Is.Equal("00123400"),
                out Arg<Address>.Out(Address.Ptr32(0x00123400)).Dummy))
                .Return(true);
            mockFactory.CreateLoadMetadataStub(
                OsPath.Absolute("meta1.xml"),
                this.platform,
                new TypeLibrary(
                    types1, new Dictionary<string, FunctionType>(), new Dictionary<string, DataType>()
                )
            );
            mockFactory.CreateLoadMetadataStub(
                OsPath.Absolute("meta2.xml"),
                this.platform,
                new TypeLibrary(
                    types2, new Dictionary<string, FunctionType>(), new Dictionary<string, DataType>()
                )
            );
            mr.ReplayAll();

            var prld = new ProjectLoader(sc, ldr, listener);
            var project = prld.LoadProject(OsPath.Absolute("foo.project"), sProject);
            Assert.AreEqual(2, project.Programs[0].EnvironmentMetadata.Types.Count);
            Assert.AreEqual(
                "word16",
                project.Programs[0].EnvironmentMetadata.Types["USRTYPE1"].ToString()
            );
            Assert.AreEqual(
                "word32",
                project.Programs[0].EnvironmentMetadata.Types["USRTYPE2"].ToString()
            );
            Assert.AreEqual(
                Address.Ptr32(0x00123400),
                project.Programs[0].User.LoadAddress);
        }
Exemple #18
0
        public void Prld_Partial_UserProc()
        {
            var sProject = new Project_v4
            {
                ArchitectureName = "testArch",
                PlatformName = "testOS",
                Inputs =
                {
                    new DecompilerInput_v4
                    {
                        User = new UserData_v4
                        {
                            Procedures =
                            {
                                new Procedure_v1
                                {
                                    Address = "00123400",
                                    Decompile = false,
                                }
                            }
                        }
                    }
                }
            };

            var ldr = mockFactory.CreateLoader();
            Given_TestArch();
            Given_TestOS();
            var addrNav = mr.Stub<ICodeLocation>();
            listener.Stub(l => l.CreateAddressNavigator(null, null))
                .IgnoreArguments()
                .Return(addrNav);
            listener.Expect(l => l.Warn(null, null, null))
                .IgnoreArguments();
            mr.ReplayAll();

            var prld = new ProjectLoader(sc, ldr, listener);
            prld.LoadProject("foo.dcproject", sProject);

            mr.VerifyAll();
        }
        public void SudLoadProgramOptions()
        {
            var sProject = new Project_v2
            {
                Inputs = 
                {
                    new DecompilerInput_v2
                    {
                        Options = new ProgramOptions_v2
                        {
                            HeuristicScanning = true,
                        }
                    }
                }
            };
            var loader = mr.Stub<ILoader>();
            loader.Stub(l => l.LoadImageBytes(null, 0))
                .IgnoreArguments()
                .Return(new byte[10]);
            loader.Stub(l => l.LoadExecutable(null, null, null))
                .IgnoreArguments()
                .Return(new Program());
            mr.ReplayAll();

            var ploader = new ProjectLoader(loader);
            var project = ploader.LoadProject(sProject);
            Assert.IsTrue(project.Programs[0].Options.HeuristicScanning);
        }
Exemple #20
0
        public void Prld_PlatformOptions_Scalar()
        {
            var sExp =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<project xmlns=""http://schemata.jklnet.org/Reko/v4"">
  <arch>testArch</arch>
  <platform>testOS</platform>
  <input>
    <user>
      <platform>
        <item key=""Name"">Bob</item>
        <item key=""Name2"">Sue</item>
      </platform>
    </user>
  </input>
</project>";
            var ldr = mr.Stub<ILoader>();
            Given_TestArch();
            Given_TestOS();
            Given_Binary(ldr, platform);
            Expect_LoadOptions();
            mr.ReplayAll();

            var prld = new ProjectLoader(sc, ldr);
            prld.LoadProject("/foo/bar", new MemoryStream(Encoding.UTF8.GetBytes(sExp)));

            Assert.AreEqual(2, loadedOptions.Count);
            Assert.AreEqual("Bob", loadedOptions["Name"]);
            Assert.AreEqual("Sue", loadedOptions["Name2"]);
        }
        public void Ps_Load_v4()
        {
            var bytes = new byte[100];
            loader.Stub(l => l.LoadImageBytes(null, 0)).IgnoreArguments().Return(bytes);
            loader.Stub(l => l.LoadExecutable(null, null, null)).IgnoreArguments().Return(
                new Program { Architecture = arch });
            Given_Architecture();
            Given_TestOS_Platform();
            Given_Platform_Address("113800", 0x113800);
            Given_Platform_Address("114000", 0x114000);
            Given_Platform_Address("115000", 0x115000);
            Given_Platform_Address("115012", 0x115012);
            Given_Platform_Address("11504F", 0x11504F);
            arch.Stub(a => a.GetRegister("r1")).Return(new RegisterStorage("r1", 1, 0, PrimitiveType.Word32));
            mr.ReplayAll();

            var sp = new Project_v4
            {
                ArchitectureName = "testArch",
                PlatformName = "testOS",
                Inputs = {
                    new DecompilerInput_v4
                    {
                        Filename = "f.exe",
                        User = new UserData_v4
                        {
                            Procedures =
                            {
                                new Procedure_v1 {
                                    Name = "Fn",
                                    Decompile = true,
                                    Characteristics = new ProcedureCharacteristics
                                    {
                                        Terminates = true,
                                    },
                                    Address = "113300",
                                    Signature = new SerializedSignature {
                                        ReturnValue = new Argument_v1 {
                                            Type = new PrimitiveType_v1(Domain.SignedInt, 4),
                                        },
                                        Arguments = new Argument_v1[] {
                                            new Argument_v1
                                            {
                                                Name = "a",
                                                Kind = new StackVariable_v1(),
                                                Type = new PrimitiveType_v1(Domain.Character, 2)
                                            },
                                            new Argument_v1
                                            {
                                                Name = "b",
                                                Kind = new StackVariable_v1(),
                                                Type = new PointerType_v1 { DataType = new PrimitiveType_v1(Domain.Character, 2) }
                                            }
                                        }
                                    }
                                }
                            },
                            IndirectJumps =
                            {
                                new IndirectJump_v4
                                {
                                    InstructionAddress = "113800",
                                    IndexRegister = "r1",
                                    TableAddress = "114000",
                                }
                            },
                            JumpTables =
                            {
                                new JumpTable_v4
                                {
                                    TableAddress = "114000",
                                    Destinations = new []
                                    {
                                        "115000",
                                        "115012",
                                        "11504F",
                                    }
                                }
                            }
                        }
                    }
                }
            };
            var ps = new ProjectLoader(sc, loader);
            var p = ps.LoadProject("c:\\tmp\\fproj.proj", sp);
            Assert.AreEqual(1, p.Programs.Count);
            var inputFile = p.Programs[0]; 
            Assert.AreEqual(1, inputFile.User.Procedures.Count);
            Assert.AreEqual("Fn", inputFile.User.Procedures.First().Value.Name);

            Assert.AreEqual(1, inputFile.User.JumpTables.Count);
            var jumpTable = inputFile.User.JumpTables[Address.Ptr32(0x114000)];
            Assert.AreEqual(Address.Ptr32(0x00115000), jumpTable.Addresses[0]);
            Assert.AreEqual(Address.Ptr32(0x00115012), jumpTable.Addresses[1]);
            Assert.AreEqual(Address.Ptr32(0x0011504F), jumpTable.Addresses[2]);

            Assert.AreEqual(1, inputFile.User.IndirectJumps.Count);
            var indJump = inputFile.User.IndirectJumps[Address.Ptr32(0x00113800)];
            Assert.AreSame(jumpTable, indJump.Table);

        }
Exemple #22
0
        public void Prld_PlatformOptions_Dictionary()
        {
            var sproject =
    @"<?xml version=""1.0"" encoding=""utf-8""?>
<project xmlns=""http://schemata.jklnet.org/Reko/v4"">
  <arch>testArch</arch>
  <platform>testOS</platform>
  <input>
    <user>
      <platform>
        <dict key=""Names"">
          <item key=""Adam"">30</item>
          <item key=""Bob"">10</item>
          <item key=""Cecil"">120</item>
        </dict>
        <item key=""Name2"">Sue</item>
      </platform>
    </user>
  </input>
</project>";
            var ldr = mr.Stub<ILoader>();
            Given_TestArch();
            Given_TestOS();
            Given_Binary(ldr, platform);
            Expect_LoadOptions();

            mr.ReplayAll();

            var prld = new ProjectLoader(sc, ldr);
            prld.LoadProject("c:\\foo\\bar.proj", new MemoryStream(Encoding.UTF8.GetBytes(sproject)));

            var list = (IDictionary)loadedOptions["Names"];
            Assert.AreEqual(3, list.Count);
        }
Exemple #23
0
 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;
 }
Exemple #24
0
        public void Prld_LoadUserDefinedMetadata()
        {
            var sProject = new Project_v4
            {
                ArchitectureName = "testArch",
                PlatformName = "testOS",
                Inputs =
                {
                    new DecompilerInput_v4
                    {
                        Filename = "foo.exe",
                    },
                    new MetadataFile_v3 {
                        Filename = "meta1.xml",
                    },
                    new MetadataFile_v3 {
                        Filename = "meta2.xml",
                    },
                }
            };

            var types1 = new Dictionary<string, DataType>()
            {
                {"USRTYPE1", PrimitiveType.Word16}
            };
            var types2 = new Dictionary<string, DataType>()
            {
                {"USRTYPE2", PrimitiveType.Word32}
            };

            var ldr = mockFactory.CreateLoader();
            Given_TestArch();
            Given_TestOS();

            mockFactory.CreateLoadMetadataStub(
                OsPath.Absolute("meta1.xml"),
                this.platform,
                new TypeLibrary(
                    types1, new Dictionary<string, FunctionType>(), new Dictionary<string, DataType>()
                )
            );
            mockFactory.CreateLoadMetadataStub(
                OsPath.Absolute("meta2.xml"),
                this.platform,
                new TypeLibrary(
                    types2, new Dictionary<string, FunctionType>(), new Dictionary<string, DataType>()
                )
            );
            mr.ReplayAll();

            var prld = new ProjectLoader(sc, ldr);
            var project = prld.LoadProject(OsPath.Absolute("foo.project"), sProject);
            Assert.AreEqual(2, project.Programs[0].EnvironmentMetadata.Types.Count);
            Assert.AreEqual(
                "word16",
                project.Programs[0].EnvironmentMetadata.Types["USRTYPE1"].ToString()
            );
            Assert.AreEqual(
                "word32",
                project.Programs[0].EnvironmentMetadata.Types["USRTYPE2"].ToString()
            );
        }
Exemple #25
0
 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),
                 new FakeDecompilerEventListener())
             .LoadProject(absFile, stm);
         }
     }
     else
     {
         project = new Project();
     }
     return project;
 }
Exemple #26
0
        public void Prld_issue_299()
        {
            var sExp =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<project xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns=""http://schemata.jklnet.org/Reko/v3"">
  <input>
    <filename>switch.dll</filename>
    <disassembly>switch.asm</disassembly>
    <intermediate-code>switch.dis</intermediate-code>
    <output>switch.c</output>
    <types-file>switch.h</types-file>
    <global-vars>switch.globals.c</global-vars>
    <user>
      <procedure name=""get"">
        <address>10071000</address>
        <CSignature>char * get(unsigned int n)</CSignature>
      </procedure>
      <heuristic name=""shingle"" />
    </user>
  </input>
</project>
";
            var ldr = mr.Stub<ILoader>();
            var platform = new TestPlatform(sc);
            Given_TestArch();
            Given_TestOS();
            Given_Binary(ldr, platform);
            Given_TypeLibraryLoaderService();
            oe.Stub(o => o.TypeLibraries).Return(new List<ITypeLibraryElement>());
            oe.Stub(o => o.CharacteristicsLibraries).Return(new List<ITypeLibraryElement>());
            mr.ReplayAll();

            var prld = new ProjectLoader(sc, ldr);
            var project = prld.LoadProject("/foo/bar", new MemoryStream(Encoding.UTF8.GetBytes(sExp)));

            Assert.AreEqual(1, project.Programs.Count);
        }
Exemple #27
0
 public void AddMetadataFile()
 {
     var fileName = uiSvc.ShowOpenFileDialog(null);
     if (fileName == null)
         return;
     mru.Use(fileName);
     var projectLoader = new ProjectLoader(Services, loader, this.decompilerSvc.Decompiler.Project);
     var metadata = projectLoader.LoadMetadataFile(fileName);
     decompilerSvc.Decompiler.Project.MetadataFiles.Add(metadata);
 }
Exemple #28
0
 public Deserializer(ProjectLoader outer, string filename)
 {
     this.outer = outer; this.filename = filename;
 }
Exemple #29
0
        /// <summary>
        /// Prompts the user for a metadata file and adds to the project.
        /// </summary>
        public void AddMetadataFile()
        {
            var fileName = uiSvc.ShowOpenFileDialog(null);
            if (fileName == null)
                return;
            mru.Use(fileName);
            var projectLoader = new ProjectLoader(
                Services,
                loader,
                this.decompilerSvc.Decompiler.Project,
                this.sc.RequireService<DecompilerEventListener>());

            try
            {
                var metadata = projectLoader.LoadMetadataFile(fileName);
                decompilerSvc.Decompiler.Project.MetadataFiles.Add(metadata);
            }
            catch (Exception e)
            {
                uiSvc.ShowError(e, "An error occured while parsing the metadata file {0}", fileName);
            }
        }