Exemplo n.º 1
0
        public void StReadStruct()
        {
            SerializedStructType str = new SerializedStructType
            {
                ByteSize = 32,
                Fields = new StructField_v1 []
                {
                    new StructField_v1(0, null, new PrimitiveType_v1(Domain.SignedInt, 4)),
                    new StructField_v1(4, null, new PrimitiveType_v1(Domain.Real, 8)),
                }
            };
            StringWriter writer = new StringWriter();
            XmlTextWriter x = new XmlTextWriter(writer);
            x.Formatting = Formatting.None;
            XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(str.GetType());
            ser.Serialize(x, str);

            string s = writer.ToString();
            int b = s.IndexOf("<field");
            int e = s.IndexOf("</Ser");
            Assert.AreEqual(
                "<field offset=\"0\"><prim domain=\"SignedInt\" size=\"4\" xmlns=\"http://schemata.jklnet.org/Decompiler\" /></field>" +
                "<field offset=\"4\"><prim domain=\"Real\" size=\"8\" xmlns=\"http://schemata.jklnet.org/Decompiler\" /></field>",
                s.Substring(b, e-b));
            StringReader rdr = new StringReader(s);
            XmlSerializer deser = SerializedLibrary.CreateSerializer_v1(typeof(SerializedStructType));
            SerializedStructType destr = (SerializedStructType) deser.Deserialize(rdr);
        }
Exemplo n.º 2
0
        public void StReadStruct()
        {
            SerializedStructType str = new SerializedStructType
            {
                ByteSize = 32,
                Fields   = new StructField_v1 []
                {
                    new StructField_v1(0, null, new PrimitiveType_v1(Domain.SignedInt, 4)),
                    new StructField_v1(4, null, new PrimitiveType_v1(Domain.Real, 8)),
                }
            };
            StringWriter  writer = new StringWriter();
            XmlTextWriter x      = new XmlTextWriter(writer);

            x.Formatting = Formatting.None;
            XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(str.GetType());

            ser.Serialize(x, str);

            string s = writer.ToString();
            int    b = s.IndexOf("<field");
            int    e = s.IndexOf("</Ser");

            Assert.AreEqual(
                "<field offset=\"0\"><prim domain=\"SignedInt\" size=\"4\" xmlns=\"http://schemata.jklnet.org/Decompiler\" /></field>" +
                "<field offset=\"4\"><prim domain=\"Real\" size=\"8\" xmlns=\"http://schemata.jklnet.org/Decompiler\" /></field>",
                s.Substring(b, e - b));
            StringReader         rdr   = new StringReader(s);
            XmlSerializer        deser = SerializedLibrary.CreateSerializer_v1(typeof(SerializedStructType));
            SerializedStructType destr = (SerializedStructType)deser.Deserialize(rdr);
        }
Exemplo n.º 3
0
		public void StWriteStruct()
		{
            SerializedStructType str = new SerializedStructType
            {
                Fields = new StructField_v1[] {
                    new StructField_v1(0, null, new PrimitiveType_v1(Domain.UnsignedInt, 4)),
			        new StructField_v1(4, null, new PrimitiveType_v1(Domain.Real, 8)),
                }
            };
			Assert.AreEqual("struct((0, ?, prim(UnsignedInt,4))(4, ?, prim(Real,8)))", str.ToString());
		}
Exemplo n.º 4
0
        public void StWriteStruct()
        {
            SerializedStructType str = new SerializedStructType
            {
                Fields = new StructField_v1[] {
                    new StructField_v1(0, null, new PrimitiveType_v1(Domain.UnsignedInt, 4)),
                    new StructField_v1(4, null, new PrimitiveType_v1(Domain.Real, 8)),
                }
            };

            Assert.AreEqual("struct((0, ?, prim(UnsignedInt,4))(4, ?, prim(Real,8)))", str.ToString());
        }
Exemplo n.º 5
0
        public int VisitStructure(SerializedStructType structure)
        {
            var size = 0;

            if (structure.Fields == null)
            {
                this.tagSizes.TryGetValue(structure, out size);
                return(size);
            }
            foreach (var field in structure.Fields)
            {
                size += field.Type.Accept(this);
            }
            return(size);
        }
Exemplo n.º 6
0
        public DataType VisitStructure(SerializedStructType structure)
        {
            StructureType str;

            if (!structures.TryGetValue(structure.Name, out str))
            {
                str = new StructureType(structure.Name, structure.ByteSize);
                structures.Add(structure.Name, str);
                if (structure.Fields != null)
                {
                    var fields = structure.Fields.Select(f => new StructureField(f.Offset, f.Type.Accept(this), f.Name));
                    str.Fields.AddRange(fields);
                }
                return(str);
            }
            else
            {
                return(new TypeReference(str));
            }
        }
Exemplo n.º 7
0
        public bool VisitStructure(SerializedStructType sX)
        {
            var sY = (SerializedStructType)y;

            return(sX.Name == sY.Name && sX.Name != null);
        }
Exemplo n.º 8
0
 public SerializedType VisitComplexType(ComplexTypeSpec complexType)
 {
     if (complexType.Type == CTokenType.Struct)
     {
         SerializedStructType str;
         if (complexType.Name == null || symbolTable.StructsSeen.TryGetValue(complexType.Name, out str))
         {
             str = new SerializedStructType {
                 Name = complexType.Name != null
                     ? complexType.Name
                     : string.Format("struct_{0}", symbolTable.StructsSeen.Count)
             };
             symbolTable.StructsSeen.Add(str.Name, str);
         }
         else
         {
             str = new SerializedStructType {
                 Name = complexType.Name
             };
         }
         if (!complexType.IsForwardDeclaration() && str.Fields == null)
         {
             str.Fields = ExpandStructFields(complexType.DeclList).ToArray();
             symbolTable.Sizer.SetSize(str);
             symbolTable.Types.Add(str);
             str = new SerializedStructType {
                 Name = str.Name
             };
         }
         return(str);
     }
     else if (complexType.Type == CTokenType.Union)
     {
         UnionType_v1 un;
         if (complexType.Name == null || !symbolTable.UnionsSeen.TryGetValue(complexType.Name, out un))
         {
             un = new UnionType_v1 {
                 Name = complexType.Name
             };
             if (un.Name != null)
             {
                 symbolTable.UnionsSeen.Add(un.Name, un);
             }
         }
         if (!complexType.IsForwardDeclaration() && un.Alternatives == null)
         {
             un.Alternatives = ExpandUnionFields(complexType.DeclList).ToArray();
             symbolTable.Sizer.SetSize(un);
             if (un.Name != null)
             {
                 symbolTable.Types.Add(un);
                 un = new UnionType_v1 {
                     Name = un.Name
                 };
             }
         }
         return(un);
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Exemplo n.º 9
0
 public StringBuilder VisitStructure(SerializedStructType structure)
 {
     throw new NotImplementedException();
 }