示例#1
0
        public void StReadStruct()
        {
            StructType_v1 str = new StructType_v1
            {
                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("</Struc");

            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(StructType_v1));
            StructType_v1 destr = (StructType_v1)deser.Deserialize(rdr);
        }
 public SerializedType VisitComplexType(ComplexTypeSpec complexType)
 {
     if (complexType.Type == CTokenType.Struct)
     {
         if (complexType.Name == null || symbolTable.StructsSeen.TryGetValue(complexType.Name, out var str))
         {
             str = new StructType_v1
             {
                 Name = complexType.Name ?? $"struct_{symbolTable.StructsSeen.Count}"
             };
             symbolTable.StructsSeen.Add(str.Name, str);
         }
         else
         {
             str = new StructType_v1 {
                 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 StructType_v1 {
                 Name = str.Name
             };
         }
         return(str);
     }
     else if (complexType.Type == CTokenType.Union)
     {
         if (complexType.Name == null || !symbolTable.UnionsSeen.TryGetValue(complexType.Name, out var 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();
     }
 }
 public DataType VisitStructure(StructType_v1 structure)
 {
     if (structure.Name == null || !structures.TryGetValue(structure.Name, out var str))
     {
         str = new StructureType(structure.Name, structure.ByteSize, true);
         str.ForceStructure = structure.ForceStructure;
         if (structure.Name != null)
         {
             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 if (str.Fields.Count == 0 && structure.Fields != null)
     {
         // Forward reference resolved.
         var fields = structure.Fields.Select(
             f => new StructureField(
                 f.Offset,
                 f.Type.Accept(this),
                 f.Name));
         str.Fields.AddRange(fields);
         return(str);
     }
     else
     {
         return(str);
     }
 }
示例#4
0
		public void StReadStruct()
		{
			StructType_v1 str = new StructType_v1
            {
			    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("</Struc");
			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(StructType_v1));
			StructType_v1 destr = (StructType_v1) deser.Deserialize(rdr);
		}
示例#5
0
		public void StWriteStruct()
		{
            StructType_v1 str = new StructType_v1
            {
                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());
		}
示例#6
0
        public void StWriteStruct()
        {
            StructType_v1 str = new StructType_v1
            {
                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());
        }
示例#7
0
        public int VisitStructure(StructType_v1 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);
        }
示例#8
0
        private void BuildStructure(Structure st, StructType_v1 str)
        {
            var fieldTypes =
                (object[])dictionary[st.TypeList].Leaves[0];
            var fieldNamesOffsets =
                (object[])dictionary[st.NameOffsetList].Leaves[0];

            if (2 * fieldTypes.Length != fieldNamesOffsets.Length ||
                fieldTypes.Length != st.FieldCount)
            {
                throw new FormatException();
            }
            var fields = new StructField_v1[st.FieldCount];

            for (int i = 0; i < st.FieldCount; ++i)
            {
                var type   = TranslateType(Convert.ToInt32(fieldTypes[i]));
                var name   = (string)fieldNamesOffsets[i * 2];
                var offset = Convert.ToInt32(fieldNamesOffsets[i * 2 + 1]);
                fields[i] = new StructField_v1(offset, name, type);
            }
            str.Fields   = fields;
            str.ByteSize = (st.BitSize + 7) / 8;
        }
示例#9
0
 public StringBuilder VisitStructure(StructType_v1 structure)
 {
     throw new NotImplementedException();
 }
示例#10
0
 public DataType VisitStructure(StructType_v1 structure)
 {
     throw new NotImplementedException();
 }
示例#11
0
 public DataType VisitStructure(StructType_v1 structure)
 {
     return(new StructureType(structure.Name, 0));
 }
示例#12
0
        public bool VisitStructure(StructType_v1 sX)
        {
            var sY = (StructType_v1)y !;

            return(sX.Name == sY.Name && sX.Name != null);
        }
示例#13
0
 public StringBuilder VisitStructure(StructType_v1 structure)
 {
     sb.Append(structure.Name);
     return(sb);
 }