示例#1
0
        void UnpackV200()
        {
            m_output = new byte[m_pixels * 3];
            var reader = new MrgDecoder(m_input, 0, (uint)m_pixels);

            do
            {
                reader.ResetKey(m_key);
                try
                {
                    for (int i = 0; i < 3; ++i)
                    {
                        reader.Unpack();
                        var plane = reader.Data;
                        int src   = 0;
                        for (int j = ChannelOrder[i]; j < m_output.Length; j += 3)
                        {
                            m_output[j] = plane[src++];
                        }
                    }
//                    Trace.WriteLine (string.Format ("Found matching key {0:X2}", key), "[MCG]");
                }
                catch (InvalidFormatException)
                {
                    m_key++;
                    continue;
                }
                Transform();
                Properties.Settings.Default.MCGLastKey = m_key;
                return;
            }while (m_key != Properties.Settings.Default.MCGLastKey);
            throw new UnknownEncryptionScheme();
        }
示例#2
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var mrg_entry = entry as Mrg2Entry;

            if (null == mrg_entry || mrg_entry.Method > 3)
            {
                return(arc.File.CreateStream(entry.Offset, entry.Size));
            }
            IBinaryStream input;

            if (0 == mrg_entry.Method)
            {
                var data = arc.File.View.ReadBytes(entry.Offset, entry.Size);
                Decrypt(data, 0, data.Length, mrg_entry.Key, mrg_entry.ArcKey);
                input = new BinMemoryStream(data, entry.Name);
            }
            else if (mrg_entry.Method >= 2)
            {
                var data   = arc.File.View.ReadBytes(entry.Offset, entry.Size);
                var reader = new MrgDecoder(data);
                reader.Unpack();
                input = new BinMemoryStream(reader.Data, entry.Name);
            }
            else
            {
                input = arc.File.CreateStream(entry.Offset, entry.Size);
            }
            if (1 == mrg_entry.Method || 3 == mrg_entry.Method)
            {
                using (input)
                    using (var reader = new MrgLzssReader(input, (int)input.Length, (int)mrg_entry.UnpackedSize))
                    {
                        reader.Unpack();
                        return(new BinMemoryStream(reader.Data, entry.Name));
                    }
            }
            return(input.AsStream);
        }
示例#3
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var packed_entry = entry as MrgEntry;

            if (null == packed_entry || !packed_entry.IsPacked || packed_entry.Method > 3)
            {
                return(arc.File.CreateStream(entry.Offset, entry.Size));
            }
            Stream input;

            if (packed_entry.Method >= 2)
            {
                if (entry.Size < 0x108)
                {
                    return(arc.File.CreateStream(entry.Offset, entry.Size));
                }
                var data = new byte[entry.Size];
                arc.File.View.Read(entry.Offset, data, 0, entry.Size);
                var reader = new MrgDecoder(data);
                reader.Unpack();
                input = new MemoryStream(reader.Data);
            }
            else
            {
                input = arc.File.CreateStream(entry.Offset, entry.Size);
            }
            if (packed_entry.Method < 3)
            {
                using (input)
                    using (var reader = new MrgLzssReader(input, (int)input.Length, (int)packed_entry.UnpackedSize))
                    {
                        reader.Unpack();
                        return(new MemoryStream(reader.Data));
                    }
            }
            return(input);
        }
示例#4
0
文件: ArcMRG.cs 项目: Casidi/GARbro
 public override Stream OpenEntry(ArcFile arc, Entry entry)
 {
     var packed_entry = entry as MrgEntry;
     if (null == packed_entry || !packed_entry.IsPacked || packed_entry.Method > 3)
         return arc.File.CreateStream (entry.Offset, entry.Size);
     Stream input;
     if (packed_entry.Method >= 2)
     {
         if (entry.Size < 0x108)
             return arc.File.CreateStream (entry.Offset, entry.Size);
         var data = new byte[entry.Size];
         arc.File.View.Read (entry.Offset, data, 0, entry.Size);
         var reader = new MrgDecoder (data);
         reader.Unpack();
         input = new MemoryStream (reader.Data);
     }
     else
         input = arc.File.CreateStream (entry.Offset, entry.Size);
     if (packed_entry.Method < 3)
     {
         using (input)
         using (var reader = new MrgLzssReader (input, (int)input.Length, (int)packed_entry.UnpackedSize))
         {
             reader.Unpack();
             return new MemoryStream (reader.Data);
         }
     }
     return input;
 }