public void WriteSparseFileToDevice(SerialPortDevice portCnn, string pszPartitionStartSector, string pszPartitionSectorNumber, string pszImageFile, string pszFileStartSector, string pszSectorSizeInBytes, string pszPhysicalPartitionNumber) { var int32_1 = Convert.ToInt32(pszPartitionStartSector); var int32_2 = Convert.ToInt32(pszPartitionSectorNumber); var int32_3 = Convert.ToInt32(pszFileStartSector); long offset1 = 0; var int32_4 = Convert.ToInt32(pszSectorSizeInBytes); Convert.ToInt32(pszPhysicalPartitionNumber); var sparseImageHeader = new SparseImageHeader(); var str = ""; if (int32_3 != 0) { str = "ERROR_BAD_FORMAT"; Log.w(portCnn.comm.serialPort.PortName, str); } if (int32_4 == 0) { str = "ERROR_BAD_FORMAT"; Log.w(portCnn.comm.serialPort.PortName, "ERROR_BAD_FORMAT"); } var size1 = Marshal.SizeOf(sparseImageHeader); var n = 0; var stuct1 = (SparseImageHeader)CommandFormat.BytesToStuct(GetBytesFromFile(offset1, size1, out n), typeof(SparseImageHeader)); var offset2 = offset1 + stuct1.uFileHeaderSize; if ((int)stuct1.uMagic != -316211398) { str = "ERROR_BAD_FORMAT"; Log.w(portCnn.comm.serialPort.PortName, "ERROR_BAD_FORMAT"); } if (stuct1.uMajorVersion != 1) { str = "ERROR_UNSUPPORTED_TYPE"; Log.w(portCnn.comm.serialPort.PortName, "ERROR_UNSUPPORTED_TYPE"); } if (stuct1.uBlockSize % int32_4 != 0L) { str = "ERROR_BAD_FORMAT"; Log.w(portCnn.comm.serialPort.PortName, "ERROR_BAD_FORMAT"); } if (int32_2 != 0 && stuct1.uBlockSize * stuct1.uTotalBlocks / int32_4 > int32_2) { str = "ERROR_FILE_TOO_LARGE"; Log.w(portCnn.comm.serialPort.PortName, "ERROR_FILE_TOO_LARGE"); } if (!string.IsNullOrEmpty(str)) { FlashingDevice.UpdateDeviceStatus(portName, new float?(), str, "error", false); } else { for (var index = 0; index < stuct1.uTotalChunks; ++index) { Log.w(portCnn.comm.serialPort.PortName, string.Format("total chunks {0}, current chunk {1}", stuct1.uTotalChunks, index)); var size2 = Marshal.SizeOf(new SparseChunkHeader()); var stuct2 = (SparseChunkHeader)CommandFormat.BytesToStuct(GetBytesFromFile(offset2, size2, out n), typeof(SparseChunkHeader)); offset2 += stuct1.uChunkHeaderSize; var num1 = (int)stuct1.uBlockSize * (int)stuct2.uChunkSize; var num2 = num1 / int32_4; switch (stuct2.uChunkType) { case 51905: if (stuct2.uTotalSize != stuct1.uChunkHeaderSize + num1) { Log.w(portCnn.comm.serialPort.PortName, "ERROR_BAD_FORMAT"); FlashingDevice.UpdateDeviceStatus(portName, new float?(), "ERROR_BAD_FORMAT", "error", false); return; } var strPartitionStartSector = int32_1.ToString(); var strPartitionSectorNumber = num2.ToString(); var strFileStartSector = (offset2 / int32_4).ToString(); var strFileSectorOffset = (offset2 % int32_4).ToString(); WriteFile(portCnn, strPartitionStartSector, strPartitionSectorNumber, pszImageFile, strFileStartSector, strFileSectorOffset, pszSectorSizeInBytes, pszPhysicalPartitionNumber); offset2 += int32_4 * num2; int32_1 += num2; break; case 51907: if ((int)stuct2.uTotalSize != stuct1.uChunkHeaderSize) { Log.w(portCnn.comm.serialPort.PortName, "ERROR_BAD_FORMAT"); } int32_1 += num2; break; default: Log.w(portCnn.comm.serialPort.PortName, "ERROR_UNSUPPORTED_TYPE"); break; } } } }
// Token: 0x060000FD RID: 253 RVA: 0x0000DC64 File Offset: 0x0000BE64 public void WriteSparseFileToDevice(SerialPortDevice portCnn, string pszPartitionStartSector, string pszPartitionSectorNumber, string pszImageFile, string pszFileStartSector, string pszSectorSizeInBytes, string pszPhysicalPartitionNumber, string addtionalFirehose) { int num = Convert.ToInt32(pszPartitionStartSector); int num2 = Convert.ToInt32(pszPartitionSectorNumber); int num3 = Convert.ToInt32(pszFileStartSector); long num4 = 0L; int num5 = Convert.ToInt32(pszSectorSizeInBytes); Convert.ToInt32(pszPhysicalPartitionNumber); SparseImageHeader sparseImageHeader = default(SparseImageHeader); string text = ""; if (num3 != 0) { text = "ERROR_BAD_FORMAT"; Log.w(portCnn.comm.serialPort.PortName, text); } if (num5 == 0) { text = "ERROR_BAD_FORMAT"; Log.w(portCnn.comm.serialPort.PortName, "ERROR_BAD_FORMAT"); } int size = Marshal.SizeOf(sparseImageHeader); int num6 = 0; byte[] bytesFromFile = this.GetBytesFromFile(num4, size, out num6); sparseImageHeader = (SparseImageHeader)CommandFormat.BytesToStuct(bytesFromFile, typeof(SparseImageHeader)); num4 += (long)((ulong)sparseImageHeader.uFileHeaderSize); if (sparseImageHeader.uMagic != 3978755898u) { text = "ERROR_BAD_FORMAT"; Log.w(portCnn.comm.serialPort.PortName, string.Format("ERROR_BAD_FORMAT {0}", sparseImageHeader.uMagic.ToString())); } if (sparseImageHeader.uMajorVersion != 1) { text = "ERROR_UNSUPPORTED_TYPE"; Log.w(portCnn.comm.serialPort.PortName, string.Format("ERROR_UNSUPPORTED_TYPE {0}", sparseImageHeader.uMajorVersion.ToString())); } if ((ulong)sparseImageHeader.uBlockSize % (ulong)((long)num5) != 0UL) { text = "ERROR_BAD_FORMAT"; Log.w(portCnn.comm.serialPort.PortName, string.Format("ERROR_BAD_FORMAT {0}", sparseImageHeader.uBlockSize.ToString())); } if (num2 != 0 && (ulong)(sparseImageHeader.uBlockSize * sparseImageHeader.uTotalBlocks) / (ulong)((long)num5) > (ulong)((long)num2)) { text = "ERROR_FILE_TOO_LARGE"; Log.w(portCnn.comm.serialPort.PortName, string.Format("ERROR_FILE_TOO_LARGE size {0} ullPartitionSectorNumber {1}", ((long)((ulong)(sparseImageHeader.uBlockSize * sparseImageHeader.uTotalBlocks) / (ulong)((long)num5))).ToString(), num2.ToString())); } if (!string.IsNullOrEmpty(text)) { throw new Exception(text); } int num7 = 0; int num8 = 1; while ((long)num8 <= (long)((ulong)sparseImageHeader.uTotalChunks)) { Log.w(portCnn.comm.serialPort.PortName, string.Format("total chunks {0}, current chunk {1}", sparseImageHeader.uTotalChunks, num8)); SparseChunkHeader sparseChunkHeader = default(SparseChunkHeader); size = Marshal.SizeOf(sparseChunkHeader); float num9 = 0f; bytesFromFile = this.GetBytesFromFile(num4, size, out num6, out num9); sparseChunkHeader = (SparseChunkHeader)CommandFormat.BytesToStuct(bytesFromFile, typeof(SparseChunkHeader)); num4 += (long)((ulong)sparseImageHeader.uChunkHeaderSize); int num10 = (int)(sparseImageHeader.uBlockSize * sparseChunkHeader.uChunkSize); int num11 = num10 / num5; if (sparseChunkHeader.uChunkType == 51905) { if ((ulong)sparseChunkHeader.uTotalSize != (ulong)((long)((int)sparseImageHeader.uChunkHeaderSize + num10))) { Log.w(portCnn.comm.serialPort.PortName, "ERROR_BAD_FORMAT"); throw new Exception("ERROR_BAD_FORMAT"); } string strPartitionStartSector = num.ToString(); string strPartitionSectorNumber = num11.ToString(); string strFileStartSector = (num4 / (long)num5).ToString(); string strFileSectorOffset = (num4 % (long)num5).ToString(); num7++; bool chkAck = false; int value = 0; if (sparseImageHeader.uTotalChunks <= 10u) { if ((long)num8 == (long)((ulong)sparseImageHeader.uTotalChunks)) { value = num7; chkAck = true; } } else { if (num7 % 10 == 0) { value = 10; chkAck = true; } if ((long)num8 == (long)((ulong)sparseImageHeader.uTotalChunks)) { value = num7 % 10; chkAck = true; } } this.WriteFile(portCnn, strPartitionStartSector, strPartitionSectorNumber, pszImageFile, strFileStartSector, strFileSectorOffset, pszSectorSizeInBytes, pszPhysicalPartitionNumber, addtionalFirehose, chkAck, new int?(value)); num4 += (long)(num5 * num11); num += num11; } else if (sparseChunkHeader.uChunkType == 51907) { if (sparseChunkHeader.uTotalSize != (uint)sparseImageHeader.uChunkHeaderSize) { Log.w(portCnn.comm.serialPort.PortName, "ERROR_BAD_FORMAT"); } num += num11; if ((long)num8 == (long)((ulong)sparseImageHeader.uTotalChunks)) { int num12 = num7 % 10; if (num12 > 0) { string message = null; if (!portCnn.comm.chkRspAck(out message, num12)) { throw new Exception(message); } } } } else { Log.w(portCnn.comm.serialPort.PortName, string.Format("ERROR_UNSUPPORTED_TYPE {0}", sparseChunkHeader.uChunkType.ToString())); } num8++; } }