Beispiel #1
0
        private void ReadHeader()
        {
            this.binaryReader = new BinaryReader(this.BaseStream);

            // Skip the first 100 bytes. Signature, perhaps?
            this._signature = this.binaryReader.ReadBytes(100);

            this.filecount = CmfHelper.Decode(binaryReader.ReadUInt32(), CmfFormat.EntryKey1);

            this.headeroffsetStart = this.BaseStream.Position;

            this.dataoffsetStart = this.BaseStream.Position + (CmfFormat.FileHeaderSize * this.filecount);
        }
Beispiel #2
0
        public bool MoveNext()
        {
            if (this.currentCount < this.sourceArchive.FileCount)
            {
                if (this.myEntry == null)
                {
                    this.myEntry = new CMFEntry();
                }
                this.sourceArchive.BaseStream.Seek(this.currentPos, SeekOrigin.Begin);

                int readcount = this.br.Read(this.buffer, 0, this.buffer.Length);
                if (readcount == this.buffer.Length)
                {
                    this.myEntry.headeroffset = (int)this.currentPos;
                    // Decode the buffer.
                    CmfHelper.Decode(ref this.buffer);

                    // First 512 bytes is the filename
                    string tmp_filename = Encoding.ASCII.GetString(this.buffer, 0, CmfFormat.FileHeaderNameSize);

                    // This doesn't look good.
                    int indexofNull = tmp_filename.IndexOf("\0\0");
                    if (tmp_filename.IndexOf("\0\0") == -1)
                    {
                        indexofNull  = tmp_filename.LastIndexOf('\0');
                        tmp_filename = Encoding.ASCII.GetString(this.buffer, 0, indexofNull);
                    }
                    else
                    {
                        this.myEntry._filename = Encoding.Unicode.GetString(this.buffer, 0, indexofNull + 1);
                    }

                    this.myEntry._filename = this.myEntry._filename.RemoveNullChar();

                    // Next is 4 bytes for the unpacked size (aka original file)
                    this.myEntry._unpackedsize = BitConverter.ToInt32(this.buffer, 512);

                    // Next is another 4 bytes for compressedsize
                    this.myEntry._compressedsize = BitConverter.ToInt32(this.buffer, 516);

                    // Next is another 4 bytes for "DataOffset"
                    this.myEntry.dataoffset = BitConverter.ToInt32(this.buffer, 520);

                    // if (str == "FX" || str == "LUA" || str == "TET" || str == "XET")

                    // Last is the flag, determine if the file is compressed (with Zlib) or encrypted or nothing special.
                    switch (BitConverter.ToInt32(this.buffer, 524))
                    {
                    case 1:
                        this.myEntry._iscompressed = true;
                        break;

                    case 2:
                        this.myEntry._isencrypted = true;
                        break;
                    }
                }

                this.currentPos += readcount;

                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #3
0
        private ReadOnlyCollection <CMFEntry> ReadEntryList()
        {
            this.BaseStream.Seek(this.headeroffsetStart, SeekOrigin.Begin);

            /*
             * File table has fixed row size 528 bytes.
             * string(512):Filename - int(4):FileSize - int(4):CompressedFileSize - int(4):FileOffset - int(4):Flag
             */
            // CmfFormat.FileHeaderSize

            CMFEntry[] entryList = new CMFEntry[this.filecount];
            string     tmp_filename;

            byte[]   bytebuffer = new byte[CmfFormat.FileHeaderSize];
            int      readcount, indexofNull;
            int      offset = (int)this.BaseStream.Position;
            CMFEntry currentCMFEntry;

            for (int i = 0; i < entryList.Length; i++)
            {
                tmp_filename    = null;
                currentCMFEntry = new CMFEntry();

                readcount = this.binaryReader.Read(bytebuffer, 0, bytebuffer.Length);
                if (readcount == bytebuffer.Length)
                {
                    currentCMFEntry.headeroffset = offset;
                    // Decode the buffer.
                    CmfHelper.Decode(ref bytebuffer);

                    // First 512 bytes is the filename
                    tmp_filename = Encoding.ASCII.GetString(bytebuffer, 0, CmfFormat.FileHeaderNameSize);

                    // This doesn't look good.
                    indexofNull = tmp_filename.IndexOf("\0\0");
                    if (tmp_filename.IndexOf("\0\0") == -1)
                    {
                        indexofNull  = tmp_filename.LastIndexOf('\0');
                        tmp_filename = Encoding.ASCII.GetString(bytebuffer, 0, indexofNull);
                    }
                    else
                    {
                        currentCMFEntry._filename = Encoding.Unicode.GetString(bytebuffer, 0, indexofNull + 1);
                    }

                    currentCMFEntry._filename = currentCMFEntry._filename.RemoveNullChar();

                    // Next is 4 bytes for the unpacked size (aka original file)
                    currentCMFEntry._unpackedsize = BitConverter.ToInt32(bytebuffer, 512);

                    // Next is another 4 bytes for compressedsize
                    currentCMFEntry._compressedsize = BitConverter.ToInt32(bytebuffer, 516);

                    // Next is another 4 bytes for "DataOffset"
                    currentCMFEntry.dataoffset = BitConverter.ToInt32(bytebuffer, 520);

                    // if (str == "FX" || str == "LUA" || str == "TET" || str == "XET")

                    // Last is the flag, determine if the file is compressed (with Zlib) or encrypted or nothing special.
                    switch (BitConverter.ToInt32(bytebuffer, 524))
                    {
                    case 1:
                        currentCMFEntry._iscompressed = true;
                        break;

                    case 2:
                        currentCMFEntry._isencrypted = true;
                        break;
                    }
                    entryList[i] = currentCMFEntry;
                }
                offset += readcount;
            }

            return(new ReadOnlyCollection <CMFEntry>(entryList));
        }