Example #1
0
        public static CreatorPacket Create(PacketHeader header, byte[] bytes, int index)
        {
            CreatorPacket tmpPacket = new CreatorPacket();
            tmpPacket.header = header;

            int offset = 0;

            // Name is specific to read since it's dependant of packet.length
            int name_offset = index + offset;
            int name_size = (int)header.length - header.GetSize();

            byte[] name = new byte[name_size];
            Buffer.BlockCopy(bytes, name_offset, name, 0, name_size);

            tmpPacket.client = ToolKit.ByteArrayToString(name);

            return tmpPacket;
        }
Example #2
0
        public static CreatorPacket Create(PacketHeader header, byte[] bytes, int index)
        {
            CreatorPacket tmpPacket = new CreatorPacket();

            tmpPacket.header = header;

            int offset = 0;

            // Name is specific to read since it's dependant of packet.length
            int name_offset = index + offset;
            int name_size   = (int)header.length - header.GetSize();

            byte[] name = new byte[name_size];
            Buffer.BlockCopy(bytes, name_offset, name, 0, name_size);

            tmpPacket.client = ToolKit.ByteArrayToString(name);

            return(tmpPacket);
        }
Example #3
0
        public static CreatorPacket Create(byte[] setid)
        {
            //string creator = string.Format("Created by {0} version {1}.", Par2Library.PACKAGE, Par2Library.VERSION);
            string creator = "Created by par2cmdline version 0.4.";
            string pad = new string(new char[4 - (creator.Length % 4)]);

            CreatorPacket tmpPacket = new CreatorPacket();

            // Fill in the details the we know
            tmpPacket.header = new PacketHeader();
            tmpPacket.header.magic = Par2FileReader.packet_magic;

            tmpPacket.header.hash = new byte[16]; // Compute later
            tmpPacket.header.setid = setid;
            tmpPacket.header.type = Par2FileReader.creatorpacket_type;

            tmpPacket.client = creator + pad;

            tmpPacket.header.length = (ulong)(tmpPacket.GetSize());

            // Compute the packet hash
            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    bw.Write(tmpPacket.header.setid);
                    bw.Write(tmpPacket.header.type);
                    bw.Write(Encoding.UTF8.GetBytes(tmpPacket.client));
                }

                byte[] buffer = ms.ToArray();
                // Compute the fileid from the hash, length, and name fields in the packet.
                MD5 md5Hasher = MD5.Create();
                tmpPacket.header.hash = md5Hasher.ComputeHash(buffer);
            }

            return tmpPacket;
        }
Example #4
0
        public static CreatorPacket Create(byte[] setid)
        {
            //string creator = string.Format("Created by {0} version {1}.", Par2Library.PACKAGE, Par2Library.VERSION);
            string creator = "Created by par2cmdline version 0.4.";
            string pad     = new string(new char[4 - (creator.Length % 4)]);

            CreatorPacket tmpPacket = new CreatorPacket();

            // Fill in the details the we know
            tmpPacket.header       = new PacketHeader();
            tmpPacket.header.magic = Par2FileReader.packet_magic;

            tmpPacket.header.hash  = new byte[16]; // Compute later
            tmpPacket.header.setid = setid;
            tmpPacket.header.type  = Par2FileReader.creatorpacket_type;

            tmpPacket.client = creator + pad;

            tmpPacket.header.length = (ulong)(tmpPacket.GetSize());

            // Compute the packet hash
            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    bw.Write(tmpPacket.header.setid);
                    bw.Write(tmpPacket.header.type);
                    bw.Write(Encoding.UTF8.GetBytes(tmpPacket.client));
                }

                byte[] buffer = ms.ToArray();
                // Compute the fileid from the hash, length, and name fields in the packet.
                MD5 md5Hasher = MD5.Create();
                tmpPacket.header.hash = md5Hasher.ComputeHash(buffer);
            }

            return(tmpPacket);
        }