예제 #1
0
        private static ModuleFileHeaderStruct ReadAndValidateFileHeader(BinaryReader reader)
        {
            var header = new ModuleFileHeaderStruct();

            header.Read(reader);
            ValidateHeader(header);
            return(header);
        }
예제 #2
0
        private static int[] ReadResourceEntries(BinaryReader reader, ModuleFileHeaderStruct header)
        {
            var files = new int[header.ResourceCount];

            for (var i = 0; i < header.ResourceCount; i++)
            {
                files[i] = reader.ReadInt32();
            }
            return(files);
        }
예제 #3
0
 private static void ValidateHeader(ModuleFileHeaderStruct header)
 {
     if (header.Magic != ModuleFileHeaderStruct.ExpectedMagic)
     {
         throw new InvalidDataException($"Invalid module magic {header.Magic}");
     }
     if (header.Version != ModuleFileHeaderStruct.ExpectedVersion)
     {
         throw new InvalidDataException($"Unsupported module version {header.Version}");
     }
 }
예제 #4
0
        private static ModuleEntryStruct[] ReadFileEntries(BinaryReader reader, ModuleFileHeaderStruct header)
        {
            var entries = new ModuleEntryStruct[header.FileCount];

            for (var i = 0; i < header.FileCount; i++)
            {
                var entry = new ModuleEntryStruct();
                entry.Read(reader);
                entries[i] = entry;
            }
            return(entries);
        }
예제 #5
0
        private static ModuleCompressedBlockStruct[] ReadCompressedBlocks(BinaryReader reader, ModuleFileHeaderStruct header)
        {
            var blocks = new ModuleCompressedBlockStruct[header.CompressedBlockCount];

            for (var i = 0; i < header.CompressedBlockCount; i++)
            {
                var block = new ModuleCompressedBlockStruct();
                block.Read(reader);
                blocks[i] = block;
            }
            return(blocks);
        }
예제 #6
0
        private static StringBlob ReadStringTable(BinaryReader reader, ModuleFileHeaderStruct header)
        {
            var bytes = reader.ReadBytes((int)header.StringTableSize);

            return(new StringBlob(Encoding.UTF8, bytes));
        }