예제 #1
0
        public MainForm(string[] args)
        {
            InitializeComponent();
            if (args.Length > 0)
            {
                // Use first argument as source file
                if (File.Exists(args[0]))
                {
                    coff = OpenCoffFile(args[0]);
                    if (args.Length > 1)
                    {
                        // Use other parameters as section names
                        List <Coff.Section> sections = coff.GetSections();

                        for (int index = 1; index < args.Length; ++index)
                        {
                            string sec_name = args[index];
                            foreach (Coff.Section sec in sections)
                            {
                                if (sec.name == sec_name)
                                {
                                    sections.Add(sec);
                                    break;
                                }
                            }
                        }
                        toolStripStatusLabel1.Text = UpdateChecksumInformation(coff, sections);
                    }
                }
                else
                {
                    MessageBox.Show("File to open not found !", Title, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// This function simply write checksum information
        /// </summary>
        /// <param name="executable">Coff executable</param>
        /// <param name="sections">List of sections to be used to compute checksum</param>
        string UpdateChecksumInformation(Coff executable, List <Coff.Section> sections)
        {
            byte[] flashData = PrepareRawData(executable, sections);
            Crc32  crc32     = new Crc32();

            crc32.AddData(flashData);
            return(string.Format("CRC32: 0x{0:X8}, Checksum32: 0x{1:X8}", crc32.Crc32Value, Checksum32.Calculate(flashData)));
        }
예제 #3
0
        private byte[] PrepareRawData(Coff coff, List <Coff.Section> section_list)
        {
            byte[] flashData;
            if (coff.header.VersionID == 0x00c1)
            {
                flashData = new byte[0x10000];
            }
            else
            {
                flashData = new byte[0x20000];
            }

            for (int i = 0; i < flashData.Length; ++i)
            {
                flashData[i] = 0xFF;
            }

            foreach (Coff.Section section in section_list)
            {
                Array.Copy(section.rawData, 0, flashData, section.PhysicalAddress & 0xFFFF, section.Size);
            }
            return(flashData);
        }
예제 #4
0
        private Coff OpenCoffFile(string fileName)
        {
            Coff coff = new Coff(fileName);

            if (coff != null)
            {
                Text = Title + " - " + Path.GetFileName(fileName);

                // Write info
                textBoxInfo.Text  = "EXEC CODE ADDR: " + coff.optionalHeader.ExecCodeAddress.ToString("X4") + Environment.NewLine;
                textBoxInfo.Text += "EXEC CODE SIZE: " + coff.optionalHeader.ExecCodeSize + Environment.NewLine;
                textBoxInfo.Text += "BUILD DATE: " + coff.header.Timestamp.ToString() + Environment.NewLine;

                // Write list view
                listViewSections.Items.Clear();
                foreach (Coff.Section section in coff.GetSections())
                {
                    ListViewItem lvi = new ListViewItem(new string[] { section.name, section.PhysicalAddress.ToString("X4"), section.Size.ToString(), section.MemoryPage.ToString() });
                    listViewSections.Items.Add(lvi);
                }
            }
            return(coff);
        }