Esempio n. 1
0
        private bool verifychecksum(bool showinterface)
        {
            //Verify checksums and show result

            bool m_checksums_ok = true;
            if (File.Exists(m_currentfile))
            {
                T7FileHeader t7InfoHeader = null;
                t7InfoHeader = new T7FileHeader();
                t7InfoHeader.init(m_currentfile, m_appSettings.AutoFixFooter);

                ChecksumHandler csHandler = new ChecksumHandler();
                csHandler.SramOffset = m_currentSramOffsett;
                int fwLength = t7InfoHeader.getFWLength();
                int calculatedFWChecksum = csHandler.calculateFWChecksum(m_currentfile);

                uint calculatedF2Checksum = csHandler.calculateF2Checksum(m_currentfile, 0, fwLength);
                int calculatedFBChecksum = csHandler.calculateFBChecksum(m_currentfile, 0, fwLength);

                int readF2checksum = t7InfoHeader.getChecksumF2();
                int readFBchecksum = t7InfoHeader.getChecksumFB();

                if (readF2checksum != 0)
                {
                    if (t7InfoHeader.getChecksumF2() != (int)calculatedF2Checksum)
                    {
                        m_checksums_ok = false;
                    }
                }

                if (t7InfoHeader.getChecksumFB() != calculatedFBChecksum)
                {
                    m_checksums_ok = false;
                }
                if (csHandler.getFWChecksum(m_currentfile) != calculatedFWChecksum)
                {
                    m_checksums_ok = false;
                }
                if (m_checksums_ok)
                {
                    if (showinterface)
                    {
                        frmInfoBox info = new frmInfoBox("Checksums verified and all matched!");
                    }
                }
                else
                {
                    if (m_appSettings.AutoChecksum)
                    {
                        logger.Debug("calculatedF2Checksum = " + calculatedF2Checksum.ToString("X8") + " readF2checksum = " + readF2checksum.ToString("X8"));
                        logger.Debug("calculatedFBChecksum = " + calculatedFBChecksum.ToString("X8") + " readFBchecksum = " + readFBchecksum.ToString("X8"));
                        logger.Debug("calculatedFWChecksum = " + calculatedFWChecksum.ToString("X8") + " csHandler.getFWChecksum(m_currentfile) = " + csHandler.getFWChecksum(m_currentfile).ToString("X8"));

                        csHandler.setFWChecksum(m_currentfile, calculatedFWChecksum);
                        t7InfoHeader.setChecksumF2((int)calculatedF2Checksum);
                        t7InfoHeader.setChecksumFB(calculatedFBChecksum);
                        t7InfoHeader.save(m_currentfile);
                        if (showinterface)
                        {
                            frmInfoBox info = new frmInfoBox("Checksums did not verify ok, but were recalculated.");
                        }

                    }
                    else
                    {
                        if (MessageBox.Show("Checksums did not verify ok, do you want to recalculate and update the checksums?", "Question", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            csHandler.setFWChecksum(m_currentfile, calculatedFWChecksum);
                            t7InfoHeader.setChecksumF2((int)calculatedF2Checksum);
                            t7InfoHeader.setChecksumFB(calculatedFBChecksum);
                            t7InfoHeader.save(m_currentfile);
                        }
                    }
                }
            }
            else
            {
                if (showinterface)
                {
                    frmInfoBox info = new frmInfoBox("Current file does not exsist, please re-open the file.");
                }
            }
            return m_checksums_ok;
        }
Esempio n. 2
0
        private void UpdateChecksum(string m_fileName)
        {
            T7FileHeader t7InfoHeader = null;
            t7InfoHeader = new T7FileHeader();
            t7InfoHeader.init(m_fileName, m_appSettings.AutoFixFooter);

            ChecksumHandler csHandler = new ChecksumHandler();
            csHandler.SramOffset = m_currentSramOffsett;
            int fwLength = t7InfoHeader.getFWLength();
            int calculatedFWChecksum = csHandler.calculateFWChecksum(m_fileName);
            logger.Debug("FW Checksum: " + calculatedFWChecksum.ToString("X8"));
            csHandler.setFWChecksum(m_fileName, calculatedFWChecksum);

            uint calculatedF2Checksum = csHandler.calculateF2Checksum(m_fileName, 0, fwLength);
            int calculatedFBChecksum = csHandler.calculateFBChecksum(m_fileName, 0, fwLength);
            t7InfoHeader.setChecksumF2((int)calculatedF2Checksum);
            t7InfoHeader.setChecksumFB(calculatedFBChecksum);
            t7InfoHeader.save(m_fileName);
        }