Ejemplo n.º 1
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var mca    = arc as McaArchive;
            int method = arc.File.View.ReadInt32(entry.Offset);

            if (null == mca || method < 0 || method > 1)
            {
                return(base.OpenEntry(arc, entry));
            }
            uint width         = arc.File.View.ReadUInt32(entry.Offset + 0xC);
            uint height        = arc.File.View.ReadUInt32(entry.Offset + 0x10);
            uint packed_size   = arc.File.View.ReadUInt32(entry.Offset + 0x14);
            int  unpacked_size = arc.File.View.ReadInt32(entry.Offset + 0x18);

            var data = arc.File.View.ReadBytes(entry.Offset + 0x20, packed_size);

            MrgOpener.Decrypt(data, 0, data.Length, mca.Key);
            if (method > 0)
            {
                using (var input = new MemoryStream(data))
                    using (var lzss = new MrgLzssReader(input, data.Length, unpacked_size))
                    {
                        lzss.Unpack();
                        data = lzss.Data;
                    }
            }
            int stride = ((int)width * 3 + 3) & ~3;
            var info   = new ImageMetaData {
                Width = width, Height = height, BPP = 24
            };

            return(TgaStream.Create(info, stride, data));
        }
Ejemplo n.º 2
0
        protected override ImageData GetImageData()
        {
            m_input.Position = 0x20;
            var data = m_input.ReadBytes(m_packed_size);

            MrgOpener.Decrypt(data, 0, data.Length, m_key);
            if (m_compressed)
            {
                using (var input = new BinMemoryStream(data))
                    using (var lzss = new MrgLzssReader(input, data.Length, m_unpacked_size))
                    {
                        lzss.Unpack();
                        data = lzss.Data;
                    }
            }
            int stride = ((int)Info.Width * Info.BPP / 8 + 3) & ~3;
            var format = 8 == Info.BPP ? PixelFormats.Indexed8 : PixelFormats.Bgr24;

            return(ImageData.Create(Info, format, m_palette, data, stride));
        }
Ejemplo n.º 3
0
        void UnpackV101()
        {
            if (m_key != 0)
            {
                MrgOpener.Decrypt(m_input, 0, m_input.Length - 1, m_key);
            }
#if DEBUG
            else // bruteforce key *in debug build only*
            {
                var copy = new byte[m_input.Length];
                for (int key = 1; key < 256; ++key)
                {
                    Buffer.BlockCopy(m_input, 0, copy, 0, m_input.Length);
                    MrgOpener.Decrypt(copy, 0, copy.Length - 1, (byte)key);
                    using (var input = new BinMemoryStream(copy))
                        using (var lzss = new MrgLzssReader(input, copy.Length, Stride * m_height))
                        {
                            lzss.Unpack();
                            if (input.Length - input.Position <= 1)
                            {
                                Trace.WriteLine(string.Format("Found matching key {0:X2}", key), "[MCG]");
                                m_output = lzss.Data;
                                m_key    = (byte)key;
                                return;
                            }
                        }
                }
            }
#endif
            using (var input = new BinMemoryStream(m_input))
                using (var lzss = new MrgLzssReader(input, m_input.Length, Stride * m_height))
                {
                    lzss.Unpack();
                    // data remaining within input stream indicates invalid encryption key
                    if (input.Length - input.Position > 1)
                    {
                        m_key = 0;
                    }
                    m_output = lzss.Data;
                }
        }
Ejemplo n.º 4
0
        void UnpackV101()
        {
            if (m_key != 0)
            {
                MrgOpener.Decrypt(m_input, 0, m_input.Length - 1, m_key);
            }
#if DEBUG
            else // bruteforce key *in debug build only*
            {
                for (int key = 1; key < 256; ++key)
                {
                    var copy = m_input.Clone() as byte[];
                    MrgOpener.Decrypt(copy, 0, copy.Length - 1, (byte)key);
                    using (var input = new BinMemoryStream(copy))
                        using (var lzss = new MrgLzssReader(input, m_input.Length, Stride * m_height))
                        {
                            lzss.Unpack();
                            if (input.Length - input.Position <= 1)
                            {
                                m_output = lzss.Data;
                                m_key    = (byte)key;
                                return;
                            }
                        }
                }
            }
#endif
            using (var input = new BinMemoryStream(m_input))
                using (var lzss = new MrgLzssReader(input, m_input.Length, Stride * m_height))
                {
                    lzss.Unpack();
                    // data remaining within input stream indicates invalid encryption key
                    if (input.Length - input.Position > 1)
                    {
                        m_key = 0;
                    }
                    m_output = lzss.Data;
                }
        }