예제 #1
0
        private void SaveHex(byte[] data)
        {
            ////Writing the main firmware or empty on choice
            if (!OptionFull.Checked)
            {
                for (int i = Firmware.BOOTLOADER_SIZE; i < Firmware.XOR_TABLE_OFFSET; i++)
                {
                    data[i] = 0xFF;
                }
            }
            //Disable the CP0 bit if necessary
            if (!cp0.Checked)
            {
                data[Firmware.CP0_ADDRESS] |= 0x04;
            }
            ////Writing serial code
            byte[] info = new byte[Firmware.BLOCK_SIZE];
            string s1   = TxtDevcode.Text + new string(' ', Firmware.DEVCODE_LENGHT - TxtDevcode.Text.Length);
            string s2   = TxtSerial.Text + new string(' ', Firmware.SERIALCODE_LENGHT - TxtSerial.Text.Length);

            Array.Copy(Encoding.ASCII.GetBytes(s1), 0, info, 0, Firmware.DEVCODE_LENGHT);
            Array.Copy(Encoding.ASCII.GetBytes(s2), 0, info, Firmware.DEVCODE_LENGHT, Firmware.SERIALCODE_LENGHT);
            firmware.EncryptSerial(info, data);
            Array.Copy(info, 0, data, Firmware.SERIAL_OFFSET, info.Length);

            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Title           = "Firmware output hex file";
            dlg.Filter          = "hex files (*.hex)|*.hex|All files (*.*)|*.*";
            dlg.CheckPathExists = true;
            dlg.OverwritePrompt = true;
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if (File.Exists(dlg.FileName))
                    {
                        File.Delete(dlg.FileName);
                    }
                    if (dlg.FileName.EndsWith(".hex"))
                    {
                        HexWriter hexwriter = new HexWriter(File.CreateText(dlg.FileName));
                        hexwriter.WriteHex(data);
                    }
                    else
                    {
                        File.WriteAllBytes(dlg.FileName, data);
                    }
                    SystemSounds.Asterisk.Play();
                }
                catch
                {
                    MessageBox.Show(string.Format("Error creating file {0}", dlg.FileName), "TL866",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #2
0
파일: mainform.cs 프로젝트: junimp/TL866
 private void Dump(string filepath)
 {
     byte[] buffer     = new byte[Firmware.FLASH_SIZE]; //128Kbytes buffer
     byte[] readbuffer = new byte[64];
     for (int i = 0; i < buffer.Length; i += 64)
     {
         if (worker.CancellationPending)
         {
             return;
         }
         usbdevice.Write(new byte[]
         {
             Firmware.DUMPER_READ_FLASH, 64, (byte)(i & 0xFF), (byte)((i >> 8) & 0xFF),
             (byte)((i >> 16) & 0xFF)
         });
         if (usbdevice.Read(readbuffer) != 64)
         {
             MessageBox.Show("Read error!", "TL866", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             return;
         }
         Array.Copy(readbuffer, 0, buffer, i, readbuffer.Length);
         SetProgressBar(i);
         Application.DoEvents();
     }
     Array.Copy(firmware.GetUnencryptedFirmware(devtype), 0, buffer, Firmware.BOOTLOADER_SIZE,
                Firmware.UNENCRYPTED_FIRMWARE_SIZE);
     try
     {
         if (filepath.EndsWith(".hex"))
         {
             HexWriter hexwriter = new HexWriter(File.CreateText(filepath));
             hexwriter.WriteHex(buffer);
         }
         else
         {
             byte[] info = new byte[Firmware.BLOCK_SIZE];
             Array.Copy(buffer, Firmware.SERIAL_OFFSET, info, 0, info.Length);
             firmware.DecryptSerial(info, buffer);
             File.WriteAllBytes(filepath + "_info.bin", info);
             File.WriteAllBytes(filepath, buffer);
         }
         MessageBox.Show("Firmware dump complete!", "TL866", MessageBoxButtons.OK, MessageBoxIcon.Information);
         SetProgressBar(0);
     }
     catch
     {
         SetProgressBar(0);
         MessageBox.Show("Error creating dump.hex file", "TL866", MessageBoxButtons.OK,
                         MessageBoxIcon.Exclamation);
     }
 }