Example #1
0
 public byte[] ReadFile(MYP.MFTEntry entry)
 {
     if ((int)entry.Compressed == 1)
     {
         byte[] buffer = new byte[(int)entry.UnCompressedSize];
         this._stream.Position = (long)entry.Offset + (long)entry.HeaderSize + 2L;
         MemoryStream memoryStream = new MemoryStream(buffer);
         using (DeflateStream deflateStream = new DeflateStream(this._stream, CompressionMode.Decompress, true))
             deflateStream.Read(buffer, 0, buffer.Length);
         return(buffer);
     }
     byte[] buffer1 = new byte[(int)entry.CompressedSize];
     this._stream.Position = (long)entry.Offset + (long)entry.HeaderSize;
     this._stream.Read(buffer1, 0, (int)entry.CompressedSize);
     return(buffer1);
 }
Example #2
0
        public MYP(MythicPackage package, Stream stream)
        {
            this._stream = stream;
            this.Package = package;
            BinaryReader reader = new BinaryReader(stream);

            this.Header = new MYP.MYPHeader();
            this.Header.Load(reader);
            this.MFTTables.Add(new MYP.MFTHeader()
            {
                Length        = this.Header.EntriesPerMFT,
                NextMFTOffset = this.Header.MFTOffset
            });
            long num1 = this.Header.MFTOffset;
            uint num2 = this.Header.EntriesPerMFT;

            reader.BaseStream.Position = num1;
            while (num1 > 0L)
            {
                reader.BaseStream.Position = num1;
                this.MFT        = new MYP.MFTHeader();
                this.MFT.Offset = reader.BaseStream.Position;
                this.MFT.Load(reader);
                this.MFTTables.Add(this.MFT);
                num1 = this.MFT.NextMFTOffset;
                for (int index = 0; (long)index < (long)num2; ++index)
                {
                    MYP.MFTEntry mftEntry = new MYP.MFTEntry();
                    mftEntry.Changed = false;
                    mftEntry.Load(this, reader, index);
                    if (mftEntry.Hash != 0L)
                    {
                        this.Enteries[mftEntry.Hash] = mftEntry;
                    }
                }
                num2 = this.MFT.Length;
            }
        }
Example #3
0
        public void AddEntries(List <Tuple <string, byte[]> > files)
        {
            this._stream.Position = 24L;
            BinaryWriter binaryWriter = new BinaryWriter(this._stream);

            binaryWriter.Write((long)(uint)this.Enteries.Count + (long)files.Count);
            if (this.MFTTables.Count > 0)
            {
                this._stream.Position = this.MFTTables.Last <MYP.MFTHeader>().Offset + 4L;
                binaryWriter.Write((ulong)binaryWriter.BaseStream.Length);
            }
            binaryWriter.BaseStream.Position = binaryWriter.BaseStream.Length;
            int index1 = 0;
            List <MYP.MFTEntry> mftEntryList = new List <MYP.MFTEntry>();
            int  count = files.Count;
            long num1  = 0;

            while (count > 0)
            {
                binaryWriter.Write(1000U);
                if (files.Count - index1 > 1000)
                {
                    num1 = this._stream.Position;
                    binaryWriter.Write(0L);
                }
                else
                {
                    binaryWriter.Write(0L);
                }
                for (int index2 = 0; index2 < 1000; ++index2)
                {
                    if (index1 < files.Count)
                    {
                        --count;
                        MYP.MFTEntry mftEntry     = new MYP.MFTEntry();
                        MemoryStream memoryStream = new MemoryStream();
                        using (DeflateStream deflateStream = new DeflateStream((Stream)memoryStream, CompressionMode.Compress, true))
                            deflateStream.Write(files[index1].Item2, 0, files[index1].Item2.Length);
                        mftEntry.Data    = new byte[memoryStream.Length + 2L];
                        mftEntry.Data[0] = (byte)120;
                        mftEntry.Data[1] = (byte)156;
                        Buffer.BlockCopy((Array)memoryStream.ToArray(), 0, (Array)mftEntry.Data, 2, (int)memoryStream.Length);
                        mftEntry.CompressedSize   = (uint)mftEntry.Data.Length;
                        mftEntry.Hash             = MYP.HashWAR(files[index1].Item1);
                        mftEntry.CRC32            = CRC32.ComputeChecksum(files[index1].Item2);
                        mftEntry.Compressed       = (byte)1;
                        mftEntry.UnCompressedSize = (uint)files[index1].Item2.Length;
                        mftEntry.MFTEntryOffset   = this._stream.Position;
                        binaryWriter.Write(0L);
                        binaryWriter.Write(mftEntry.HeaderSize);
                        binaryWriter.Write(mftEntry.CompressedSize);
                        binaryWriter.Write(mftEntry.UnCompressedSize);
                        binaryWriter.Write(mftEntry.Hash);
                        binaryWriter.Write(mftEntry.CRC32);
                        binaryWriter.Write(mftEntry.Compressed);
                        binaryWriter.Write((byte)0);
                        mftEntryList.Add(mftEntry);
                        ++index1;
                    }
                    else
                    {
                        binaryWriter.Write(0L);
                        binaryWriter.Write(0U);
                        binaryWriter.Write(0U);
                        binaryWriter.Write(0U);
                        binaryWriter.Write(0L);
                        binaryWriter.Write(0U);
                        binaryWriter.Write((byte)0);
                        binaryWriter.Write((byte)0);
                    }
                }
                int num2 = 0;
                foreach (MYP.MFTEntry mftEntry in mftEntryList)
                {
                    long position = this._stream.Position;
                    this._stream.Position = mftEntry.MFTEntryOffset;
                    binaryWriter.Write(position);
                    this._stream.Position = position;
                    byte[] data = mftEntry.Data;
                    this._stream.Write(data, 0, data.Length);
                    if ((int)mftEntry.Compressed == 1)
                    {
                        byte[]       buffer       = new byte[(int)mftEntry.UnCompressedSize];
                        MemoryStream memoryStream = new MemoryStream(data);
                        memoryStream.Position = (long)(mftEntry.HeaderSize + 2U);
                        using (DeflateStream deflateStream = new DeflateStream((Stream)memoryStream, CompressionMode.Decompress, true))
                            deflateStream.Read(buffer, 0, buffer.Length);
                    }
                    ++num2;
                }
                if (index1 < files.Count)
                {
                    long position = this._stream.Position;
                    this._stream.Position = num1;
                    binaryWriter.Write(position);
                    this._stream.Position = position;
                }
                mftEntryList.Clear();
            }
        }
Example #4
0
        public void Save()
        {
            BinaryWriter binaryWriter = new BinaryWriter(this._stream);

            foreach (MYP.MFTEntry mftEntry in this.Enteries.Where <KeyValuePair <long, MYP.MFTEntry> >((Func <KeyValuePair <long, MYP.MFTEntry>, bool>)(e =>
            {
                if (e.Value.Changed)
                {
                    return(e.Value.Offset > 0UL);
                }
                return(false);
            })).Select <KeyValuePair <long, MYP.MFTEntry>, MYP.MFTEntry>((Func <KeyValuePair <long, MYP.MFTEntry>, MYP.MFTEntry>)(e => e.Value)).ToList <MYP.MFTEntry>())
            {
                byte[] numArray = mftEntry.Data;
                if ((int)mftEntry.Compressed == 1)
                {
                    MemoryStream memoryStream = new MemoryStream();
                    using (DeflateStream deflateStream = new DeflateStream((Stream)memoryStream, CompressionMode.Compress, true))
                        deflateStream.Write(mftEntry.Data, 0, mftEntry.Data.Length);
                    numArray = memoryStream.ToArray();
                }
                if ((long)numArray.Length > (long)mftEntry.CompressedSize)
                {
                    this._stream.Position = mftEntry.MFTEntryOffset;
                    binaryWriter.Write((ulong)this._stream.Length);
                    binaryWriter.Write(mftEntry.HeaderSize);
                    if ((int)mftEntry.Compressed == 1)
                    {
                        binaryWriter.Write((uint)(numArray.Length + 2));
                    }
                    else
                    {
                        binaryWriter.Write((uint)numArray.Length);
                    }
                    binaryWriter.Write((uint)mftEntry.Data.Length);
                    this._stream.Position = mftEntry.MFTEntryOffset + 28L;
                    binaryWriter.Write(CRC32.ComputeChecksum(numArray));
                    this._stream.Position = this._stream.Length;
                    mftEntry.Offset       = (ulong)this._stream.Length;
                    binaryWriter.Write(this.ReadFileHeader(mftEntry.Hash));
                    if ((int)mftEntry.Compressed == 1)
                    {
                        binaryWriter.Write((ushort)40056);
                    }
                    binaryWriter.Write(numArray);
                }
                else
                {
                    this._stream.Position = mftEntry.MFTEntryOffset;
                    binaryWriter.Write(mftEntry.Offset);
                    binaryWriter.Write(mftEntry.HeaderSize);
                    if ((int)mftEntry.Compressed == 1)
                    {
                        binaryWriter.Write((uint)(numArray.Length + 2));
                    }
                    else
                    {
                        binaryWriter.Write((uint)numArray.Length);
                    }
                    binaryWriter.Write((uint)mftEntry.Data.Length);
                    this._stream.Position = mftEntry.MFTEntryOffset + 28L;
                    binaryWriter.Write(CRC32.ComputeChecksum(numArray));
                    this._stream.Position = (int)mftEntry.Compressed != 1 ? (long)mftEntry.Offset + (long)mftEntry.HeaderSize : (long)mftEntry.Offset + (long)mftEntry.HeaderSize + 2L;
                    binaryWriter.Write(numArray);
                }
            }
            List <MYP.MFTEntry> list = this.Enteries.Where <KeyValuePair <long, MYP.MFTEntry> >((Func <KeyValuePair <long, MYP.MFTEntry>, bool>)(e => (long)e.Value.Offset == 0L)).Select <KeyValuePair <long, MYP.MFTEntry>, MYP.MFTEntry>((Func <KeyValuePair <long, MYP.MFTEntry>, MYP.MFTEntry>)(e => e.Value)).ToList <MYP.MFTEntry>();

            if (list.Count <= 0)
            {
                return;
            }
            this._stream.Position = 24L;
            binaryWriter.Write((long)(uint)this.Enteries.Count + (long)list.Count);
            if (this.MFTTables.Count > 0)
            {
                this._stream.Position = this.MFTTables.Last <MYP.MFTHeader>().Offset + 4L;
                binaryWriter.Write((ulong)binaryWriter.BaseStream.Length);
            }
            binaryWriter.BaseStream.Position = binaryWriter.BaseStream.Length;
            int index1 = 0;
            List <MYP.MFTEntry> mftEntryList = new List <MYP.MFTEntry>();
            int count = list.Count;

            while (count > 0)
            {
                binaryWriter.Write(1000U);
                if (list.Count - index1 > 1000)
                {
                    long position = this._stream.Position;
                    binaryWriter.Write(0L);
                }
                else
                {
                    binaryWriter.Write(0L);
                }
                for (int index2 = 0; index2 < 1000; ++index2)
                {
                    if (index1 < list.Count)
                    {
                        --count;
                        MYP.MFTEntry mftEntry     = list[index1];
                        MemoryStream memoryStream = new MemoryStream();
                        using (DeflateStream deflateStream = new DeflateStream((Stream)memoryStream, CompressionMode.Compress, true))
                            deflateStream.Write(mftEntry.Data, 0, mftEntry.Data.Length);
                        memoryStream.ToArray();
                        mftEntry.MFTEntryOffset = this._stream.Position;
                        binaryWriter.Write(0L);
                        binaryWriter.Write(mftEntry.HeaderSize);
                        binaryWriter.Write(mftEntry.CompressedSize);
                        binaryWriter.Write(mftEntry.UnCompressedSize);
                        binaryWriter.Write(mftEntry.Hash);
                        binaryWriter.Write(mftEntry.CRC32);
                        binaryWriter.Write(mftEntry.Compressed);
                        binaryWriter.Write((byte)0);
                        mftEntryList.Add(mftEntry);
                        ++index1;
                    }
                    else
                    {
                        binaryWriter.Write(0L);
                        binaryWriter.Write(0U);
                        binaryWriter.Write(0U);
                        binaryWriter.Write(0U);
                        binaryWriter.Write(0L);
                        binaryWriter.Write(0U);
                        binaryWriter.Write((byte)0);
                        binaryWriter.Write((byte)0);
                    }
                }
                int num = 0;
                foreach (MYP.MFTEntry mftEntry in mftEntryList)
                {
                    long position = this._stream.Position;
                    this._stream.Position = mftEntry.MFTEntryOffset;
                    binaryWriter.Write(position);
                    this._stream.Position = position;
                    byte[] data = mftEntry.Data;
                    this._stream.Write(data, 0, data.Length);
                    if ((int)mftEntry.Compressed == 1)
                    {
                        byte[]       buffer       = new byte[(int)mftEntry.UnCompressedSize];
                        MemoryStream memoryStream = new MemoryStream(data);
                        memoryStream.Position = (long)(mftEntry.HeaderSize + 2U);
                        using (DeflateStream deflateStream = new DeflateStream((Stream)memoryStream, CompressionMode.Decompress, true))
                            deflateStream.Read(buffer, 0, buffer.Length);
                    }
                    ++num;
                }
                mftEntryList.Clear();
            }
        }
Example #5
0
 public byte[] GetAsset(MYP.MFTEntry entry)
 {
     return(entry.Archive.ReadFile(entry));
 }