Exemple #1
0
        private void LoadHeader(byte[] header)
        {
            if (header.Length < 4)
            {
                throw new InvalidDataException("NAR header is invalid.");
            }
            int version = BitConverter.ToInt32(header, 0);

            if (version != 1)
            {
                throw new InvalidDataException("NAR header version is invalid.");
            }
            if (header.Length < 16)
            {
                throw new InvalidDataException("NAR header is invalid.");
            }
            BitConverter.ToInt32(header, 4);
            BitConverter.ToInt32(header, 8);
            BitConverter.ToInt32(header, 12);
            int directoryCount = BitConverter.ToInt32(header, 16);

            if (directoryCount < 0)
            {
                throw new InvalidDataException("Directory entry count is too large.");
            }
            int entryOffset = 20;

            for (int i = 0; i < directoryCount; i++)
            {
                NexonArchiveFileEntry fileEntry = new NexonArchiveFileEntry(this);
                entryOffset += fileEntry.Load(header, entryOffset);
                this.fileEntries.Add(fileEntry);
            }
        }
Exemple #2
0
        internal int Load(byte[] header, int offset)
        {
            int result;

            try
            {
                int pathSize = (int)BitConverter.ToUInt16(header, offset);
                this.path             = Encoding.ASCII.GetString(header, offset + 2, pathSize);
                this.storedType       = (NexonArchiveFileEntryType)BitConverter.ToInt32(header, offset + 2 + pathSize);
                this.offset           = (long)((ulong)BitConverter.ToUInt32(header, offset + 2 + pathSize + 4));
                this.storedSize       = (long)BitConverter.ToInt32(header, offset + 2 + pathSize + 8);
                this.extractedSize    = (long)BitConverter.ToInt32(header, offset + 2 + pathSize + 12);
                this.lastModifiedTime = NexonArchiveFileEntry.FromEpoch(BitConverter.ToInt32(header, offset + 2 + pathSize + 16));
                this.checksum         = BitConverter.ToUInt32(header, offset + 2 + pathSize + 20);
                result = 2 + pathSize + 24;
            }
            catch (ArgumentOutOfRangeException ex)
            {
                throw new InvalidDataException("NAR file entry is invalid.", ex);
            }
            return(result);
        }