Esempio n. 1
0
        private Trionic7File TryToOpenFileUsingClass(string filename, out SymbolCollection symbol_collection, int filename_size, bool isWorkingFile)
        {
            Trionic7File retval = new Trionic7File();

            retval.onProgress += retval_onProgress;
            SymbolTranslator translator = new SymbolTranslator();
            string help = string.Empty;
            _softwareIsOpen = false;
            _softwareIsOpenDetermined = false;
            m_currentsramfile = string.Empty; // geen sramfile erbij
            barStaticItem1.Caption = "";
            barFilenameText.Caption = "";

            FileInfo fi = new FileInfo(filename);
            try
            {
                fi.IsReadOnly = false;
                btnReadOnly.Caption = "File access OK";
            }
            catch (Exception E)
            {
                logger.Debug("Failed to remove read only flag: " + E.Message);
                btnReadOnly.Caption = "File is READ ONLY";
            }

            try
            {
                if (isWorkingFile)
                {
                    T7FileHeader t7InfoHeader = new T7FileHeader();
                    if (t7InfoHeader.init(filename, m_appSettings.AutoFixFooter))
                    {
                        m_current_softwareversion = t7InfoHeader.getSoftwareVersion();
                        m_currentSramOffsett = ReverseInt(t7InfoHeader.Unknown_9cvalue);
                    }
                    else
                    {
                        m_current_softwareversion = "";
                    }
                }
            }
            catch (Exception E2)
            {
                logger.Debug(E2.Message);
            }
            AddFileToMRUList(filename);
            symbol_collection = retval.ExtractFile(filename, m_appSettings.ApplicationLanguage, m_current_softwareversion);

            SetProgressPercentage(60);
            SetProgress("Examining file");
            System.Windows.Forms.Application.DoEvents();
            if (isWorkingFile)
            {
                if (m_currentSramOffsett == 0)
                {
                    m_currentSramOffsett = retval.SramOffsetForOpenFile;
                    logger.Debug("Overrules m_currentSramOffsett with value from t7file: " + m_currentSramOffsett.ToString("X8"));
                }

                // <GS-27042010> now we need to check if there is a symbol information XML file present.
                try
                {
                    IsSoftwareOpen();
                    // fill in the rest of the parameters
                    barFilenameText.Caption = Path.GetFileNameWithoutExtension(filename);
                }
                catch (Exception E3)
                {
                    logger.Debug(E3.Message);
                }
            }

            if (IsBinaryBiopower())
            {
                foreach (SymbolHelper sh in symbol_collection)
                {
                    if (sh.Varname == "BFuelCal.StartMap")
                    {
                        sh.Varname = "BFuelCal.E85Map";
                        XDFCategories cat = XDFCategories.Undocumented;
                        XDFSubCategory sub = XDFSubCategory.Undocumented;
                        sh.Description = translator.TranslateSymbolToHelpText(sh.Varname, out help, out cat, out sub, m_appSettings.ApplicationLanguage);
                    }
                    if (sh.Userdescription == "BFuelCal.StartMap")
                    {
                        sh.Userdescription = "BFuelCal.E85Map";
                        XDFCategories cat = XDFCategories.Undocumented;
                        XDFSubCategory sub = XDFSubCategory.Undocumented;
                        sh.Description = translator.TranslateSymbolToHelpText(sh.Userdescription, out help, out cat, out sub, m_appSettings.ApplicationLanguage);
                    }
                }
            }
            return retval;
        }
Esempio n. 2
0
 void retval_onProgress(object sender, Trionic7File.ProgressEventArgs e)
 {
     if (e.Percentage < 100)
     {
         barProgress.Visibility = BarItemVisibility.Always;
         barProgress.EditValue = e.Percentage;
         barProgress.Caption = e.Info;
     }
     else
     {
         barProgress.Caption = "Done";
         barProgress.Visibility = BarItemVisibility.Never;
     }
     System.Windows.Forms.Application.DoEvents();
 }
Esempio n. 3
0
        private void simpleButton3_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Binary files|*.bin";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                m_current_comparefilename = ofd.FileName;
                SymbolTranslator translator = new SymbolTranslator();
                string help = string.Empty;
                FileInfo fi = new FileInfo(m_current_comparefilename);
                fi.IsReadOnly = false;

                try
                {
                    T7FileHeader t7InfoHeader = new T7FileHeader();
                    if (t7InfoHeader.init(m_current_comparefilename, false))
                    {
                        m_current_softwareversion = t7InfoHeader.getSoftwareVersion();
                    }
                    else
                    {
                        m_current_softwareversion = "";
                    }
                }
                catch (Exception E2)
                {
                    logger.Debug(E2.Message);
                }
                Trionic7File t7file = new Trionic7File();

                Compare_symbol_collection = t7file.ExtractFile(m_current_comparefilename, 44, m_current_softwareversion);
                // so... now determine the max values for the compare file
                // show the dynograph
                xtraTabControl1.SelectedTabPage = xtraTabPage2;
                LoadGraphWithDetails(); // initial values from original bin
                //DataTable dt = CalculateDataTable(m_current_comparefilename, Compare_symbol_collection);
                //LoadExtraGraphFromCompareBin(dt, m_current_comparefilename);
            }
        }
Esempio n. 4
0
        private void OpenFile(string filename, bool showmessage)
        {
            m_fileiss19 = false;
            m_currentsramfile = string.Empty; // geen sramfile erbij
            barStaticItem1.Caption = "";
            if (filename.ToUpper().EndsWith(".S19"))
            {
                m_fileiss19 = true;
                srec2bin convert = new srec2bin();
                string convertedfile = string.Empty;
                if (convert.ConvertSrecToBin(filename, out convertedfile))
                {
                    filename = convertedfile;
                }
                else
                {
                    frmInfoBox info = new frmInfoBox("Failed to convert S19 file to binary");
                }
            }

            FileInfo fi = new FileInfo(filename);
            try
            {
                fi.IsReadOnly = false;
            }
            catch (Exception E)
            {
                logger.Debug("Failed to clear readonly flag: " + E.Message);
                // failed
            }

            m_currentfile = filename;
            m_appSettings.Lastfilename = m_currentfile;
            if (ValidateFile())
            {
                m_symbols = new SymbolCollection();
                t7file = TryToOpenFileUsingClass(m_currentfile, out m_symbols, m_currentfile_size, true);
                SetProgressPercentage(70);
                SetProgress("Sorting data");
                System.Windows.Forms.Application.DoEvents();
                m_symbols.SortColumn = "Length";
                m_symbols.SortingOrder = GenericComparer.SortOrder.Descending;
                m_symbols.Sort();
                SetProgressPercentage(80);
                SetProgress("Loading data into view");
                gridControlSymbols.DataSource = m_symbols;
                //gridViewSymbols.BestFitColumns();
                SetDefaultFilters();
                Text = String.Format("T7SuitePro v{0} [ {1} ]", System.Windows.Forms.Application.ProductVersion, Path.GetFileName(m_currentfile));
                SetProgressPercentage(90);
                SetProgress("Loading realtime info");
                // also rearrange the symbolnumbers in the realtime view
                UpdateRealTimeDataTableWithNewSRAMValues();
                SetProgressPercentage(100);
                System.Windows.Forms.Application.DoEvents();
            }
            else
            {
                m_symbols = new SymbolCollection();
                gridControlSymbols.DataSource = m_symbols;
                Text = String.Format("T7SuitePro v{0} [ none ]", System.Windows.Forms.Application.ProductVersion);
                if (showmessage)
                {
                    frmInfoBox info = new frmInfoBox("File is not a Trionic 7 binary file!");
                }
                m_currentfile = string.Empty;
            }
            logger.Debug("Number of symbols loaded: " + m_symbols.Count);

            try
            {
                int _width = 18;
                int _height = 16;
                if (m_appSettings.AutoCreateAFRMaps)
                {
                    GetTableMatrixWitdhByName(m_currentfile, m_symbols, "BFuelCal.Map", out _width, out _height);
                    m_AFRMap.RpmYSP = GetSymbolAsIntArray("BFuelCal.RpmYSP");
                    m_AFRMap.AirXSP = GetSymbolAsIntArray("BFuelCal.AirXSP");
                    m_AFRMap.InitializeMaps(_width * _height, m_currentfile);
                }
            }
            catch (Exception E)
            {
                logger.Debug("Failed to load AFR maps: " + E.Message);
            }

            try
            {
                T7FileHeader t7header = new T7FileHeader();
                t7header.init(m_currentfile, false);
                if(CheckFileInLibrary(t7header.getPartNumber()))
                {
                    btnCompareToOriginal.Enabled = true;
                }
                else btnCompareToOriginal.Enabled = false;
            }
            catch (Exception E)
            {
                logger.Debug(E.Message);
            }

            if (m_currentfile != string.Empty) LoadRealtimeTable();
            // <GS-07072011> If the opened file is a BioPower file, then BFuelCal.StartMap = the actual fuel E85 map
            if (IsBinaryBiopower())
            {
                barButtonItem67.Caption = "Petrol VE Map";
                barButtonItem69.Caption = "E85 VE Map";
            }
            else
            {
                barButtonItem67.Caption = "VE map";
                barButtonItem69.Caption = "Startup VE map";
            }

            DynamicTuningMenu();

            System.Windows.Forms.Application.DoEvents();
        }
Esempio n. 5
0
        public bool DisassembleFile(Trionic7File m_trionicFile, string inputfile, string outputfile, SymbolCollection symbols)
        {
            // recursive method when jsr was found
            mnemonics = new MNemonicCollection();
            labels = new MNemonicCollection();

            findLabels(inputfile);

            _passOne = false;

            uint i, t, seg, adr;
            long addr, endaddr, adrcntr, trgaddr, trgaddr1, trgaddr2, trgaddr3, offaddr;

            byte ch1, ch2, ch3, ch4, ch5, ch6, ch7, ch8, ch9, ch10;
            //byte n1, n2, n3, n4;
            //uint infile = 0, outfile = 0,
            uint addoff = 0;
            string inname, outname, offsetval;
            //byte inname[80], outname[80], offsetval[40];
            //byte str[80],cmd[80];
            string str, cmd;
            str = string.Empty;
            for (int temp = 0; temp < 8; temp++)
            {
                A_reg.SetValue(0, temp);
                D_reg.SetValue(0, temp);
            }
            m_symbols = symbols;
            swap = 0;
            addr = offaddr = 0;

            inname = inputfile;
            //infile = 1;
            //            outname = outputfile;
            //outfile = 1;
            //addr = startaddress;
            /********************* DISASSEMBLY STARTS HERE *********************/
            /* Read all the preceding words first */
            adrcntr = 0L;
            //StreamWriter sw = new StreamWriter(outname, false);
            FileStream fsbr = new FileStream(inname, FileMode.Open, FileAccess.Read);
            if (fsbr == null) return false;
            BinaryReader br = new BinaryReader(fsbr);
            if (br == null)
            {
                fsbr.Close();
                //sw.Close();
                return false;
            }
            //fsbr.Position = addr;
            adrcntr = addr;
            // iterate through all functions
            // first get all the pointers to work from
            func_count = 0;
            FileInfo fi = new FileInfo(inputfile);
            CastProgressEvent("Starting disassembly", 0, ProgressType.DisassemblingVectors);
            long[] vectors = Trionic7File.GetVectorAddresses(inputfile);
            for (int vec = 0; vec < vectors.Length; vec++)
            {
                int percentage = ((vec+1) * 100) / vectors.Length;
                CastProgressEvent("Disassembling vectors", percentage, ProgressType.DisassemblingVectors);
                long vector = Convert.ToInt64(vectors.GetValue(vec));

                if (vector != 0 && vector < fi.Length)
                {
                    try
                    {
                        DisassembleFunction(vector, symbols, fsbr, br, 0);
                    }
                    catch (Exception E)
                    {
                        logger.Debug("Failed to handle vector: " + E.Message);
                    }
                }
            }

            CastProgressEvent("Translating vector labels", 0, ProgressType.TranslatingVectors);
            //logger.Debug("Translating vector labels");

            int lblcount = 0;
            string[] names = Trionic7File.GetVectorNames();
            foreach (MNemonicHelper label in labels)
            {
                //logger.Debug("label: " + label.Address.ToString("X8") + " " + label.Mnemonic);
                int percentage = (lblcount++ * 100) / labels.Count;
                CastProgressEvent("Translating vector labels", percentage, ProgressType.TranslatingVectors);
                for (i = 0; i < vectors.Length; i++)
                {
                    if (label.Address == Convert.ToInt64(vectors.GetValue(i)))
                    {
                        label.Mnemonic = names[i].Replace(" ","_").ToUpper() + ":";
                    }
                }
            }
            /*
            logger.Debug("Translating known functions");
            CastProgressEvent("Translating known functions", 0, ProgressType.TranslatingLabels);
            lblcount = 0;
            foreach (MNemonicHelper label in labels)
            {
                int percentage = (lblcount++ * 100) / labels.Count;
                CastProgressEvent("Translating known functions", percentage, ProgressType.TranslatingLabels);
                foreach (MNemonicHelper mnemonic in mnemonics)
                {
                    if (mnemonic.Mnemonic.Contains("JSR") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
                    {
                        mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                        //    break;
                    }
                    else if (mnemonic.Mnemonic.Contains("BEQ") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
                    {
                        mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                    }
                    else if (mnemonic.Mnemonic.Contains("BRA") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
                    {
                        mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                    }
                    else if (mnemonic.Mnemonic.Contains("BLS") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
                    {
                        mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                    }
                    else if (mnemonic.Mnemonic.Contains("BNE") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
                    {
                        mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                    }
                    else if (mnemonic.Mnemonic.Contains("BHI") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
                    {
                        mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                    }
                    else if (mnemonic.Mnemonic.Contains("BCS") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
                    {
                        mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                    }
                    else if (mnemonic.Mnemonic.Contains("BCC") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
                    {
                        mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                    }
                    else if (mnemonic.Mnemonic.Contains("BGE") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
                    {
                        mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                    }
                    else if (mnemonic.Mnemonic.Contains("BLT") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
                    {
                        mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                    }
                    else if (mnemonic.Mnemonic.Contains("BGT") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
                    {
                        mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                    }
                    else if (mnemonic.Mnemonic.Contains("BLE") && mnemonic.Mnemonic.Contains(label.Address.ToString("X8")))
                    {
                        mnemonic.Mnemonic = mnemonic.Mnemonic.Replace(label.Address.ToString("X8"), label.Mnemonic.Replace(":", ""));
                    }
                }
            }*/
            CastProgressEvent("Adding labels", 0, ProgressType.AddingLabels);
            //logger.Debug("Adding labels");
            lblcount = 0;
            foreach (MNemonicHelper label in labels)
            {
                int percentage = (lblcount++ * 100) / labels.Count;
                CastProgressEvent("Adding labels", percentage, ProgressType.AddingLabels);

                label.Address--; // for sequencing
                mnemonics.Add(label);
            }

            //logger.Debug("Sorting data");
            CastProgressEvent("Sorting mnemonics", 0, ProgressType.SortingData);
            mnemonics.SortColumn = "Address";
            mnemonics.SortingOrder = GenericComparer.SortOrder.Ascending;
            mnemonics.Sort();
            CastProgressEvent("Sorting mnemonics", 100, ProgressType.SortingData);
            return true;
        }