示例#1
0
        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);
        }
示例#2
0
        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, listener);
            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);
        }
示例#3
0
        public void SudLoadMetadata()
        {
            var sProject = new Project_v2 {
                Inputs =
                {
                    new MetadataFile_v2
                    {
                        Filename = "c:\\tmp\\foo.def"
                    }
                }
            };
            var loader  = new Mock <ILoader>();
            var typelib = new TypeLibrary();

            loader.Setup(l => l.LoadMetadata(
                             It.IsAny <string>(),
                             It.IsAny <IPlatform>(),
                             It.IsAny <TypeLibrary>()))
            .Returns(typelib);
            var oracle = new Mock <IOracleService>();

            oracle.Setup(o => o.QueryPlatform(It.IsNotNull <string>())).Returns(mockFactory.CreatePlatform());
            sc.AddService <IOracleService>(oracle.Object);

            var ploader = new ProjectLoader(sc, loader.Object, listener.Object);
            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);
        }
示例#4
0
 public Project_v2 Save(Project project)
 {
     var inputs = new List<ProjectFile_v2>();
     inputs.AddRange(project.Programs.Select(prog => VisitProgram(prog)));
     inputs.AddRange(project.MetadataFiles.Select(m => VisitMetadataFile(m)));
     var sp = new Project_v2()
     {
         Inputs = inputs
     };
     return sp;
 }
示例#5
0
        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, listener);
            var project = ps.LoadProject("project.dcproj", 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();
        }
示例#6
0
 public void foo()
 {
     var sp = new Project_v2
     {
         Inputs = new List<ProjectFile_v2> {
             new AssemblerFile_v2 { Filename="foo.asm", Assembler="x86-att" }
         }
     };
     var sw = new StringWriter();
     new ProjectLoader(sc, loader).Save(sp, sw);
     Console.WriteLine(sw);
 }
示例#7
0
        public void SlibCodeWrite()
        {
            var proj = new Project_v2
            {
                Inputs =
                {
                    new DecompilerInput_v2 {
                        UserGlobalData =
                        {
                            new GlobalDataItem_v2
                            {
                                Address  = "00100000",
                                Name     = "foo",
                                DataType = new ArrayType_v1{
                                    ElementType = new PointerType_v1{
                                        PointerSize = 4,
                                        DataType    = new CodeType_v1()
                                    },
                                    Length = 10,
                                }
                            }
                        }
                    }
                }
            };
            var ser    = SerializedLibrary.CreateSerializer_v2(typeof(Project_v2));
            var sw     = new StringWriter();
            var writer = new FilteringXmlWriter(sw);

            writer.Formatting = Formatting.Indented;
            ser.Serialize(writer, proj);

            Debug.Print(sw.ToString());
            var sExp = @"<?xml version=""1.0"" encoding=""utf-16""?>
<project xmlns=""http://schemata.jklnet.org/Decompiler/v2"">
  <input>
    <global>
      <Address>00100000</Address>
      <arr length=""10"">
        <ptr size=""4"">
          <code />
        </ptr>
      </arr>
      <Name>foo</Name>
    </global>
  </input>
  <output />
</project>";

            Assert.AreEqual(sExp, sw.ToString());
        }
示例#8
0
        public void foo()
        {
            var sp = new Project_v2
            {
                Inputs = new List <ProjectFile_v2> {
                    new AssemblerFile_v2 {
                        Filename = "foo.asm", Assembler = "x86-att"
                    }
                }
            };
            var sw = new StringWriter();

            new ProjectLoader(loader).Save(sp, sw);
            Console.WriteLine(sw);
        }
示例#9
0
        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);
        }
示例#10
0
        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("")).IgnoreArguments().Return(typelib);
            mr.ReplayAll();

            var ploader = new ProjectLoader(loader);
            var project = ploader.LoadProject(sProject);

            Assert.AreEqual(1, project.MetadataFiles.Count);
            Assert.AreEqual("c:\\tmp\\foo.def", project.MetadataFiles[0].Filename);
        }
示例#11
0
 public void Save(Project_v2 project, TextWriter sw)
 {
     XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(typeof(Project_v2));
     ser.Serialize(sw, project);
 }
示例#12
0
 public Project LoadProject(Project_v2 sp)
 {
     var typelibs = sp.Inputs.OfType<MetadataFile_v2>().Select(m => VisitMetadataFile(m));
     var programs = sp.Inputs.OfType<DecompilerInput_v2>().Select(s => VisitInputFile(s));
     var asm = sp.Inputs.OfType<AssemblerFile_v2>().Select(s => VisitAssemblerFile(s));
     var project = new Project();
     project.Programs.AddRange(programs);
     project.MetadataFiles.AddRange(typelibs);
     return project;
 }
示例#13
0
        public void SlibCodeWrite()
        {
            var proj = new Project_v2
            {
                Inputs = {
                    new DecompilerInput_v2 {
                        UserGlobalData = {
                            new GlobalDataItem_v2 
                            {
                                 Address = "00100000",
                                 Name = "foo",
                                 DataType = new ArrayType_v1 {
                                     ElementType = new PointerType_v1 {
                                          PointerSize = 4,
                                          DataType = new CodeType_v1()
                                     },
                                     Length = 10,
                                 }
                            }
                        }
                    }
                }
            };
            var ser = SerializedLibrary.CreateSerializer_v2(typeof(Project_v2));
            var sw = new StringWriter();
            var writer = new FilteringXmlWriter(sw);
            writer.Formatting = Formatting.Indented;
            ser.Serialize(writer, proj);

            Debug.Print(sw.ToString());
            var sExp = @"<?xml version=""1.0"" encoding=""utf-16""?>
<project xmlns=""http://schemata.jklnet.org/Decompiler/v2"">
  <input>
    <global>
      <Address>00100000</Address>
      <arr length=""10"">
        <ptr size=""4"">
          <code />
        </ptr>
      </arr>
      <Name>foo</Name>
    </global>
  </input>
  <output />
</project>";
            Assert.AreEqual(sExp, sw.ToString());
        }
示例#14
0
        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();
        }
示例#15
0
        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);
        }
示例#16
0
        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);
        }