From 6867da8a610c5345399a309a809c3f328a0c82d7 Mon Sep 17 00:00:00 2001 From: morkt Date: Sat, 8 Oct 2016 05:09:42 +0400 Subject: [PATCH] (ByteStringEncryptedStream): moved to SimpleEncryption. --- ArcFormats/Emic/ArcPACK.cs | 38 ------------------------------ ArcFormats/SimpleEncryption.cs | 43 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/ArcFormats/Emic/ArcPACK.cs b/ArcFormats/Emic/ArcPACK.cs index fd4c277b..b09c9156 100644 --- a/ArcFormats/Emic/ArcPACK.cs +++ b/ArcFormats/Emic/ArcPACK.cs @@ -115,42 +115,4 @@ namespace GameRes.Formats.Emic return input; } } - - internal class ByteStringEncryptedStream : InputProxyStream - { - byte[] m_key; - int m_base_pos; - - public ByteStringEncryptedStream (Stream main, long start_pos, byte[] key, bool leave_open = false) - : base (main, leave_open) - { - m_key = key; - m_base_pos = (int)(start_pos % m_key.Length); - } - - public override int Read (byte[] buffer, int offset, int count) - { - int start_pos = (int)((m_base_pos + BaseStream.Position) % m_key.Length); - int read = BaseStream.Read (buffer, offset, count); - if (read > 0) - { - for (int i = 0; i < read; ++i) - { - buffer[offset+i] ^= m_key[(start_pos + i) % m_key.Length]; - } - } - return read; - } - - public override int ReadByte () - { - long pos = BaseStream.Position; - int b = BaseStream.ReadByte(); - if (-1 != b) - { - b ^= m_key[(m_base_pos + pos) % m_key.Length]; - } - return b; - } - } } diff --git a/ArcFormats/SimpleEncryption.cs b/ArcFormats/SimpleEncryption.cs index 025edaa3..5eb1b90c 100644 --- a/ArcFormats/SimpleEncryption.cs +++ b/ArcFormats/SimpleEncryption.cs @@ -97,4 +97,47 @@ namespace GameRes.Formats System.GC.SuppressFinalize (this); } } + + public class ByteStringEncryptedStream : InputProxyStream + { + byte[] m_key; + int m_base_pos; + + public ByteStringEncryptedStream (Stream main, byte[] key, bool leave_open = false) + : this (main, 0, key, leave_open) + { + } + + public ByteStringEncryptedStream (Stream main, long start_pos, byte[] key, bool leave_open = false) + : base (main, leave_open) + { + m_key = key; + m_base_pos = (int)(start_pos % m_key.Length); + } + + public override int Read (byte[] buffer, int offset, int count) + { + int start_pos = (int)((m_base_pos + BaseStream.Position) % m_key.Length); + int read = BaseStream.Read (buffer, offset, count); + if (read > 0) + { + for (int i = 0; i < read; ++i) + { + buffer[offset+i] ^= m_key[(start_pos + i) % m_key.Length]; + } + } + return read; + } + + public override int ReadByte () + { + long pos = BaseStream.Position; + int b = BaseStream.ReadByte(); + if (-1 != b) + { + b ^= m_key[(m_base_pos + pos) % m_key.Length]; + } + return b; + } + } }