Ejemplo n.º 1
0
        public void Tlldr_typedef_ptr_int()
        {
            Given_ArchitectureStub();
            Given_Arch_PointerDataType(PrimitiveType.Ptr32);

            var tlLdr = new TypeLibraryDeserializer(platform.Object, true, new TypeLibrary());
            var slib  = new SerializedLibrary
            {
                Types = new SerializedType[]
                {
                    new SerializedTypedef {
                        Name     = "pint",
                        DataType = new PointerType_v1
                        {
                            DataType = new PrimitiveType_v1 {
                                Domain = Domain.SignedInt, ByteSize = 4
                            }
                        }
                    }
                }
            };
            var lib = tlLdr.Load(slib);

            Assert.AreEqual("(ptr32 int32)", lib.LookupType("pint").ToString());
        }
Ejemplo n.º 2
0
        public void Tlldr_void_fn()
        {
            Given_ArchitectureStub();
            Given_ProcedureSignature(FunctionType.Action());

            var tlLdr = new TypeLibraryDeserializer(platform.Object, true, new TypeLibrary());
            var slib  = new SerializedLibrary
            {
                Procedures =
                {
                    new Procedure_v1 {
                        Name      = "foo",
                        Signature = new SerializedSignature
                        {
                            Convention  = "__cdecl",
                            ReturnValue = new Argument_v1{
                                Type = new VoidType_v1()
                            },
                        }
                    }
                }
            };
            var lib = tlLdr.Load(slib);

            Assert.AreEqual(
                "void foo()",
                lib.Lookup("foo").ToString("foo"));
        }
        public void Tlldr_procedure_with_address()
        {
            Given_ArchitectureStub();
            var addr = Address.SegPtr(0x1234, 0x4567);

            platform.Setup(p => p.TryParseAddress("0123:4567", out addr)).Returns(true);
            Given_ProcedureSignature(FunctionType.Action());

            var tlLdr = new TypeLibraryDeserializer(platform.Object, true, new TypeLibrary());
            var slib  = new SerializedLibrary
            {
                Procedures =
                {
                    new Procedure_v1 {
                        Name      = "foo",
                        Signature = new SerializedSignature
                        {
                            Convention  = "__cdecl",
                            ReturnValue = new Argument_v1{
                                Type = new VoidType_v1()
                            },
                        },
                        Address = "0123:4567"
                    }
                }
            };
            var lib = tlLdr.Load(slib);

            var(name, sig) = lib.Procedures[addr];
            Assert.AreEqual("foo", name);
            Assert.AreEqual("(fn void ())", sig.ToString());
        }
Ejemplo n.º 4
0
        public void Tlldr_BothOrdinalAndName()
        {
            Given_ArchitectureStub();
            Given_ProcedureSignature(new FunctionType());

            var tlLDr = new TypeLibraryDeserializer(platform.Object, true, new TypeLibrary());
            var slib  = new SerializedLibrary
            {
                Procedures =
                {
                    new SerializedService {
                        Name      = "foo",
                        Ordinal   = 2,
                        Signature = new SerializedSignature{
                            ReturnValue = new Argument_v1{
                                Type = new VoidType_v1()
                            }
                        }
                    }
                }
            };
            var lib = tlLDr.Load(slib);

            Assert.AreEqual(1, lib.Modules[""].ServicesByOrdinal.Count);
            Assert.IsNotNull(lib.Modules[""].ServicesByOrdinal[2]);
        }
Ejemplo n.º 5
0
        public void Tlldr_LoadGlobalByOrdinal()
        {
            var typelib = new TypeLibrary();

            platform = new Mock <IPlatform>();
            platform.Setup(p => p.DefaultCallingConvention).Returns("__cdecl");
            platform.Setup(p => p.Architecture).Returns(new FakeArchitecture(new ServiceContainer()));

            var tlldr = new TypeLibraryDeserializer(platform.Object, true, typelib);

            tlldr.Load(new SerializedLibrary
            {
                ModuleName = "stdlib",
                Globals    = new List <GlobalVariable_v1>
                {
                    new GlobalVariable_v1
                    {
                        Name    = "errno",
                        Ordinal = 42,
                        Type    = PrimitiveType_v1.Int32(),
                    }
                }
            });
            var stdlib          = typelib.Modules["stdlib"];
            var globalByName    = stdlib.GlobalsByName["errno"];
            var globalByOrdinal = stdlib.GlobalsByOrdinal[42];

            Assert.AreSame(globalByName, globalByOrdinal);
        }
Ejemplo n.º 6
0
        public void Tlldr_typedef_empty_enum()
        {
            Given_ArchitectureStub();
            mr.ReplayAll();

            var tlLdr = new TypeLibraryDeserializer(platform, true, new TypeLibrary());
            var slib  = new SerializedLibrary
            {
                Types = new SerializedType[]
                {
                    new SerializedTypedef
                    {
                        Name     = "empty_enum",
                        DataType = new SerializedEnumType
                        {
                            Name = "empty",
                            Size = 4,
                        }
                    }
                }
            };
            var lib = tlLdr.Load(slib);

            Assert.AreEqual("(enum empty,())", lib.LookupType("empty_enum").ToString());
        }
Ejemplo n.º 7
0
 public override TypeLibrary Load(IPlatform platform, TypeLibrary dstLib)
 {
     var ser = SerializedLibrary.CreateSerializer();
     var slib = (SerializedLibrary) ser.Deserialize(stream);
     var tldser = new TypeLibraryDeserializer(platform, true, dstLib);
     var tlib = tldser.Load(slib);
     return tlib;
 }
        public void Tlldr_Empty()
        {
            Given_ArchitectureStub();
            mr.ReplayAll();

            var tlLdr = new TypeLibraryDeserializer(platform, true, new TypeLibrary());
            TypeLibrary lib = tlLdr.Load(new SerializedLibrary());
        }
Ejemplo n.º 9
0
        public void Tlldr_Empty()
        {
            Given_ArchitectureStub();
            mr.ReplayAll();

            var         tlLdr = new TypeLibraryDeserializer(platform, true, new TypeLibrary());
            TypeLibrary lib   = tlLdr.Load(new SerializedLibrary());
        }
Ejemplo n.º 10
0
        public void Tlldr_Empty()
        {
            Given_ArchitectureStub();
            mr.ReplayAll();

            var tlLdr = new TypeLibraryDeserializer(platform, true, new TypeLibrary());
            TypeLibrary lib = tlLdr.Load(new SerializedLibrary());
            Assert.AreEqual(0, lib.Types.Count);
            Assert.AreEqual(0, lib.Signatures.Count);
            Assert.AreEqual(1, lib.Modules.Count, "The blank module is there");
        }
Ejemplo n.º 11
0
        public void Tlldr_Empty()
        {
            Given_ArchitectureStub();

            var         tlLdr = new TypeLibraryDeserializer(platform.Object, true, new TypeLibrary());
            TypeLibrary lib   = tlLdr.Load(new SerializedLibrary());

            Assert.AreEqual(0, lib.Types.Count);
            Assert.AreEqual(0, lib.Signatures.Count);
            Assert.AreEqual(1, lib.Modules.Count, "The blank module is there");
        }
Ejemplo n.º 12
0
 public void SlLookupType()
 {
     var slib = new SerializedLibrary
     {
         Types = new SerializedType[]
         {
             new SerializedTypedef { 
                 Name="int", 
                 DataType=new PrimitiveType_v1 { Domain = Reko.Core.Types.Domain.SignedInt, ByteSize = 4 }
             }
         }
     };
     var arch = new X86ArchitectureFlat32();
     var platform = new SysVPlatform(null, arch);
     var tldser = new TypeLibraryDeserializer(platform, true, new TypeLibrary());
     var lib = tldser.Load(slib);
     Assert.AreEqual(PrimitiveType.Int32, lib.LookupType("int"));
 }
Ejemplo n.º 13
0
        public void Tlldr_typedef_int()
        {
            Given_ArchitectureStub();

            var tlLdr = new TypeLibraryDeserializer(platform.Object, true, new TypeLibrary());
            var slib  = new SerializedLibrary
            {
                Types = new SerializedType[]
                {
                    new SerializedTypedef {
                        Name = "int", DataType = new PrimitiveType_v1 {
                            Domain = Domain.SignedInt, ByteSize = 4
                        }
                    }
                }
            };
            var lib = tlLdr.Load(slib);

            Assert.AreSame(PrimitiveType.Int32, lib.LookupType("int"));
        }
Ejemplo n.º 14
0
        public void SlLookupType()
        {
            var slib = new SerializedLibrary
            {
                Types = new SerializedType[]
                {
                    new SerializedTypedef {
                        Name     = "int",
                        DataType = new PrimitiveType_v1 {
                            Domain = Reko.Core.Types.Domain.SignedInt, ByteSize = 4
                        }
                    }
                }
            };
            var arch     = new X86ArchitectureFlat32();
            var platform = new SysVPlatform(null, arch);
            var tldser   = new TypeLibraryDeserializer(platform, true, new TypeLibrary());
            var lib      = tldser.Load(slib);

            Assert.AreEqual(PrimitiveType.Int32, lib.LookupType("int"));
        }
        public void Tlldr_LoadGlobalByOrdinal()
        {
            var typelib = new TypeLibrary();
            var tlldr   = new TypeLibraryDeserializer(platform, true, typelib);

            tlldr.Load(new SerializedLibrary
            {
                ModuleName = "stdlib",
                Globals    = new List <GlobalVariable_v1>
                {
                    new GlobalVariable_v1
                    {
                        Name    = "errno",
                        Ordinal = 42,
                        Type    = PrimitiveType_v1.Int32(),
                    }
                }
            });
            var stdlib          = typelib.Modules["stdlib"];
            var globalByName    = stdlib.GlobalsByName["errno"];
            var globalByOrdinal = stdlib.GlobalsByOrdinal[42];

            Assert.AreSame(globalByName, globalByOrdinal);
        }
        public void Tlldr_BothOrdinalAndName()
        {  
            Given_ArchitectureStub();
            mr.ReplayAll();
            var tlLDr = new TypeLibraryDeserializer(platform, true, new TypeLibrary());
            var slib = new SerializedLibrary {
                Procedures = {
                    new SerializedService {
                        Name="foo",
                        Ordinal=2,
                        Signature = new SerializedSignature {
                            ReturnValue = new Argument_v1 {
                                Type = new VoidType_v1()
                            }
                        }
                    }
                }
            };
            var lib = tlLDr.Load(slib);

            mr.VerifyAll();
            Assert.AreEqual(1, lib.Modules[""].ServicesByVector.Count);
            Assert.IsNotNull(lib.Modules[""].ServicesByVector[2]);
        }
        public void Tlldr_typedef_int()
        {
            Given_ArchitectureStub();
            mr.ReplayAll();

            var tlLdr = new TypeLibraryDeserializer(platform, true, new TypeLibrary());
            var slib = new SerializedLibrary
            {
                Types = new SerializedType[]
                {
                    new SerializedTypedef { Name="int", DataType=new PrimitiveType_v1 { Domain = Domain.SignedInt, ByteSize=4 }}
                }
            };
            var lib = tlLdr.Load(slib);

            Assert.AreSame(PrimitiveType.Int32, lib.LookupType("int"));
        }
        public void Tlldr_typedef_ptr_int()
        {
            Given_ArchitectureStub();
            Given_Arch_PointerDataType(PrimitiveType.Pointer32);
            mr.ReplayAll();

            var tlLdr = new TypeLibraryDeserializer(platform, true, new TypeLibrary());
            var slib = new SerializedLibrary
            {
                Types = new SerializedType[]
                {
                    new SerializedTypedef { 
                        Name="pint", 
                        DataType= new PointerType_v1
                        {
                            DataType = new PrimitiveType_v1 { Domain = Domain.SignedInt, ByteSize=4 } 
                        }
                    }
                }
            };
            var lib = tlLdr.Load(slib);

            Assert.AreEqual("(ptr int32)", lib.LookupType("pint").ToString());
        }
        public void Tlldr_void_fn()
        {
            Given_ArchitectureStub();
            mr.ReplayAll();

            var tlLdr = new TypeLibraryDeserializer(platform, true, new TypeLibrary());
            var slib = new SerializedLibrary
            {
                Procedures = {
                    new Procedure_v1 { 
                        Name="foo",
                        Signature = new SerializedSignature
                        {
                            Convention="__cdecl",
                            ReturnValue = new Argument_v1 {
                                Type = new VoidType_v1()
                            },
                        }
                    }
                }
            };
            var lib = tlLdr.Load(slib);

            mr.VerifyAll();
            Assert.AreEqual(
                "void foo()",
                lib.Lookup("foo").ToString("foo"));
        }