Beispiel #1
0
        public static LargeDataPacket Decode(G2Header root)
        {
            LargeDataPacket packet = new LargeDataPacket(root.Name, 0, null);

            // size packet
            G2Header child = new G2Header(root.Data);

            while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(child))
                {
                    continue;
                }

                if (child.Name == Packet_Size)
                {
                    packet.Size = BitConverter.ToInt32(child.Data, child.PayloadPos);
                }

                if (child.Name == Packet_Hash)
                {
                    packet.Hash = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                }
            }

            return(packet);
        }
Beispiel #2
0
        public static byte[] Read(LargeDataPacket start, PacketStream stream, byte name)
        {
            byte[] data = new byte[start.Size];
            int    pos  = 0;

            G2Header root = null;

            while (stream.ReadPacket(ref root))
            {
                if (root.Name == name)
                {
                    if (!LargeDataPacket.Decode(root, data, ref pos))
                    {
                        break;
                    }

                    // done, break
                    if (pos == start.Size)
                    {
                        break;
                    }
                }
                // unknown packet, break
                else
                {
                    break;
                }
            }

            if (start != null && data != null)
            {
                if (Utilities.MemCompare(start.Hash, new SHA1Managed().ComputeHash(data)))
                {
                    return(data);
                }
            }

            return(null);
        }