示例#1
0
        public static RecoveryPacket Create(PacketHeader header, byte[] bytes, int index, string filename, int file_offset)
        {
            RecoveryPacket tmpPacket = new RecoveryPacket();

            tmpPacket.header = header;

            int offset = 0;

            tmpPacket.exponent = BitConverter.ToUInt32(bytes, index + offset);
            offset            += sizeof(UInt32);

            tmpPacket.offset   = index + offset + file_offset;
            tmpPacket.length   = (int)header.length - header.GetSize() - sizeof(UInt32);
            tmpPacket.filename = filename;

            tmpPacket.diskfile = new DiskFile();
            tmpPacket.diskfile.Open(filename);

            tmpPacket.datablock = new DataBlock();
            // Set the data block to immediatly follow the header on disk
            tmpPacket.datablock.SetLocation(tmpPacket.diskfile, (ulong)tmpPacket.offset);
            tmpPacket.datablock.SetLength((ulong)tmpPacket.length);

            return(tmpPacket);
        }
示例#2
0
        internal static RecoveryPacket Create(DiskFile diskFile, ulong offset, ulong blocksize, uint exponent, byte[] setid)
        {
            RecoveryPacket tmpPacket = new RecoveryPacket();

            // 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.recoveryblockpacket_type;

            tmpPacket.diskfile = diskFile;
            tmpPacket.offset   = (int)offset;

            tmpPacket.exponent = exponent;

            //tmpPacket.length = 0; //
            tmpPacket.header.length = (ulong)(tmpPacket.header.GetSize() + sizeof(UInt32) + (int)blocksize);
            tmpPacket.length        = (int)tmpPacket.header.length;

            // Start computation of the packet hash
            tmpPacket.packetcontext = MD5.Create();
            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    // PacketHeader section
                    bw.Write(tmpPacket.header.setid);
                    bw.Write(tmpPacket.header.type);

                    //Packet section
                    bw.Write(tmpPacket.exponent);

                    byte[] buffer = ms.ToArray();

                    tmpPacket.packetcontext.TransformBlock(buffer, 0, buffer.Length, null, 0);
                }
            }

            // Set the data block to immediatly follow the header on disk
            tmpPacket.datablock = new DataBlock();
            tmpPacket.datablock.SetLocation(tmpPacket.diskfile, (ulong)(tmpPacket.offset + tmpPacket.GetSize()));
            tmpPacket.datablock.SetLength(blocksize);

            return(tmpPacket);
        }
示例#3
0
        public static RecoveryPacket Create(PacketHeader header, byte[] bytes, int index, string filename, int file_offset)
        {
            RecoveryPacket tmpPacket = new RecoveryPacket();
            tmpPacket.header = header;

            int offset = 0;

            tmpPacket.exponent = BitConverter.ToUInt32(bytes, index + offset);
            offset += sizeof(UInt32);

            tmpPacket.offset = index + offset + file_offset;
            tmpPacket.length = (int)header.length - header.GetSize() - sizeof(UInt32);
            tmpPacket.filename = filename;

            tmpPacket.diskfile = new DiskFile();
            tmpPacket.diskfile.Open(filename);

            tmpPacket.datablock = new DataBlock();
            // Set the data block to immediatly follow the header on disk
            tmpPacket.datablock.SetLocation(tmpPacket.diskfile, (ulong)tmpPacket.offset);
            tmpPacket.datablock.SetLength((ulong)tmpPacket.length);

            return tmpPacket;
        }
示例#4
0
        internal static RecoveryPacket Create(DiskFile diskFile, ulong offset, ulong blocksize, uint exponent, byte[] setid)
        {
            RecoveryPacket tmpPacket = new RecoveryPacket();

            // 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.recoveryblockpacket_type;

            tmpPacket.diskfile = diskFile;
            tmpPacket.offset = (int)offset;

            tmpPacket.exponent = exponent;

            //tmpPacket.length = 0; //
            tmpPacket.header.length = (ulong)(tmpPacket.header.GetSize() + sizeof(UInt32) + (int)blocksize);
            tmpPacket.length = (int)tmpPacket.header.length;

            // Start computation of the packet hash
            tmpPacket.packetcontext = MD5.Create();
            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    // PacketHeader section
                    bw.Write(tmpPacket.header.setid);
                    bw.Write(tmpPacket.header.type);

                    //Packet section
                    bw.Write(tmpPacket.exponent);

                    byte[] buffer = ms.ToArray();

                    tmpPacket.packetcontext.TransformBlock(buffer, 0, buffer.Length, null, 0);
                }
            }

            // Set the data block to immediatly follow the header on disk
            tmpPacket.datablock = new DataBlock();
            tmpPacket.datablock.SetLocation(tmpPacket.diskfile, (ulong)(tmpPacket.offset + tmpPacket.GetSize()));
            tmpPacket.datablock.SetLength(blocksize);

            return tmpPacket;
        }