namespace SHNDecryptHK { using System; using System.IO; using System.Text; internal class BinaryReaderEx : BinaryReader { private static byte[] Buffer = new byte[0x100]; private const int BufferLength = 0x100; public BinaryReaderEx(Stream input) : base(input) { } private string _ReadString(uint bytes) { string str = string.Empty; if (bytes > 0x100) { str = this.ReadString((uint) (bytes - 0x100)); } this.Read(Buffer, 0, (int) bytes); if (Program.eT == "UTF7") { return (str + Encoding.UTF7.GetString(Buffer, 0, (int) bytes)); } if (Program.eT == "UTF8") { return (str + Encoding.UTF8.GetString(Buffer, 0, (int) bytes)); } return (str + Encoding.GetEncoding(Program.eT).GetString(Buffer, 0, (int) bytes)); } public override string ReadString() { int count = 0; for (byte i = this.ReadByte(); i != 0; i = this.ReadByte()) { Buffer[count++] = i; if (count >= 0x100) { break; } } string str = Encoding.UTF7.GetString(Buffer, 0, count); string str2 = Encoding.UTF8.GetString(Buffer, 0, count); string str3 = Encoding.GetEncoding(Program.eT).GetString(Buffer, 0, count); if (Program.eT == "UTF7") { if (count == 0x100) { str = str + this.ReadString(); } return str; } if (Program.eT == "UTF8") { if (count == 0x100) { str2 = str2 + this.ReadString(); } return str2; } if (count == 0x100) { str3 = str3 + this.ReadString(); } return str3; } public string ReadString(int bytes) { if (bytes > 0) { return this.ReadString((uint) bytes); } return string.Empty; } public string ReadString(uint bytes) { return this._ReadString(bytes).TrimEnd(new char[1]); } public long Length { get { return this.BaseStream.Length; } } } }