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 } } }
public StructReference ReadStructReference() { var reference = new StructReference(); if (Magic.Is32Bit) { reference.Offset = Reader.ReadUInt32(); } else { reference.Offset = Reader.ReadUInt64(); } return(reference); }
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); } }
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 } }