public static FileVerificationPacket Create(PacketHeader header, byte[] bytes, int index) { FileVerificationPacket tmpPacket = new FileVerificationPacket(); tmpPacket.header = header; int offset = 0; Buffer.BlockCopy(bytes, index + offset, tmpPacket.fileid, 0, tmpPacket.fileid.Length * sizeof(byte)); offset += tmpPacket.fileid.Length * sizeof(byte); int nbEntries = ((int)header.length - header.GetSize() - (16 * sizeof(byte))) / FileVerificationEntry.GetSize(); tmpPacket.entries = new List <FileVerificationEntry>(); tmpPacket.blockcount = (ulong)((header.length - (ulong)tmpPacket.GetSize()) / (ulong)FileVerificationEntry.GetSize()); for (int i = 0; i < nbEntries; i++) { FileVerificationEntry entry = new FileVerificationEntry(); Buffer.BlockCopy(bytes, index + offset, entry.hash, 0, entry.hash.Length * sizeof(byte)); offset += entry.hash.Length * sizeof(byte); entry.crc = BitConverter.ToUInt32(bytes, index + offset); offset += sizeof(UInt32); tmpPacket.entries.Add(entry); } return(tmpPacket); }
public byte[] fileid = new byte[16]; // MD5hash of file_hash_16k, file_length, file_name #endregion Fields #region Methods public static FileVerificationPacket Create(PacketHeader header, byte[] bytes, int index) { FileVerificationPacket tmpPacket = new FileVerificationPacket(); tmpPacket.header = header; int offset = 0; Buffer.BlockCopy(bytes, index + offset, tmpPacket.fileid, 0, tmpPacket.fileid.Length * sizeof(byte)); offset += tmpPacket.fileid.Length * sizeof(byte); int nbEntries = ((int)header.length - header.GetSize() - (16 * sizeof(byte))) / FileVerificationEntry.GetSize(); tmpPacket.entries = new List<FileVerificationEntry>(); tmpPacket.blockcount = (ulong)((header.length - (ulong)tmpPacket.GetSize()) / (ulong)FileVerificationEntry.GetSize()); for (int i = 0; i < nbEntries; i++) { FileVerificationEntry entry = new FileVerificationEntry(); Buffer.BlockCopy(bytes, index + offset, entry.hash, 0, entry.hash.Length * sizeof(byte)); offset += entry.hash.Length * sizeof(byte); entry.crc = BitConverter.ToUInt32(bytes, index + offset); offset += sizeof(UInt32); tmpPacket.entries.Add(entry); } return tmpPacket; }
internal void SetBlockHashAndCRC(uint blocknumber, byte[] hash, uint crc) { Debug.Assert(blocknumber < blockcount); // Store the block hash and block crc in the packet. //FileVerificationEntry entry = entries[(int)blocknumber]; FileVerificationEntry entry = new FileVerificationEntry(); entry.hash = hash; entry.crc = crc; entries.Add(entry); }
private void WriteObject(BinaryWriter bw, object obj) { switch (obj.GetType().ToString().ToLower()) { case "system.string": bw.Write(StrToByteArray((string)obj)); break; case "system.uint64": case "system.ulong": bw.Write((ulong)obj); break; case "system.uint32": bw.Write((uint)obj); break; case "system.byte[]": bw.Write((byte[])obj); break; case "par2net.packets.fileverificationentry": FileVerificationEntry entry = (FileVerificationEntry)obj; bw.Write(entry.hash); bw.Write(entry.crc); break; case "system.collections.generic.list`1[par2net.packets.fileverificationentry]": foreach (FileVerificationEntry item in ((List <FileVerificationEntry>)obj)) { bw.Write(item.hash); bw.Write(item.crc); } break; case "system.collections.generic.list`1[system.byte[]]": foreach (byte[] item in ((List <byte[]>)obj)) { bw.Write(item); } break; default: Debug.Assert(false); throw new NotImplementedException(string.Format("Case '{0}' is not implemented for method 'WriteObject' of class CriticalPacket", obj.GetType())); } }
// Create a packet large enough for the specified number of blocks internal static FileVerificationPacket Create(ulong _blockcount) { // Allocate a packet large enough to hold the required number of verification entries. FileVerificationPacket tmpPacket = new FileVerificationPacket(); tmpPacket.blockcount = _blockcount; // Record everything we know in the packet. tmpPacket.header = new PacketHeader(); tmpPacket.header.magic = Par2FileReader.packet_magic; tmpPacket.header.hash = new byte[16]; tmpPacket.header.setid = new byte[16]; tmpPacket.header.type = Par2FileReader.fileverificationpacket_type; tmpPacket.fileid = new byte[16]; tmpPacket.entries = new List <FileVerificationEntry>((int)_blockcount); tmpPacket.header.length = (ulong)tmpPacket.GetSize() + (_blockcount * (ulong)FileVerificationEntry.GetSize()); return(tmpPacket); }
public int GetSize() { return(header.GetSize() + 16 * sizeof(byte) + (entries.Count * FileVerificationEntry.GetSize())); }