Esempio n. 1
0
        private void ReadSectionMixedMarshallingRelocationsInternal(Section section, Stream relocationsStream)
        {
#if DEBUG_GR2_SERIALIZATION
            System.Console.WriteLine(String.Format(" ===== Mixed marshalling relocations for section at {0:X8} ===== ", section.Header.offsetInFile));
#endif

            using (var relocationsReader = new BinaryReader(relocationsStream, Encoding.Default, true))
            {
                for (int i = 0; i < section.Header.numMixedMarshallingData; i++)
                {
                    UInt32 count           = relocationsReader.ReadUInt32();
                    UInt32 offsetInSection = relocationsReader.ReadUInt32();
                    Debug.Assert(offsetInSection <= section.Header.uncompressedSize);
                    var type     = ReadSectionReference(relocationsReader);
                    var typeDefn = new StructReference();
                    typeDefn.Offset = Sections[(int)type.Section].Header.offsetInFile + type.Offset;

                    Seek(section, offsetInSection);
                    MixedMarshal(count, typeDefn.Resolve(this));

#if DEBUG_GR2_SERIALIZATION
                    System.Console.WriteLine(String.Format("    {0:X8} [{1}] --> {2}:{3:X8}", offsetInSection, count, (SectionType)type.Section, type.Offset));
#endif
                }
            }
        }
Esempio n. 2
0
        public void Read(object root)
        {
            using (this.InputReader = new BinaryReader(InputStream))
            {
                Magic = ReadMagic();

                if (Magic.format != Magic.Format.LittleEndian32 && Magic.format != Magic.Format.LittleEndian64)
                {
                    throw new ParsingException("Only little-endian GR2 files are supported");
                }

                Header = ReadHeader();
                for (int i = 0; i < Header.numSections; i++)
                {
                    var section = new Section();
                    section.Header = ReadSectionHeader();
                    Sections.Add(section);
                }

                Debug.Assert(InputStream.Position == Magic.headersSize);

                UncompressStream();

                foreach (var section in Sections)
                {
                    ReadSectionRelocations(section);
                }

                if (Magic.IsLittleEndian != BitConverter.IsLittleEndian)
                {
                    // TODO: This should be done before applying relocations?
                    foreach (var section in Sections)
                    {
                        ReadSectionMixedMarshallingRelocations(section);
                    }
                }

                var rootStruct = new StructReference();
                rootStruct.Offset = Sections[(int)Header.rootType.Section].Header.offsetInFile + Header.rootType.Offset;

                Seek(Header.rootNode);
                ReadStruct(rootStruct.Resolve(this), MemberType.Inline, root, null);
            }
        }
Esempio n. 3
0
        public UInt32 Size(GR2Reader gr2)
        {
            switch (Type)
            {
            case MemberType.Inline:
                return(Definition.Resolve(gr2).Size(gr2));

            case MemberType.Int8:
            case MemberType.BinormalInt8:
            case MemberType.UInt8:
            case MemberType.NormalUInt8:
                return(1);

            case MemberType.Int16:
            case MemberType.BinormalInt16:
            case MemberType.UInt16:
            case MemberType.NormalUInt16:
                return(2);

            case MemberType.Reference:
            case MemberType.String:
            case MemberType.Real32:
            case MemberType.Int32:
            case MemberType.UInt32:
                return(4);

            case MemberType.VariantReference:
            case MemberType.ArrayOfReferences:
            case MemberType.ReferenceToArray:
                return(8);

            case MemberType.ReferenceToVariantArray:
                return(12);

            case MemberType.Transform:
                return(17 * 4);

            default:
                throw new ParsingException(String.Format("Unhandled member type: {0}", Type.ToString()));
            }
        }
Esempio n. 4
0
        private void ReadSectionMixedMarshallingRelocations(Section section)
        {
#if DEBUG_GR2_SERIALIZATION
            System.Console.WriteLine(String.Format(" ===== Mixed marshalling relocations for section at {0:X8} ===== ", section.Header.offsetInFile));
#endif

            InputStream.Seek(section.Header.mixedMarshallingDataOffset, SeekOrigin.Begin);
            for (int i = 0; i < section.Header.numMixedMarshallingData; i++)
            {
                UInt32 count           = InputReader.ReadUInt32();
                UInt32 offsetInSection = InputReader.ReadUInt32();
                Debug.Assert(offsetInSection <= section.Header.uncompressedSize);
                var type     = ReadSectionReference();
                var typeDefn = new StructReference();
                typeDefn.Offset = Sections[(int)type.Section].Header.offsetInFile + type.Offset;

                Seek(section, offsetInSection);
                MixedMarshal(count, typeDefn.Resolve(this));

#if DEBUG_GR2_SERIALIZATION
                System.Console.WriteLine(String.Format("    {0:X8} [{1}] --> {2}:{3:X8}", offsetInSection, count, (SectionType)type.Section, type.Offset));
#endif
            }
        }