System.IO.BinaryReader.ReadBytes(int)

Here are the examples of the csharp api System.IO.BinaryReader.ReadBytes(int) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2644 Examples 7

19 View Source File : XnaToFnaExt.cs
License : zlib License
Project Creator : 0x0ade

public static byte[] ReadBytesUntil(this BinaryReader reader, long position)
            => reader.ReadBytes((int) (position - reader.BaseStream.Position));

19 View Source File : IrdParser.cs
License : MIT License
Project Creator : 13xforever

public static Ird Parse(byte[] content)
        {
            if (content == null)
                throw new ArgumentNullException(nameof(content));

            if (content.Length < 200)
                throw new ArgumentException("Data is too small to be a valid IRD structure", nameof(content));

            if (BitConverter.ToInt32(content, 0) != Ird.Magic)
                using (var compressedStream = new MemoryStream(content, false))
                using (var gzip = new GZipStream(compressedStream, CompressionMode.Decompress))
                using (var decompressedStream = new MemoryStream())
                {
                    gzip.CopyTo(decompressedStream);
                    content = decompressedStream.ToArray();
                }
            if (BitConverter.ToInt32(content, 0) != Ird.Magic)
                throw new FormatException("Not a valid IRD file");

            var result = new Ird();
            using (var stream = new MemoryStream(content, false))
            using (var reader = new BinaryReader(stream, Encoding.UTF8))
            {
                reader.ReadInt32(); // magic
                result.Version = reader.ReadByte();
                result.ProductCode = Encoding.ASCII.GetString(reader.ReadBytes(9));
                result.replacedleLength = reader.ReadByte();
                result.replacedle = Encoding.UTF8.GetString(reader.ReadBytes(result.replacedleLength));
                result.UpdateVersion = Encoding.ASCII.GetString(reader.ReadBytes(4)).Trim();
                result.GameVersion = Encoding.ASCII.GetString(reader.ReadBytes(5)).Trim();
                result.AppVersion = Encoding.ASCII.GetString(reader.ReadBytes(5)).Trim();
                if (result.Version == 7)
                    result.Id = reader.ReadInt32();
                result.HeaderLength = reader.ReadInt32();
                result.Header = reader.ReadBytes(result.HeaderLength);
                result.FooterLength = reader.ReadInt32();
                result.Footer = reader.ReadBytes(result.FooterLength);
                result.RegionCount = reader.ReadByte();
                result.RegionMd5Checksums = new List<byte[]>(result.RegionCount);
                for (var i = 0; i < result.RegionCount; i++)
                    result.RegionMd5Checksums.Add(reader.ReadBytes(16));
                result.FileCount = reader.ReadInt32();
                result.Files = new List<IrdFile>(result.FileCount);
                for (var i = 0; i < result.FileCount; i++)
                {
                    var file = new IrdFile();
                    file.Offset = reader.ReadInt64();
                    file.Md5Checksum = reader.ReadBytes(16);
                    result.Files.Add(file);
                }
                result.Unknown = reader.ReadInt32();
                if (result.Version == 9)
                    result.Pic = reader.ReadBytes(115);
                result.Data1 = reader.ReadBytes(16);
                result.Data2 = reader.ReadBytes(16);
                if (result.Version < 9)
                    result.Pic = reader.ReadBytes(115);
                result.Uid = reader.ReadInt32();
                var dataLength = reader.BaseStream.Position;
                result.Crc32 = reader.ReadUInt32();

                var crc32 = Crc32Algorithm.Compute(content, 0, (int)dataLength);
                if (result.Crc32 != crc32)
                    throw new InvalidDataException($"Corrupted IRD data, expected {result.Crc32:x8}, but was {crc32:x8}");
            }
            return result;
        }

19 View Source File : ParamSfoEntry.cs
License : MIT License
Project Creator : 13xforever

public static ParamSfoEntry Read(BinaryReader reader, ParamSfo paramSfo, int itemNumber)
        {
            const int indexOffset = 0x14;
            const int indexEntryLength = 0x10;
            reader.BaseStream.Seek(indexOffset + indexEntryLength * itemNumber, SeekOrigin.Begin);
            var result = new ParamSfoEntry();
            result.KeyOffset = reader.ReadUInt16();
            result.ValueFormat = (EntryFormat)reader.ReadUInt16();
            result.ValueLength = reader.ReadInt32();
            result.ValueMaxLength = reader.ReadInt32();
            result.ValueOffset = reader.ReadInt32();

            reader.BaseStream.Seek(paramSfo.KeysOffset + result.KeyOffset, SeekOrigin.Begin);
            byte tmp;
            var sb = new StringBuilder(32);
            while ((tmp = reader.ReadByte()) != 0)
                sb.Append((char)tmp);
            result.Key = sb.ToString();

            reader.BaseStream.Seek(paramSfo.ValuesOffset + result.ValueOffset, SeekOrigin.Begin);
            result.BinaryValue = reader.ReadBytes(result.ValueMaxLength);

            return result;
        }

19 View Source File : UEStructProperty.cs
License : MIT License
Project Creator : 13xforever

public static UEStructProperty Read(BinaryReader reader, long valueLength)
        {
            var type = reader.ReadUEString();
            var id = new Guid(reader.ReadBytes(16));
            if (id != Guid.Empty)
                throw new FormatException($"Offset: 0x{reader.BaseStream.Position - 16:x8}. Expected struct ID {Guid.Empty}, but was {id}");

            var terminator = reader.ReadByte();
            if (terminator != 0)
                throw new FormatException($"Offset: 0x{reader.BaseStream.Position - 1:x8}. Expected terminator (0x00), but was (0x{terminator:x2})");

            return ReadStructValue(type, reader);
        }

19 View Source File : UESerializer.cs
License : MIT License
Project Creator : 13xforever

public static Gvas Read(Stream stream)
        {
            using (var reader = new BinaryReader(stream, Encoding.ASCII, true))
            {
                var header = reader.ReadBytes(Gvas.Header.Length);
                if (!Gvas.Header.SequenceEqual(header))
                    throw new FormatException($"Invalid header, expected {Gvas.Header.AsHex()}");

                var result = new Gvas();
                result.SaveGameVersion = reader.ReadInt32();
                result.PackageVersion = reader.ReadInt32();
                result.EngineVersion.Major = reader.ReadInt16();
                result.EngineVersion.Minor = reader.ReadInt16();
                result.EngineVersion.Patch = reader.ReadInt16();
                result.EngineVersion.Build = reader.ReadInt32();
                result.EngineVersion.BuildId = reader.ReadUEString();
                result.CustomFormatVersion = reader.ReadInt32();
                result.CustomFormatData.Count = reader.ReadInt32();
                result.CustomFormatData.Entries = new CustomFormatDataEntry[result.CustomFormatData.Count];
                for (var i = 0; i < result.CustomFormatData.Count; i++)
                {
                    var entry = new CustomFormatDataEntry();
                    entry.Id = new Guid(reader.ReadBytes(16));
                    entry.Value = reader.ReadInt32();
                    result.CustomFormatData.Entries[i] = entry;
                }
                result.SaveGameType = reader.ReadUEString();

                while (UEProperty.Read(reader) is UEProperty prop)
                    result.Properties.Add(prop);

                return result;
            }
        }

19 View Source File : IrdParser.cs
License : MIT License
Project Creator : 13xforever

public static Ird Parse(byte[] content)
        {
            if (content == null)
                throw new ArgumentNullException(nameof(content));

            if (content.Length < 200)
                throw new ArgumentException("Data is too small to be a valid IRD structure", nameof(content));

            if (BitConverter.ToInt32(content, 0) != Ird.Magic)
                using (var compressedStream = new MemoryStream(content, false))
                using (var gzip = new GZipStream(compressedStream, CompressionMode.Decompress))
                using (var decompressedStream = new MemoryStream())
                {
                    gzip.CopyTo(decompressedStream);
                    content = decompressedStream.ToArray();
                }
            if (BitConverter.ToInt32(content, 0) != Ird.Magic)
                throw new FormatException("Not a valid IRD file");

            var result = new Ird();
            using (var stream = new MemoryStream(content, false))
            using (var reader = new BinaryReader(stream, Encoding.UTF8))
            {
                reader.ReadInt32(); // magic
                result.Version = reader.ReadByte();
                result.ProductCode = Encoding.ASCII.GetString(reader.ReadBytes(9));
                result.replacedleLength = reader.ReadByte();
                result.replacedle = Encoding.UTF8.GetString(reader.ReadBytes(result.replacedleLength));
                result.UpdateVersion = Encoding.ASCII.GetString(reader.ReadBytes(4)).Trim();
                result.GameVersion = Encoding.ASCII.GetString(reader.ReadBytes(5)).Trim();
                result.AppVersion = Encoding.ASCII.GetString(reader.ReadBytes(5)).Trim();
                if (result.Version == 7)
                    result.Id = reader.ReadInt32();
                result.HeaderLength = reader.ReadInt32();
                result.Header = reader.ReadBytes(result.HeaderLength);
                result.FooterLength = reader.ReadInt32();
                result.Footer = reader.ReadBytes(result.FooterLength);
                result.RegionCount = reader.ReadByte();
                result.RegionMd5Checksums = new List<byte[]>(result.RegionCount);
                for (var i = 0; i < result.RegionCount; i++)
                    result.RegionMd5Checksums.Add(reader.ReadBytes(16));
                result.FileCount = reader.ReadInt32();
                result.Files = new List<IrdFile>(result.FileCount);
                for (var i = 0; i < result.FileCount; i++)
                {
                    var file = new IrdFile();
                    file.Offset = reader.ReadInt64();
                    file.Md5Checksum = reader.ReadBytes(16);
                    result.Files.Add(file);
                }
                result.Unknown = reader.ReadInt32();
                if (result.Version == 9)
                    result.Pic = reader.ReadBytes(115);
                result.Data1 = reader.ReadBytes(16);
                result.Data2 = reader.ReadBytes(16);
                if (result.Version < 9)
                    result.Pic = reader.ReadBytes(115);
                result.Uid = reader.ReadInt32();
                var dataLength = reader.BaseStream.Position;
                result.Crc32 = reader.ReadUInt32();

                var crc32 = Crc32Algorithm.Compute(content, 0, (int)dataLength);
                if (result.Crc32 != crc32)
                    throw new InvalidDataException($"Corrupted IRD data, expected {result.Crc32:x8}, but was {crc32:x8}");
            }
            return result;
        }

19 View Source File : UEByteProperty.cs
License : MIT License
Project Creator : 13xforever

public static UEByteProperty Read(BinaryReader reader, long valueLength)
        {
            var terminator = reader.ReadByte();
            if (terminator != 0)
                throw new FormatException($"Offset: 0x{reader.BaseStream.Position - 1:x8}. Expected terminator (0x00), but was (0x{terminator:x2})");

            // valueLength starts here
            var arrayLength = reader.ReadInt32();
            var bytes = reader.ReadBytes(arrayLength);
            return new UEByteProperty {Value = bytes.AsHex()};
        }

19 View Source File : UEByteProperty.cs
License : MIT License
Project Creator : 13xforever

public static UEProperty[] Read(BinaryReader reader, long valueLength, int count)
        {
            // valueLength starts here
            var bytes = reader.ReadBytes(count);
            return new UEProperty[]{ new UEByteProperty {Value = bytes.AsHex()}};
        }

19 View Source File : UEStructProperty.cs
License : MIT License
Project Creator : 13xforever

public static UEStructProperty[] Read(BinaryReader reader, long valueLength, int count)
        {
            var type = reader.ReadUEString();
            var id = new Guid(reader.ReadBytes(16));
            if (id != Guid.Empty)
                throw new FormatException($"Offset: 0x{reader.BaseStream.Position - 16:x8}. Expected struct ID {Guid.Empty}, but was {id}");

            var terminator = reader.ReadByte();
            if (terminator != 0)
                throw new FormatException($"Offset: 0x{reader.BaseStream.Position - 1:x8}. Expected terminator (0x00), but was (0x{terminator:x2})");

            var result = new UEStructProperty[count];
            for (var i = 0; i < count; i++)
                result[i] = ReadStructValue(type, reader);
            return result;
        }

19 View Source File : BinaryReaderEx.cs
License : MIT License
Project Creator : 13xforever

public static string ReadUEString(this BinaryReader reader)
        {
            if (reader.PeekChar() < 0)
                return null;

            var length = reader.ReadInt32();
            if (length == 0)
                return null;

            if (length == 1)
                return "";

            var valueBytes = reader.ReadBytes(length);
            return Utf8.GetString(valueBytes, 0, valueBytes.Length - 1);
        }

19 View Source File : UESerializer.cs
License : MIT License
Project Creator : 13xforever

public static Gvas Read(Stream stream)
        {
            using (var reader = new BinaryReader(stream, Encoding.ASCII, true))
            {
                var header = reader.ReadBytes(Gvas.Header.Length);
                if (!Gvas.Header.SequenceEqual(header))
                    throw new FormatException($"Invalid header, expected {Gvas.Header.AsHex()}");

                var result = new Gvas();
                result.SaveGameVersion = reader.ReadInt32();
                result.PackageVersion = reader.ReadInt32();
                result.EngineVersion.Major = reader.ReadInt16();
                result.EngineVersion.Minor = reader.ReadInt16();
                result.EngineVersion.Patch = reader.ReadInt16();
                result.EngineVersion.Build = reader.ReadInt32();
                result.EngineVersion.BuildId = reader.ReadUEString();
                result.CustomFormatVersion = reader.ReadInt32();
                result.CustomFormatData.Count = reader.ReadInt32();
                result.CustomFormatData.Entries = new CustomFormatDataEntry[result.CustomFormatData.Count];
                for (var i = 0; i < result.CustomFormatData.Count; i++)
                {
                    var entry = new CustomFormatDataEntry();
                    entry.Id = new Guid(reader.ReadBytes(16));
                    entry.Value = reader.ReadInt32();
                    result.CustomFormatData.Entries[i] = entry;
                }
                result.SaveGameType = reader.ReadUEString();

                while (UEProperty.Read(reader) is UEProperty prop)
                    result.Properties.Add(prop);

                return result;
            }
        }

19 View Source File : WaveFileReader.cs
License : MIT License
Project Creator : 3wz

public static void ReadWaveHeader(Stream stream, out WaveFormat format, out long dataChunkPosition, out int dataChunkLength, List<RiffChunk> chunks)
        {
            dataChunkPosition = -1;
            format = null;
            BinaryReader br = new BinaryReader(stream);
            if (Encoding.ASCII.GetString(br.ReadBytes(4)) != "RIFF")//WaveInterop.mmioStringToFOURCC("RIFF", 0)
            {
                throw new FormatException("Not a WAVE file - no RIFF header");
            }
            uint fileSize = br.ReadUInt32(); // read the file size (minus 8 bytes)
            if (Encoding.ASCII.GetString(br.ReadBytes(4)) != "WAVE")//WaveInterop.mmioStringToFOURCC("WAVE", 0)
            {
                throw new FormatException("Not a WAVE file - no WAVE header");
            }
            int dataChunkID = BitConverter.ToInt32(Encoding.UTF8.GetBytes("data"), 0); ;//WaveInterop.mmioStringToFOURCC("data", 0)
            int formatChunkId = BitConverter.ToInt32(Encoding.UTF8.GetBytes("fmt "), 0); ;//WaveInterop.mmioStringToFOURCC("fmt ", 0)
            dataChunkLength = 0;

            // sometimes a file has more data than is specified after the RIFF header
            long stopPosition = Math.Min(fileSize + 8, stream.Length);

            // this -8 is so we can be sure that there are at least 8 bytes for a chunk id and length
            while (stream.Position <= stopPosition - 8)
            {
                Int32 chunkIdentifier = br.ReadInt32();
                Int32 chunkLength = br.ReadInt32();
                if (chunkIdentifier == dataChunkID)
                {
                    dataChunkPosition = stream.Position;
                    dataChunkLength = chunkLength;
                    stream.Position += chunkLength;
                }
                else if (chunkIdentifier == formatChunkId)
                {
                    format = WaveFormat.FromFormatChunk(br, chunkLength);
                }
                else
                {
                    // check for invalid chunk length
                    if (chunkLength < 0 || chunkLength > stream.Length - stream.Position)
                    {
                        Debug.replacedert(false, String.Format("Invalid chunk length {0}, pos: {1}. length: {2}",
                            chunkLength, stream.Position, stream.Length));
                        // an exception will be thrown further down if we haven't got a format and data chunk yet,
                        // otherwise we will tolerate this file despite it having corrupt data at the end
                        break;
                    }
                    if (chunks != null)
                    {
                        chunks.Add(new RiffChunk(chunkIdentifier, chunkLength, stream.Position));
                    }
                    stream.Position += chunkLength;
                }
            }

            if (format == null)
            {
                throw new FormatException("Invalid WAV file - No fmt chunk found");
            }
            if (dataChunkPosition == -1)
            {
                throw new FormatException("Invalid WAV file - No data chunk found");
            }
        }

19 View Source File : TLV_0017.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            var Reader = new BinaryReader(new MemoryStream(buf.ReadBytes(length)));
            WSubVer = Reader.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                long timeMillis = Reader.BeReadLong32();
                user.TXProtocol.DwServerTime = Util.GetDateTimeFromMillis(timeMillis);
                user.TXProtocol.TimeDifference = (uint.MaxValue & timeMillis) - Util.CurrentTimeMillis() / 1000;
                user.TXProtocol.DwClientIP = Util.GetIpStringFromBytes(Reader.ReadBytes(4));
                user.TXProtocol.WClientPort = Reader.BeReadUInt16();
                //buf.BeReadUInt16(); //UNKNOW
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TLV_001E.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            user.TXProtocol.BufTgtgtKey =
                buf.ReadBytes(length);
        }

19 View Source File : TLV_001F.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            if (WSubVer == 0x0001)
            {
                WSubVer = buf.BeReadUInt16(); //wSubVer
                user.TXProtocol.BufDeviceId =
                    buf.ReadBytes(length - 2);
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TLV_002F.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            WSubVer = buf.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                var bufControl = buf.ReadBytes(length - 2);
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TLV_0033.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            buf.ReadBytes(length);
        }

19 View Source File : TLV_0103.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            WSubVer = buf.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                var len = buf.BeReadUInt16();
                user.TXProtocol.BufSid = buf.ReadBytes(len);
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TLV_0104.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            var data = buf.ReadBytes(length);
            var bufData = new BinaryReader(new MemoryStream(data));
            WSubVer = bufData.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                var wCsCmd = bufData.BeReadUInt16();
                var errorCode = bufData.BeReadUInt32();

                bufData.ReadByte(); //0x00
                bufData.ReadByte(); //0x05
                PngData = bufData.ReadByte(); //是否需要验证码:0不需要,1需要
                int len;
                if (PngData == 0x00)
                {
                    len = bufData.ReadByte();
                    while (len == 0)
                    {
                        len = bufData.ReadByte();
                    }
                }
                else //ReplyCode != 0x01按下面走 兼容多版本
                {
                    bufData.BeReadInt32(); //需要验证码时为00 00 01 23,不需要时为全0
                    len = bufData.BeReadUInt16();
                }

                var buffer = bufData.ReadBytes(len);
                user.TXProtocol.BufSigPic = buffer;
                if (PngData == 0x01) //有验证码数据
                {
                    len = bufData.BeReadUInt16();
                    buffer = bufData.ReadBytes(len);
                    user.QQPacket00BaVerifyCode = buffer;
                    Next = bufData.ReadByte();
                    bufData.ReadByte();
                    //var directory = Util.MapPath("Verify");
                    //var filename = Path.Combine(directory, user.QQ + ".png");
                    //if (!Directory.Exists(directory))
                    //{
                    //    Directory.CreateDirectory(directory);
                    //}

                    //var fs = Next == 0x00
                    //    ? new FileStream(filename, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)
                    //    : new FileStream(filename, FileMode.Append, FileAccess.Write, FileShare.Read);

                    ////fs.Seek(0, SeekOrigin.End);
                    //fs.Write(buffer, 0, buffer.Length);
                    //fs.Close();
                    len = bufData.BeReadUInt16();
                    buffer = bufData.ReadBytes(len);
                    user.TXProtocol.PngToken = buffer;
                    if (bufData.BaseStream.Length > bufData.BaseStream.Position)
                    {
                        bufData.BeReadUInt16();
                        len = bufData.BeReadUInt16();
                        buffer = bufData.ReadBytes(len);
                        user.TXProtocol.PngKey = buffer;
                    }
                }
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TLV_0104.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            var data = buf.ReadBytes(length);
            var bufData = new BinaryReader(new MemoryStream(data));
            WSubVer = bufData.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                var wCsCmd = bufData.BeReadUInt16();
                var errorCode = bufData.BeReadUInt32();

                bufData.ReadByte(); //0x00
                bufData.ReadByte(); //0x05
                PngData = bufData.ReadByte(); //是否需要验证码:0不需要,1需要
                int len;
                if (PngData == 0x00)
                {
                    len = bufData.ReadByte();
                    while (len == 0)
                    {
                        len = bufData.ReadByte();
                    }
                }
                else //ReplyCode != 0x01按下面走 兼容多版本
                {
                    bufData.BeReadInt32(); //需要验证码时为00 00 01 23,不需要时为全0
                    len = bufData.BeReadUInt16();
                }

                var buffer = bufData.ReadBytes(len);
                user.TXProtocol.BufSigPic = buffer;
                if (PngData == 0x01) //有验证码数据
                {
                    len = bufData.BeReadUInt16();
                    buffer = bufData.ReadBytes(len);
                    user.QQPacket00BaVerifyCode = buffer;
                    Next = bufData.ReadByte();
                    bufData.ReadByte();
                    //var directory = Util.MapPath("Verify");
                    //var filename = Path.Combine(directory, user.QQ + ".png");
                    //if (!Directory.Exists(directory))
                    //{
                    //    Directory.CreateDirectory(directory);
                    //}

                    //var fs = Next == 0x00
                    //    ? new FileStream(filename, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)
                    //    : new FileStream(filename, FileMode.Append, FileAccess.Write, FileShare.Read);

                    ////fs.Seek(0, SeekOrigin.End);
                    //fs.Write(buffer, 0, buffer.Length);
                    //fs.Close();
                    len = bufData.BeReadUInt16();
                    buffer = bufData.ReadBytes(len);
                    user.TXProtocol.PngToken = buffer;
                    if (bufData.BaseStream.Length > bufData.BaseStream.Position)
                    {
                        bufData.BeReadUInt16();
                        len = bufData.BeReadUInt16();
                        buffer = bufData.ReadBytes(len);
                        user.TXProtocol.PngKey = buffer;
                    }
                }
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TLV_0108.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            WSubVer = buf.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                var len = buf.BeReadUInt16();
                var buffer = buf.ReadBytes(len);
                var bufAccountBasicInfo = new BinaryReader(new MemoryStream(buffer));

                len = bufAccountBasicInfo.BeReadUInt16();
                buffer = bufAccountBasicInfo.ReadBytes(len);
                var info = new BinaryReader(new MemoryStream(buffer));
                var wSsoAccountWFaceIndex = info.BeReadUInt16();
                len = info.ReadByte();
                if (len > 0)
                {
                    user.NickName = Encoding.UTF8.GetString(info.ReadBytes(len));
                }

                user.Gender = info.ReadByte();
                var dwSsoAccountDwUinFlag = info.BeReadUInt32();
                user.Age = info.ReadByte();

                var bufStOther =
                    bufAccountBasicInfo.ReadBytes(
                        (int) (bufAccountBasicInfo.BaseStream.Length - bufAccountBasicInfo.BaseStream.Position));
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TLV_010C.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            WSubVer = buf.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                user.TXProtocol.SessionKey = buf.ReadBytes(16);
                var dwUin = buf.BeReadInt32();
                var dwClientIP = Util.GetIpStringFromBytes(buf.ReadBytes(4)); //IP地址
                user.TXProtocol.WClientPort = buf.BeReadUInt16();
                var dwServerTime = Util.GetDateTimeFromMillis(buf.BeReadInt32());
                var unknow = buf.BeReadInt32();
                var cPreplacedSeqId = buf.ReadByte();
                var dwConnIP = buf.ReadBytes(4);
                var dwReLoginConnIP = buf.ReadBytes(4);
                var dwReLoginCtrlFlag = buf.BeReadInt32();

                int len = buf.BeReadUInt16();
                var bufComputerIdSig = buf.ReadBytes(len);

                len = buf.ReadByte();
                var unknow2 = buf.ReadBytes(len);

                len = buf.BeReadUInt16();
                var unknow3 = buf.ReadBytes(len);
                var a = new BinaryReader(new MemoryStream(unknow3));
                a.ReadByte();
                var dwConnIP2 = a.ReadBytes(4);
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TLV_010E.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            WSubVer = buf.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                int len = buf.BeReadUInt16();
                var buffer = buf.ReadBytes(len);
                var sig = new BinaryReader(new MemoryStream(buffer));
                var dwUinLevel = sig.BeReadInt32();
                var dwUinLevelEx = sig.BeReadInt32();

                len = sig.BeReadUInt16();
                buffer = sig.ReadBytes(len);
                var buf24ByteSignature = buffer;

                len = sig.BeReadUInt16();
                buffer = sig.ReadBytes(len);
                var buf32ByteValueAddedSignature = buffer;

                len = sig.BeReadUInt16();
                buffer = sig.ReadBytes(len);
                var buf12ByteUserBitmap = buffer;

                user.TXProtocol.ClientKey = buf32ByteValueAddedSignature;
                //client.QQUser.ClientKeyString = Util.ToHex(buf32byteValueAddedSignature).Replace(" ", "");
                //client.GetCookie();
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TLV_0110.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            WSubVer = buf.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                user.TXProtocol.BufSigPic = buf.ReadBytes(buf.BeReadUInt16());
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TLV_0112.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            user.TXProtocol.BufSigClientAddr =
                buf.ReadBytes(length); //bufSigClientAddr
        }

19 View Source File : TLV_0115.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            var bufPacketMD5 = buf.ReadBytes(length);
        }

19 View Source File : TLV_0310.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            user.TXProtocol.DwServerIP = Util.GetIpStringFromBytes(buf.ReadBytes(4));
        }

19 View Source File : EncodingUtil.cs
License : MIT License
Project Creator : 404Lcc

public static byte[] LengthDecode(ref List<byte> cacheList)
        {
            byte[] bytes;
            using (MemoryStream stream = new MemoryStream(cacheList.ToArray()))
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    int length = reader.ReadInt32();
                    if (length > stream.Length - stream.Position)
                    {
                        return null;
                    }
                    bytes = reader.ReadBytes(length);
                    cacheList.Clear();
                    cacheList.AddRange(reader.ReadBytes((int)(stream.Length - stream.Position)));
                }
            }
            return bytes;
        }

19 View Source File : EncodingUtil.cs
License : MIT License
Project Creator : 404Lcc

public static SocketModel SocketModelDncode(byte[] bytes)
        {
            SocketModel model = new SocketModel();
            using (MemoryStream stream = new MemoryStream(bytes))
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    model.type = reader.ReadByte();
                    model.area = reader.ReadInt32();
                    model.command = reader.ReadInt32();
                    if (stream.Length > stream.Position)
                    {
                        model.message = DeserializationDecode(reader.ReadBytes((int)(stream.Length - stream.Position)));
                    }
                }
            }
            return model;
        }

19 View Source File : Richtext.cs
License : MIT License
Project Creator : 499116344

public static Richtext Parse(BinaryReader reader)
        {
            var result = new Richtext();
            // TODO: 解析富文本
            try
            {
                var messageType = reader.ReadByte();
                var dataLength = reader.BeReadUInt16();
                var pos = reader.BaseStream.Position;
                while (pos + dataLength < reader.BaseStream.Length)
                {
                    reader.ReadByte();
                    switch (messageType)
                    {
                        case 0x01: // 纯文本消息、@
                        {
                            var messageStr = reader.BeReadString();
                            if (messageStr.StartsWith("@") && pos + dataLength - reader.BaseStream.Position == 16)
                            {
                                reader.ReadBytes(10);
                                result.Snippets.Add(new TextSnippet(messageStr, MessageType.At,
                                    ("Target", reader.BeReadLong32())));
                            }
                            else
                            {
                                result.Snippets.Add(messageStr);
                            }

                            break;
                        }
                        case 0x02: // Emoji(系统表情)
                        {
                            reader.BeReadUInt16(); // 这里的数字貌似总是1:系统表情只有208个。
                            result.Snippets.Add(new TextSnippet("", MessageType.Emoji, ("Type", reader.ReadByte())));
                            break;
                        }
                        case 0x03: // 图片
                        {
                            result.Snippets.Add(new TextSnippet(reader.BeReadString(), MessageType.Picture));
                            break;
                        }
                        case 0x0A: // 音频
                        {
                            result.Snippets.Add(new TextSnippet(reader.BeReadString(), MessageType.Audio));
                            break;
                        }
                        case 0x0E: // 未知
                        {
                            break;
                        }
                        case 0x12: // 群名片
                        {
                            break;
                        }
                        case 0x14: // XML
                        {
                            reader.ReadByte();
                            result.Snippets.Add(new TextSnippet(
                                GZipByteArray.DecompressString(reader.ReadBytes((int) (reader.BaseStream.Length - 1))),
                                MessageType.Xml));
                            break;
                        }
                        case 0x18: // 群文件
                        {
                            reader.ReadBytes(5);
                            var fileName = reader.BeReadString(); // 文件名称... 长度总是一个byte
                            reader.ReadByte();
                            reader.ReadBytes(reader.ReadByte()); // 文件大小
                            result.Snippets.Add(new TextSnippet(fileName, MessageType.OfflineFile));
                            break;
                        }
                        case 0x19: // 红包秘钥段
                        {
                            if (reader.ReadByte() != 0xC2)
                            {
                                break;
                            }

                            reader.ReadBytes(19);
                            reader.ReadBytes(reader.ReadByte()); // 恭喜发财
                            reader.ReadByte();
                            reader.ReadBytes(reader.ReadByte()); // 赶紧点击拆开吧
                            reader.ReadByte();
                            reader.ReadBytes(reader.ReadByte()); // QQ红包
                            reader.ReadBytes(5);
                            reader.ReadBytes(reader.ReadByte()); // [QQ红包]恭喜发财
                            reader.ReadBytes(22);
                            var redId = Encoding.UTF8.GetString(reader.ReadBytes(32)); //redid
                            reader.ReadBytes(12);
                            reader.ReadBytes(reader.BeReadUInt16());
                            reader.ReadBytes(0x10);
                            var key1 = Encoding.UTF8.GetString(reader.ReadBytes(reader.ReadByte())); //Key1
                            reader.BeReadUInt16();
                            var key2 = Encoding.UTF8.GetString(reader.ReadBytes(reader.ReadByte())); //Key2
                            result.Snippets.Add(new TextSnippet("", MessageType.RedBag, ("RedId", redId),
                                ("Key1", key1), ("Key2", key2)));
                            break;
                        }
                    }

                    reader.ReadBytes((int) (pos + dataLength - reader.BaseStream.Position));
                    messageType = reader.ReadByte();
                    dataLength = reader.BeReadUInt16();
                    pos = reader.BaseStream.Position;
                }
            }
            catch (Exception ex)
            {
            }

            // 移除所有空白的片段
            result.Snippets.RemoveAll(s => s.Type == MessageType.Normal && string.IsNullOrEmpty(s.Content));

            // 若长度大于1,那么应该只含有普通文本、At、表情、图片。
            // 虽然我看着别人好像视频也能通过转发什么的弄进来,但是反正我们现在不支持接收音视频,所以不管了
            return result.Snippets.Count > 1 && result.Snippets.Any(s =>
                       s.Type != MessageType.Normal && s.Type != MessageType.At &&
                       s.Type != MessageType.Emoji && s.Type != MessageType.Picture)
                ? throw new NotSupportedException("富文本中包含多个非聊天代码")
                : result;
        }

19 View Source File : Richtext.cs
License : MIT License
Project Creator : 499116344

public static Richtext Parse(BinaryReader reader)
        {
            var result = new Richtext();
            // TODO: 解析富文本
            try
            {
                var messageType = reader.ReadByte();
                var dataLength = reader.BeReadUInt16();
                var pos = reader.BaseStream.Position;
                while (pos + dataLength < reader.BaseStream.Length)
                {
                    reader.ReadByte();
                    switch (messageType)
                    {
                        case 0x01: // 纯文本消息、@
                        {
                            var messageStr = reader.BeReadString();
                            if (messageStr.StartsWith("@") && pos + dataLength - reader.BaseStream.Position == 16)
                            {
                                reader.ReadBytes(10);
                                result.Snippets.Add(new TextSnippet(messageStr, MessageType.At,
                                    ("Target", reader.BeReadLong32())));
                            }
                            else
                            {
                                result.Snippets.Add(messageStr);
                            }

                            break;
                        }
                        case 0x02: // Emoji(系统表情)
                        {
                            reader.BeReadUInt16(); // 这里的数字貌似总是1:系统表情只有208个。
                            result.Snippets.Add(new TextSnippet("", MessageType.Emoji, ("Type", reader.ReadByte())));
                            break;
                        }
                        case 0x03: // 图片
                        {
                            result.Snippets.Add(new TextSnippet(reader.BeReadString(), MessageType.Picture));
                            break;
                        }
                        case 0x0A: // 音频
                        {
                            result.Snippets.Add(new TextSnippet(reader.BeReadString(), MessageType.Audio));
                            break;
                        }
                        case 0x0E: // 未知
                        {
                            break;
                        }
                        case 0x12: // 群名片
                        {
                            break;
                        }
                        case 0x14: // XML
                        {
                            reader.ReadByte();
                            result.Snippets.Add(new TextSnippet(
                                GZipByteArray.DecompressString(reader.ReadBytes((int) (reader.BaseStream.Length - 1))),
                                MessageType.Xml));
                            break;
                        }
                        case 0x18: // 群文件
                        {
                            reader.ReadBytes(5);
                            var fileName = reader.BeReadString(); // 文件名称... 长度总是一个byte
                            reader.ReadByte();
                            reader.ReadBytes(reader.ReadByte()); // 文件大小
                            result.Snippets.Add(new TextSnippet(fileName, MessageType.OfflineFile));
                            break;
                        }
                        case 0x19: // 红包秘钥段
                        {
                            if (reader.ReadByte() != 0xC2)
                            {
                                break;
                            }

                            reader.ReadBytes(19);
                            reader.ReadBytes(reader.ReadByte()); // 恭喜发财
                            reader.ReadByte();
                            reader.ReadBytes(reader.ReadByte()); // 赶紧点击拆开吧
                            reader.ReadByte();
                            reader.ReadBytes(reader.ReadByte()); // QQ红包
                            reader.ReadBytes(5);
                            reader.ReadBytes(reader.ReadByte()); // [QQ红包]恭喜发财
                            reader.ReadBytes(22);
                            var redId = Encoding.UTF8.GetString(reader.ReadBytes(32)); //redid
                            reader.ReadBytes(12);
                            reader.ReadBytes(reader.BeReadUInt16());
                            reader.ReadBytes(0x10);
                            var key1 = Encoding.UTF8.GetString(reader.ReadBytes(reader.ReadByte())); //Key1
                            reader.BeReadUInt16();
                            var key2 = Encoding.UTF8.GetString(reader.ReadBytes(reader.ReadByte())); //Key2
                            result.Snippets.Add(new TextSnippet("", MessageType.RedBag, ("RedId", redId),
                                ("Key1", key1), ("Key2", key2)));
                            break;
                        }
                    }

                    reader.ReadBytes((int) (pos + dataLength - reader.BaseStream.Position));
                    messageType = reader.ReadByte();
                    dataLength = reader.BeReadUInt16();
                    pos = reader.BaseStream.Position;
                }
            }
            catch (Exception ex)
            {
            }

            // 移除所有空白的片段
            result.Snippets.RemoveAll(s => s.Type == MessageType.Normal && string.IsNullOrEmpty(s.Content));

            // 若长度大于1,那么应该只含有普通文本、At、表情、图片。
            // 虽然我看着别人好像视频也能通过转发什么的弄进来,但是反正我们现在不支持接收音视频,所以不管了
            return result.Snippets.Count > 1 && result.Snippets.Any(s =>
                       s.Type != MessageType.Normal && s.Type != MessageType.At &&
                       s.Type != MessageType.Emoji && s.Type != MessageType.Picture)
                ? throw new NotSupportedException("富文本中包含多个非聊天代码")
                : result;
        }

19 View Source File : Util.cs
License : MIT License
Project Creator : 499116344

public static byte[] ModelToByte<T>(T t)
        {
            using (var memoryStream = new MemoryStream())
            {
                var binaryReader = new BinaryReader(memoryStream);
                memoryStream.Position = 0L;
                return binaryReader.ReadBytes((int) memoryStream.Length);
            }
        }

19 View Source File : Util.cs
License : MIT License
Project Creator : 499116344

public static string BeReadString(this BinaryReader br, Encoding encoding = null)
        {
            encoding = encoding ?? Encoding.UTF8;
            return encoding.GetString(br.ReadBytes(br.BeReadUInt16()));
        }

19 View Source File : ResponseGroupOrSystemMessageCommand.cs
License : MIT License
Project Creator : 499116344

public override void Process()
        {
            if (!string.IsNullOrEmpty(_packet.Message))
            {
                //当收到消息包序为自己发送的消息包序时更新消息Id
                if (_user.GroupSendMessages.Any(c => c.Sequence == _packet.Sequence))
                {
                    var messageSend = _user.GroupSendMessages
                        .FirstOrDefault(c => c.Sequence == _packet.Sequence);
                    if (messageSend != null)
                    {
                        messageSend.MessageId = _packet.MessageId;
                        messageSend.MessageIndex = _packet.MessageIndex;
                    }
                }
                else
                {
                    if (_user.GroupReceiveMessages.All(c => c.Sequence != _packet.Sequence))
                    {
                        if (!QQGlobal.DebugLog && _packet.Message.ToString().Count(c => c == '\0') > 5)
                        {
                            _service.MessageLog($"收到群{_packet.Group}的{_packet.FromQQ}的乱码消息。");
                        }

                        _service.MessageLog($"收到群{_packet.Group}的{_packet.FromQQ}的消息:{_packet.Message}");
                        
                        //添加到已处理消息列表
                        _user.GroupReceiveMessages.Add(_packet);
                    }

                    //查看群消息确认
                    if (_packet.ReceiveTime != null)
                    {
                        _service.Send(new Send_0X0391(_user, _packet.Group, _packet.MessageIndex));
                    }
                }
            }

            //提取数据
            var dataReader = new BinaryReader(new MemoryStream(_packet.BodyDecrypted));

            _service.Send(new Send_0X0017(_user, dataReader.ReadBytes(0x10), _packet.Sequence));
        }

19 View Source File : ResponseReceiveFriendMessageCommand.cs
License : MIT License
Project Creator : 499116344

public override void Process()
        {
            if (!string.IsNullOrEmpty(_packet.Message.ToString()))
            {
                //只处理没有处理过的消息
                if (_user.FriendReceiveMessages.All(c => c.Sequence != _packet.Sequence))
                {
                    if (!QQGlobal.DebugLog && _packet.Message.ToString().Count(c => c == '\0') > 5)
                    {
                        _service.MessageLog($"收到好友{_packet.FromQQ}的乱码消息。");
                    }

                    _service.MessageLog($"收到好友{_packet.FromQQ}的消息:{_packet.Message}");

                    //添加到已处理消息列表
                    _user.FriendReceiveMessages.Add(_packet);
                }
            }
            else
            {
                _service.MessageLog($"收到好友{_packet.FromQQ}的空消息。");
            }

            var dataReader = new BinaryReader(new MemoryStream(_packet.BodyDecrypted));

            _service.Send(new Send_0X00Ce(_user, dataReader.ReadBytes(0x10), _packet.Sequence));

            //查看消息确认
            _service.Send(new Send_0X0319(_user, _packet.FromQQ, _packet.MessageDateTime));
        }

19 View Source File : TLV_0006.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            user.TXProtocol.BufTgtgt =
                buf.ReadBytes(length);
        }

19 View Source File : TLV_000A.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv_0A(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            WSubVer = buf.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                var wCsCmd = buf.BeReadUInt16();
                ErrorMsg = Encoding.UTF8.GetString(buf.ReadBytes(wCsCmd));
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TLV_000C.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            WSubVer = buf.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0002)
            {
                buf.BeReadUInt16();
                user.TXProtocol.DwIdc = buf.BeReadUInt32(); /*dwIDC =*/
                user.TXProtocol.DwIsp = buf.BeReadUInt32(); /*dwISP =*/
                user.TXProtocol.DwRedirectIP = Util.GetIpStringFromBytes(buf.ReadBytes(4)); /*dwRedirectIP =*/
                user.TXProtocol.WRedirectPort = buf.BeReadUInt16(); /*wRedirectPort =*/
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TLV_0017.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            var Reader = new BinaryReader(new MemoryStream(buf.ReadBytes(length)));
            WSubVer = Reader.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                long timeMillis = Reader.BeReadLong32();
                user.TXProtocol.DwServerTime = Util.GetDateTimeFromMillis(timeMillis);
                user.TXProtocol.TimeDifference = (uint.MaxValue & timeMillis) - Util.CurrentTimeMillis() / 1000;
                user.TXProtocol.DwClientIP = Util.GetIpStringFromBytes(Reader.ReadBytes(4));
                user.TXProtocol.WClientPort = Reader.BeReadUInt16();
                //buf.BeReadUInt16(); //UNKNOW
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TLV_0105.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            WSubVer = buf.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                buf.ReadByte(); //UNKNOWs
                var count = buf.ReadByte();
                for (var i = 0; i < count; i++)
                {
                    buf.ReadBytes(0x38); //buf
                }
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TLV_0107.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            WSubVer = buf.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                var len = buf.BeReadUInt16();
                var buffer = buf.ReadBytes(len);
                var bufTickStatus = new BinaryReader(new MemoryStream(buffer));
                var dwTgtServiceId = bufTickStatus.BeReadInt32();
                var dwTgtPriority = bufTickStatus.BeReadInt32();
                var dwTgtRefreshInterval = bufTickStatus.BeReadInt32();
                var dwTgtValidInterval = bufTickStatus.BeReadInt32();
                var dwTgtTryInterval = bufTickStatus.BeReadInt32();
                var wTgtTryCount = bufTickStatus.BeReadUInt16();

                buffer = buf.ReadBytes(16);
                user.TXProtocol.BufTgtGtKey = buffer;

                len = buf.BeReadUInt16();
                buffer = buf.ReadBytes(len);
                user.TXProtocol.BufTgt = buffer;

                buffer = buf.ReadBytes(16);
                user.TXProtocol.Buf16BytesGtKeySt = buffer;

                len = buf.BeReadUInt16();
                buffer = buf.ReadBytes(len);
                user.TXProtocol.BufServiceTicket = buffer;

                len = buf.BeReadUInt16();
                buffer = buf.ReadBytes(len);
                var bufStHttp = new BinaryReader(new MemoryStream(buffer));
                var bAllowPtlogin = bufStHttp.ReadByte();
                buffer = bufStHttp.ReadBytes(16);
                user.TXProtocol.Buf16BytesGtKeyStHttp = buffer;

                len = bufStHttp.BeReadUInt16();
                buffer = bufStHttp.ReadBytes(len);
                user.TXProtocol.BufServiceTicketHttp = buffer;

                buffer = buf.ReadBytes(16);
                user.TXProtocol.BufGtKeyTgtPwd = buffer;
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TLV_0107.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            WSubVer = buf.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                var len = buf.BeReadUInt16();
                var buffer = buf.ReadBytes(len);
                var bufTickStatus = new BinaryReader(new MemoryStream(buffer));
                var dwTgtServiceId = bufTickStatus.BeReadInt32();
                var dwTgtPriority = bufTickStatus.BeReadInt32();
                var dwTgtRefreshInterval = bufTickStatus.BeReadInt32();
                var dwTgtValidInterval = bufTickStatus.BeReadInt32();
                var dwTgtTryInterval = bufTickStatus.BeReadInt32();
                var wTgtTryCount = bufTickStatus.BeReadUInt16();

                buffer = buf.ReadBytes(16);
                user.TXProtocol.BufTgtGtKey = buffer;

                len = buf.BeReadUInt16();
                buffer = buf.ReadBytes(len);
                user.TXProtocol.BufTgt = buffer;

                buffer = buf.ReadBytes(16);
                user.TXProtocol.Buf16BytesGtKeySt = buffer;

                len = buf.BeReadUInt16();
                buffer = buf.ReadBytes(len);
                user.TXProtocol.BufServiceTicket = buffer;

                len = buf.BeReadUInt16();
                buffer = buf.ReadBytes(len);
                var bufStHttp = new BinaryReader(new MemoryStream(buffer));
                var bAllowPtlogin = bufStHttp.ReadByte();
                buffer = bufStHttp.ReadBytes(16);
                user.TXProtocol.Buf16BytesGtKeyStHttp = buffer;

                len = bufStHttp.BeReadUInt16();
                buffer = bufStHttp.ReadBytes(len);
                user.TXProtocol.BufServiceTicketHttp = buffer;

                buffer = buf.ReadBytes(16);
                user.TXProtocol.BufGtKeyTgtPwd = buffer;
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TLV_0108.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            WSubVer = buf.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                var len = buf.BeReadUInt16();
                var buffer = buf.ReadBytes(len);
                var bufAccountBasicInfo = new BinaryReader(new MemoryStream(buffer));

                len = bufAccountBasicInfo.BeReadUInt16();
                buffer = bufAccountBasicInfo.ReadBytes(len);
                var info = new BinaryReader(new MemoryStream(buffer));
                var wSsoAccountWFaceIndex = info.BeReadUInt16();
                len = info.ReadByte();
                if (len > 0)
                {
                    user.NickName = Encoding.UTF8.GetString(info.ReadBytes(len));
                }

                user.Gender = info.ReadByte();
                var dwSsoAccountDwUinFlag = info.BeReadUInt32();
                user.Age = info.ReadByte();

                var bufStOther =
                    bufAccountBasicInfo.ReadBytes(
                        (int) (bufAccountBasicInfo.BaseStream.Length - bufAccountBasicInfo.BaseStream.Position));
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TLV_0109.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            var data = buf.ReadBytes(length);
            var bufData = new BinaryReader(new MemoryStream(data));
            WSubVer = bufData.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                var buffer = bufData.ReadBytes(16);
                user.TXProtocol.BufSessionKey = buffer;

                var len = bufData.BeReadUInt16();
                buffer = bufData.ReadBytes(len);
                user.TXProtocol.BufSigSession = buffer;

                len = bufData.BeReadUInt16();
                buffer = bufData.ReadBytes(len);
                user.TXProtocol.BufPwdForConn = buffer;
                if (bufData.BaseStream.Length > bufData.BaseStream.Position)
                {
                    len = bufData.BeReadUInt16(); //bufBill
                    if (len > 0)
                    {
                        bufData.ReadBytes(len);
                    }
                }
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TLV_0109.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            var data = buf.ReadBytes(length);
            var bufData = new BinaryReader(new MemoryStream(data));
            WSubVer = bufData.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                var buffer = bufData.ReadBytes(16);
                user.TXProtocol.BufSessionKey = buffer;

                var len = bufData.BeReadUInt16();
                buffer = bufData.ReadBytes(len);
                user.TXProtocol.BufSigSession = buffer;

                len = bufData.BeReadUInt16();
                buffer = bufData.ReadBytes(len);
                user.TXProtocol.BufPwdForConn = buffer;
                if (bufData.BaseStream.Length > bufData.BaseStream.Position)
                {
                    len = bufData.BeReadUInt16(); //bufBill
                    if (len > 0)
                    {
                        bufData.ReadBytes(len);
                    }
                }
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : TLV_010D.cs
License : MIT License
Project Creator : 499116344

public void Parser_Tlv(QQUser user, BinaryReader buf)
        {
            var type = buf.BeReadUInt16(); //type
            var length = buf.BeReadUInt16(); //length
            WSubVer = buf.BeReadUInt16(); //wSubVer
            if (WSubVer == 0x0001)
            {
                var bufSigLastLoginInfo = buf.ReadBytes(length - 2);
            }
            else
            {
                throw new Exception($"{Name} 无法识别的版本号 {WSubVer}");
            }
        }

19 View Source File : Receive_0x0195.cs
License : MIT License
Project Creator : 499116344

protected override void ParseBody()
        {
            Decrypt(User.TXProtocol.SessionKey);
            Reader.BeReadUInt16();
            var groupCategoryLength = Reader.BeReadUInt16();
            Reader.ReadBytes(3);
            Reader.ReadByte();
            Reader.BeReadUInt16();
            Reader.ReadByte();

            var itemLength = Reader.BeReadUInt16();
            while (itemLength > 0)
            {
                var item = Reader.ReadBytes(itemLength);

                var itemReader = new BinaryReader(new MemoryStream(item));
                itemReader.ReadByte();
                var indnex = itemReader.ReadByte();
                var cateName = Util.GetString(itemReader.ReadBytes(itemReader.ReadByte()));
                GroupCategory.Add(cateName);
                User.MessageLog($"群分组{indnex}:{cateName}");

                itemLength = Reader.BeReadUInt16();
            }
        }

19 View Source File : ReceivePacket.cs
License : MIT License
Project Creator : 499116344

protected virtual void ParseHeader()
        {
            Header = Reader.ReadByte();
            Version = Reader.BeReadUInt16();
            Command = (QQCommand) Reader.BeReadUInt16();
            Sequence = Reader.BeReadUInt16();
            QQ = Reader.BeReadInt32();
            Reader.ReadBytes(3);
        }

19 View Source File : EndianBinaryReader.cs
License : MIT License
Project Creator : 91Act

public override ushort ReadUInt16()
        {
            if (endian == EndianType.BigEndian)
            {
                a16 = ReadBytes(2);
                Array.Reverse(a16);
                return BitConverter.ToUInt16(a16, 0);
            }
            return base.ReadUInt16();
        }

19 View Source File : EndianBinaryReader.cs
License : MIT License
Project Creator : 91Act

public string ReadASCII(int length)
        {
            return Encoding.ASCII.GetString(ReadBytes(length));
        }

See More Examples