Ejemplo n.º 1
0
        // Token: 0x060000FC RID: 252 RVA: 0x0000DAA8 File Offset: 0x0000BCA8
        public void WriteFile(SerialPortDevice portCnn, string strPartitionStartSector, string strPartitionSectorNumber, string pszImageFile, string strFileStartSector, string strFileSectorOffset, string sector_size, string physical_partition_number, string addtionalFirehose, bool chkAck, int?chunkCount)
        {
            long num = Convert.ToInt64(strPartitionSectorNumber);

            if (num == 0L)
            {
                num = 2147483647L;
            }
            long num2 = Convert.ToInt64(strFileStartSector);
            long num3 = Convert.ToInt64(strFileSectorOffset);
            long num4 = Convert.ToInt64(sector_size);
            long num5 = Convert.ToInt64(physical_partition_number);

            Log.w(portCnn.comm.serialPort.PortName, string.Format("write file legnth {0} to partition {1}", this.getFileSize(), strPartitionStartSector));
            long num6 = (this.getFileSize() + num4 - 1L) / num4;

            if (num6 - num2 > num)
            {
                num6 = num2 + num;
            }
            else
            {
                num = num6 - num2;
            }
            string command = string.Format(Firehose.FIREHOSE_PROGRAM, new object[]
            {
                num4,
                num,
                strPartitionStartSector,
                num5,
                addtionalFirehose
            });

            portCnn.comm.SendCommand(command);
            for (long num7 = num2; num7 < num6; num7 += (long)portCnn.comm.m_dwBufferSectors)
            {
                long num8 = num6 - num7;
                num8 = ((num8 < (long)portCnn.comm.m_dwBufferSectors) ? num8 : ((long)portCnn.comm.m_dwBufferSectors));
                Log.w(portCnn.comm.serialPort.PortName, string.Format("WriteFile position {0}, size {1}", (num4 * num7).ToString("X"), num4 * num8));
                long   offset        = num3 + num4 * num7;
                int    size          = (int)(num4 * num8);
                int    num9          = 0;
                byte[] bytesFromFile = this.GetBytesFromFile(offset, size, out num9);
                portCnn.comm.WritePort(bytesFromFile, 0, bytesFromFile.Length);
            }
            if (chkAck)
            {
                string message = null;
                if (!portCnn.comm.chkRspAck(out message, chunkCount.Value))
                {
                    throw new Exception(message);
                }
            }
        }
Ejemplo n.º 2
0
        public void WriteFile(SerialPortDevice portCnn, string strPartitionStartSector, string strPartitionSectorNumber, string pszImageFile, string strFileStartSector, string strFileSectorOffset, string sector_size, string physical_partition_number)
        {
            long num1 = Convert.ToInt64(strPartitionSectorNumber);

            if (num1 == 0L)
            {
                num1 = int.MaxValue;
            }
            long int64_1 = Convert.ToInt64(strFileStartSector);
            long int64_2 = Convert.ToInt64(strFileSectorOffset);
            long int64_3 = Convert.ToInt64(sector_size);
            long int64_4 = Convert.ToInt64(physical_partition_number);

            Log.w(portCnn.comm.serialPort.PortName, string.Format("write file {0} legnth {1} to partition {2}", filePath, getFileSize(), strPartitionStartSector));
            long num2 = (getFileSize() + int64_3 - 1L) / int64_3;

            if (num2 - int64_1 > num1)
            {
                num2 = int64_1 + num1;
            }
            else
            {
                num1 = num2 - int64_1;
            }
            string str = string.Format(Firehose.FIREHOSE_PROGRAM, int64_3, num1, strPartitionStartSector, int64_4);

            portCnn.comm.SendCommand(str);
            Log.w(portCnn.comm.serialPort.PortName, str);
            long num3 = int64_1;

            while (num3 < num2)
            {
                long num4 = num2 - num3;
                long num5 = num4 < portCnn.comm.m_dwBufferSectors ? num4 : portCnn.comm.m_dwBufferSectors;
                Log.w(portCnn.comm.serialPort.PortName, string.Format("WriteFile position {0}, size {1}", (int64_3 * num3).ToString("X"), int64_3 * num5));
                long   offset        = int64_2 + int64_3 * num3;
                int    size          = (int)(int64_3 * num5);
                int    n             = 0;
                byte[] bytesFromFile = GetBytesFromFile(offset, size, out n);
                portCnn.comm.WritePort(bytesFromFile, 0, bytesFromFile.Length);
                num3 += portCnn.comm.m_dwBufferSectors;
            }
        }
Ejemplo n.º 3
0
        public void WriteSparseFileToDevice(SerialPortDevice portCnn, string pszPartitionStartSector, string pszPartitionSectorNumber, string pszImageFile, string pszFileStartSector, string pszSectorSizeInBytes, string pszPhysicalPartitionNumber)
        {
            int  int32_1 = Convert.ToInt32(pszPartitionStartSector);
            int  int32_2 = Convert.ToInt32(pszPartitionSectorNumber);
            int  int32_3 = Convert.ToInt32(pszFileStartSector);
            long offset1 = 0;
            int  int32_4 = Convert.ToInt32(pszSectorSizeInBytes);

            Convert.ToInt32(pszPhysicalPartitionNumber);
            SparseImageHeader sparseImageHeader = new SparseImageHeader();
            string            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");
            }
            int size1 = Marshal.SizeOf(sparseImageHeader);
            int n     = 0;
            SparseImageHeader stuct1 = (SparseImageHeader)CommandFormat.BytesToStuct(GetBytesFromFile(offset1, size1, out n), typeof(SparseImageHeader));
            long 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 (int index = 0; index < stuct1.uTotalChunks; ++index)
                {
                    Log.w(portCnn.comm.serialPort.PortName, string.Format("total chunks {0}, current chunk {1}", stuct1.uTotalChunks, index));
                    int size2 = Marshal.SizeOf(new SparseChunkHeader());
                    SparseChunkHeader stuct2 = (SparseChunkHeader)CommandFormat.BytesToStuct(GetBytesFromFile(offset2, size2, out n), typeof(SparseChunkHeader));
                    offset2 += stuct1.uChunkHeaderSize;
                    int num1 = (int)stuct1.uBlockSize * (int)stuct2.uChunkSize;
                    int 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;
                        }
                        string strPartitionStartSector  = int32_1.ToString();
                        string strPartitionSectorNumber = num2.ToString();
                        string strFileStartSector       = (offset2 / int32_4).ToString();
                        string 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;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        // 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++;
            }
        }