Example #1
0
        public void Convert()
        {
            var lexer = new CLexer(rdr);
            var parser = new CParser(parserState, lexer);
            var declarations = parser.Parse();
            var symbolTable = new SymbolTable(platform)
            {
                NamedTypes = {
                    { "off_t", new PrimitiveType_v1 { Domain = Domain.SignedInt, ByteSize = 4 } },          //$BUGBUG: arch-dependent!
                    { "ssize_t", new PrimitiveType_v1 { Domain = Domain.SignedInt, ByteSize = 4 } },        //$BUGBUG: arch-dependent!
                    { "size_t", new PrimitiveType_v1 { Domain = Domain.UnsignedInt, ByteSize = 4 } },       //$BUGBUG: arch-dependent!
                    { "va_list", new PrimitiveType_v1 { Domain = Domain.Pointer, ByteSize = platform.PointerType.Size } }
                }
            };

            foreach (var decl in declarations)
            {
                symbolTable.AddDeclaration(decl);
            }

            var lib = new SerializedLibrary
            {
                Types = symbolTable.Types.ToArray(),
                Procedures = symbolTable.Procedures.ToList(),
            };
            var ser = SerializedLibrary.CreateSerializer();
            ser.Serialize(writer, lib);
        }
 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 lib = TypeLibrary.Load(new IntelArchitecture(ProcessorMode.Protected32), slib);
     Assert.AreEqual(PrimitiveType.Int32, lib.LookupType("int"));
 }
Example #3
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"));
 }
Example #4
0
        /// <summary>
        /// Loads an image map from a file containing the XML description of the
        /// segments inside.
        /// <param name="svc"></param>
        /// <param name="mmapFileName"></param>
        /// <param name="platform"></param>
        /// <returns></returns>
        public static MemoryMap_v1 LoadMemoryMapFromFile(IServiceProvider svc, string mmapFileName, IPlatform platform)
        {
            var cfgSvc  = svc.RequireService <IConfigurationService>();
            var fsSvc   = svc.RequireService <IFileSystemService>();
            var diagSvc = svc.RequireService <IDiagnosticsService>();

            try
            {
                var filePath = cfgSvc.GetInstallationRelativePath(mmapFileName);
                var ser      = SerializedLibrary.CreateSerializer(
                    typeof(MemoryMap_v1),
                    SerializedLibrary.Namespace_v4);
                using (var stm = fsSvc.CreateFileStream(filePath, FileMode.Open))
                {
                    var mmap = (MemoryMap_v1)ser.Deserialize(stm);
                    return(mmap);
                }
            }
            catch (Exception ex)
            {
                diagSvc.Error(ex, string.Format("Unable to open memory map file '{0}.", mmapFileName));
                return(null);
            }
        }
Example #5
0
        public void Tlldr_bothordinalandname()
        {
            Given_ArchitectureStub();
            mr.ReplayAll();
            var tlLDr = new TypeLibraryLoader(platform, true);
            var slib = new SerializedLibrary {
                Procedures = {
                    new Procedure_v1 {
                        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.ServicesByVector.Count);
            Assert.IsNotNull(lib.ServicesByVector[2]);
        }
Example #6
0
        public void Save(Project_v5 sProject, XmlWriter xw)
        {
            var ser = SerializedLibrary.CreateSerializer_v5(typeof(Project_v5));

            ser.Serialize(xw, sProject);
        }
Example #7
0
		public void SlibWriteOneProcedure()
		{
			var slib = new SerializedLibrary();
			slib.Procedures.Add(MkMalloc());
			Verify(slib, "Core/SlibWriteOneProcedure.txt");
		}
Example #8
0
		private void Verify(SerializedLibrary slib, string outputFile)
		{
			using (FileUnitTester fut = new FileUnitTester(outputFile))
			{
				XmlTextWriter writer = new FilteringXmlWriter(fut.TextWriter);
				writer.Formatting = Formatting.Indented;
                XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(slib.GetType());
				ser.Serialize(writer, slib);

				fut.AssertFilesEqual();
			}
		}
Example #9
0
 public static TypeLibrary Load(Platform platform, SerializedLibrary slib)
 {
     var tlldr = new TypeLibraryLoader(platform, true);
     var tlib = tlldr.Load(slib);
     return tlib;
 }
Example #10
0
        public void Save(Project_v2 project, TextWriter sw)
        {
            XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(typeof(Project_v2));

            ser.Serialize(sw, project);
        }
Example #11
0
        public void Save(Project_v4 sProject, TextWriter sw)
        {
            var ser = SerializedLibrary.CreateSerializer_v4(typeof(Project_v4));

            ser.Serialize(sw, sProject);
        }
        public void Tlldr_typedef_ptr_int()
        {
            Given_ArchitectureStub();
            Given_Arch_PointerDataType(PrimitiveType.Pointer32);
            mr.ReplayAll();

            var tlLdr = new TypeLibraryLoader(arch, true);
            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_typedef_int()
        {
            Given_ArchitectureStub();
            mr.ReplayAll();

            var tlLdr = new TypeLibraryLoader(arch, true);
            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_void_fn()
        {
            Given_ArchitectureStub();
            mr.ReplayAll();

            var tlLdr = new TypeLibraryLoader(arch, true);
            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"));
        }
Example #15
0
 public static TypeLibrary Load(IProcessorArchitecture arch, SerializedLibrary slib)
 {
     var tlldr = new TypeLibraryLoader(arch, true);
     var tlib = tlldr.Load(slib);
     return tlib;
 }
        public void Tlldr_BothOrdinalAndName()
        {
            Given_ArchitectureStub();
            Given_ProcedureSignature(new FunctionType());
            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]);
        }