internal static FlashingPayload[] GetOptimizedPayloads(FlashPart[] flashParts, UInt32 chunkSize) { List <FlashingPayload> flashingPayloads = new List <FlashingPayload>(); if (flashParts == null) { return(flashingPayloads.ToArray()); } Int64 TotalProcess1 = 0; for (Int32 j = 0; j < flashParts.Count(); j++) { FlashPart flashPart = flashParts[j]; TotalProcess1 += flashPart.Stream.Length / chunkSize; } Int64 CurrentProcess1 = 0; DateTime startTime = DateTime.Now; Logging.Log("Hashing resources..."); using (SHA256 crypto = SHA256.Create()) { for (UInt32 j = 0; j < flashParts.Count(); j++) { FlashPart flashPart = flashParts[(Int32)j]; flashPart.Stream.Seek(0, SeekOrigin.Begin); Int64 totalChunkCount = flashPart.Stream.Length / chunkSize; for (UInt32 i = 0; i < totalChunkCount; i++) { byte[] buffer = new byte[chunkSize]; Int64 position = flashPart.Stream.Position; flashPart.Stream.Read(buffer, 0, (Int32)chunkSize); byte[] hash = crypto.ComputeHash(buffer); if (flashingPayloads.Any(x => ByteOperations.Compare(x.ChunkHashes.First(), hash))) { var payloadIndex = flashingPayloads.FindIndex(x => ByteOperations.Compare(x.ChunkHashes.First(), hash)); var locationList = flashingPayloads[payloadIndex].TargetLocations.ToList(); locationList.Add(((UInt32)flashPart.StartLocation / chunkSize) + i); flashingPayloads[payloadIndex].TargetLocations = locationList.ToArray(); } else { flashingPayloads.Add(new FlashingPayload(1, new byte[][] { hash }, new UInt32[] { ((UInt32)flashPart.StartLocation / chunkSize) + i }, new UInt32[] { j }, new Int64[] { position })); } CurrentProcess1++; ShowProgress(CurrentProcess1, TotalProcess1, startTime); } } } return(flashingPayloads.ToArray()); }
internal static FlashingPayload[] GetOptimizedPayloads(FlashPart[] flashParts, UInt32 chunkSize, ulong PlatEnd) { List <FlashingPayload> flashingPayloads = new List <FlashingPayload>(); if (flashParts == null) { return(flashingPayloads.ToArray()); } Int64 TotalProcess1 = 0; for (Int32 j = 0; j < flashParts.Count(); j++) { FlashPart flashPart = flashParts[j]; TotalProcess1 += flashPart.Stream.Length / chunkSize; } Int64 CurrentProcess1 = 0; DateTime startTime = DateTime.Now; Logging.Log("Hashing resources..."); using (SHA256 crypto = SHA256.Create()) { for (UInt32 j = 0; j < flashParts.Count(); j++) { FlashPart flashPart = flashParts[(Int32)j]; flashPart.Stream.Seek(0, SeekOrigin.Begin); Int64 totalChunkCount = flashPart.Stream.Length / chunkSize; for (UInt32 i = 0; i < totalChunkCount; i++) { byte[] buffer = new byte[chunkSize]; Int64 position = flashPart.Stream.Position; flashPart.Stream.Read(buffer, 0, (Int32)chunkSize); byte[] hash = crypto.ComputeHash(buffer); byte[] emptyness = new byte[] { 0xFA, 0x43, 0x23, 0x9B, 0xCE, 0xE7, 0xB9, 0x7C, 0xA6, 0x2F, 0x00, 0x7C, 0xC6, 0x84, 0x87, 0x56, 0x0A, 0x39, 0xE1, 0x9F, 0x74, 0xF3, 0xDD, 0xE7, 0x48, 0x6D, 0xB3, 0xF9, 0x8D, 0xF8, 0xE4, 0x71 }; if ((((UInt32)flashPart.StartLocation / chunkSize) + i) < PlatEnd || !ByteOperations.Compare(emptyness, hash)) { flashingPayloads.Add(new FlashingPayload(1, new byte[][] { hash }, new UInt32[] { ((UInt32)flashPart.StartLocation / chunkSize) + i }, new UInt32[] { j }, new Int64[] { position })); } /*if (flashingPayloads.Any(x => ByteOperations.Compare(x.ChunkHashes.First(), hash))) * { * var payloadIndex = flashingPayloads.FindIndex(x => ByteOperations.Compare(x.ChunkHashes.First(), hash)); * var locationList = flashingPayloads[payloadIndex].TargetLocations.ToList(); * locationList.Add(((UInt32)flashPart.StartLocation / chunkSize) + i); * flashingPayloads[payloadIndex].TargetLocations = locationList.ToArray(); * } * else * { * flashingPayloads.Add(new FlashingPayload(1, new byte[][] { hash }, new UInt32[] { ((UInt32)flashPart.StartLocation / chunkSize) + i }, new UInt32[] { j }, new Int64[] { position })); * }*/ CurrentProcess1++; ShowProgress(CurrentProcess1, TotalProcess1, startTime, (((UInt32)flashPart.StartLocation / chunkSize) + i) < PlatEnd); } } } return(flashingPayloads.ToArray()); }
internal static FlashingPayload[] GetOptimizedPayloads(FlashPart[] flashParts, UInt32 chunkSize, UInt32 BlankSectorBufferSize) { List <FlashingPayload> flashingPayloads = new List <FlashingPayload>(); if (flashParts == null) { return(flashingPayloads.ToArray()); } Int64 TotalProcess1 = 0; for (Int32 j = 0; j < flashParts.Count(); j++) { FlashPart flashPart = flashParts[j]; TotalProcess1 += flashPart.Stream.Length / chunkSize; } Int64 CurrentProcess1 = 0; DateTime startTime = DateTime.Now; Logging.Log("Hashing resources..."); ulong maxblank = BlankSectorBufferSize; bool blankphase = false; ulong blankcount = 0; List <FlashingPayload> blankbuffer = new List <FlashingPayload>(); using (SHA256 crypto = SHA256.Create()) { for (UInt32 j = 0; j < flashParts.Count(); j++) { FlashPart flashPart = flashParts[(Int32)j]; flashPart.Stream.Seek(0, SeekOrigin.Begin); Int64 totalChunkCount = flashPart.Stream.Length / chunkSize; for (UInt32 i = 0; i < totalChunkCount; i++) { byte[] buffer = new byte[chunkSize]; Int64 position = flashPart.Stream.Position; flashPart.Stream.Read(buffer, 0, (Int32)chunkSize); byte[] hash = crypto.ComputeHash(buffer); byte[] emptyness = new byte[] { 0xFA, 0x43, 0x23, 0x9B, 0xCE, 0xE7, 0xB9, 0x7C, 0xA6, 0x2F, 0x00, 0x7C, 0xC6, 0x84, 0x87, 0x56, 0x0A, 0x39, 0xE1, 0x9F, 0x74, 0xF3, 0xDD, 0xE7, 0x48, 0x6D, 0xB3, 0xF9, 0x8D, 0xF8, 0xE4, 0x71 }; if (!ByteOperations.Compare(emptyness, hash)) { flashingPayloads.Add(new FlashingPayload(1, new byte[][] { hash }, new UInt32[] { ((UInt32)flashPart.StartLocation / chunkSize) + i }, new UInt32[] { j }, new Int64[] { position })); if (blankphase && blankcount < maxblank) { foreach (var blankpay in blankbuffer) { flashingPayloads.Add(blankpay); } } blankphase = false; blankcount = 0; blankbuffer.Clear(); } else if (blankcount < maxblank) { blankphase = true; blankcount++; blankbuffer.Add(new FlashingPayload(1, new byte[][] { hash }, new UInt32[] { ((UInt32)flashPart.StartLocation / chunkSize) + i }, new UInt32[] { j }, new Int64[] { position })); } else if (blankcount >= maxblank && blankbuffer.Count > 0) { foreach (var blankpay in blankbuffer) { flashingPayloads.Add(blankpay); } blankbuffer.Clear(); } CurrentProcess1++; ShowProgress(CurrentProcess1, TotalProcess1, startTime, blankphase); } } } return(flashingPayloads.ToArray()); }