Esempio n. 1
0
        /// <summary>
        /// Reads the V3 attribute headers for the LSOF resource
        /// </summary>
        /// <param name="s">Stream to read the attribute headers from</param>
        private void ReadAttributesV3(Stream s)
        {
            Attributes = new List<AttributeInfo>();
            using (var reader = new BinaryReader(s))
            {
                while (s.Position < s.Length)
                {
                    var attribute = BinUtils.ReadStruct<AttributeEntryV3>(reader);

                    var resolved = new AttributeInfo();
                    resolved.NameIndex = attribute.NameIndex;
                    resolved.NameOffset = attribute.NameOffset;
                    resolved.TypeId = attribute.TypeId;
                    resolved.Length = attribute.Length;
                    resolved.DataOffset = attribute.Offset;
                    resolved.NextAttributeIndex = attribute.NextAttributeIndex;

                    Attributes.Add(resolved);
                }

#if DEBUG_LSF_SERIALIZATION
                Console.WriteLine(" ----- DUMP OF V3 ATTRIBUTE TABLE -----");
                for (int i = 0; i < Attributes.Count; i++)
                {
                    var resolved = Attributes[i];

                    var debug = String.Format(
                        "{0}: {1} (offset {2:X}, typeId {3}, nextAttribute {4})",
                        i, Names[resolved.NameIndex][resolved.NameOffset], resolved.DataOffset,
                        resolved.TypeId, resolved.NextAttributeIndex
                    );
                    Console.WriteLine(debug);
                }
#endif
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Reads the V2 attribute headers for the LSOF resource
        /// </summary>
        /// <param name="s">Stream to read the attribute headers from</param>
        private void ReadAttributesV2(Stream s)
        {
            Attributes = new List<AttributeInfo>();
            using (var reader = new BinaryReader(s))
            {
#if DEBUG_LSF_SERIALIZATION
                var rawAttributes = new List<AttributeEntryV2>();
#endif

                var prevAttributeRefs = new List<Int32>();
                UInt32 dataOffset = 0;
                Int32 index = 0;
                while (s.Position < s.Length)
                {
                    var attribute = BinUtils.ReadStruct<AttributeEntryV2>(reader);

                    var resolved = new AttributeInfo();
                    resolved.NameIndex = attribute.NameIndex;
                    resolved.NameOffset = attribute.NameOffset;
                    resolved.TypeId = attribute.TypeId;
                    resolved.Length = attribute.Length;
                    resolved.DataOffset = dataOffset;
                    resolved.NextAttributeIndex = -1;

                    var nodeIndex = attribute.NodeIndex + 1;
                    if (prevAttributeRefs.Count > nodeIndex)
                    {
                        if (prevAttributeRefs[nodeIndex] != -1)
                        {
                            Attributes[prevAttributeRefs[nodeIndex]].NextAttributeIndex = index;
                        }

                        prevAttributeRefs[nodeIndex] = index;
                    }
                    else
                    {
                        while (prevAttributeRefs.Count < nodeIndex)
                        {
                            prevAttributeRefs.Add(-1);
                        }

                        prevAttributeRefs.Add(index);
                    }

#if DEBUG_LSF_SERIALIZATION
                    rawAttributes.Add(attribute);
#endif

                    dataOffset += resolved.Length;
                    Attributes.Add(resolved);
                    index++;
                }

#if DEBUG_LSF_SERIALIZATION
                Console.WriteLine(" ----- DUMP OF ATTRIBUTE REFERENCES -----");
                for (int i = 0; i < prevAttributeRefs.Count; i++)
                {
                    Console.WriteLine(String.Format("Node {0}: last attribute {1}", i, prevAttributeRefs[i]));
                }


                Console.WriteLine(" ----- DUMP OF V2 ATTRIBUTE TABLE -----");
                for (int i = 0; i < Attributes.Count; i++)
                {
                    var resolved = Attributes[i];
                    var attribute = rawAttributes[i];

                    var debug = String.Format(
                        "{0}: {1} (offset {2:X}, typeId {3}, nextAttribute {4}, node {5})",
                        i, Names[resolved.NameIndex][resolved.NameOffset], resolved.DataOffset,
                        resolved.TypeId, resolved.NextAttributeIndex, attribute.NodeIndex
                    );
                    Console.WriteLine(debug);
                }
#endif
            }
        }