コード例 #1
0
        public void LoadCFF(string filePath)
        {
            string directory = Path.GetDirectoryName(filePath);

            FlashBytes     = File.ReadAllBytes(filePath);
            FlashContainer = new CaesarFlashContainer(FlashBytes);

            FlashData       = new List <List <byte[]> >();
            SplicePath      = new List <List <string> >();
            MappedAddresses = new List <List <int> >();

            using (BinaryReader reader = new BinaryReader(new MemoryStream(FlashBytes)))
            {
                foreach (FlashDataBlock db in FlashContainer.CaesarFlashHeader.DataBlocks)
                {
                    long fileCursor = 0;

                    List <byte[]> segmentChunks = new List <byte[]>();
                    List <string> spliceStub    = new List <string>();
                    List <int>    mapStub       = new List <int>();

                    foreach (FlashSegment seg in db.FlashSegments)
                    {
                        long offset =
                            db.FlashData +
                            FlashContainer.CaesarFlashHeader.CffHeaderSize +
                            FlashContainer.CaesarFlashHeader.LanguageBlockLength +
                            fileCursor +
                            0x414;

                        fileCursor += seg.SegmentLength;

                        reader.BaseStream.Seek(offset, SeekOrigin.Begin);
                        byte[] fileBytes = reader.ReadBytes(seg.SegmentLength);

                        segmentChunks.Add(fileBytes);
                        spliceStub.Add("");
                        mapStub.Add(seg.FromAddress);
                    }
                    FlashData.Add(segmentChunks);
                    SplicePath.Add(spliceStub);
                    MappedAddresses.Add(mapStub);
                }
            }

            txtLog.Text = GetLog();
        }
コード例 #2
0
        private void cFFExportFlashSegmentsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title       = "Select a CFF File";
            ofd.Filter      = "CFF files (*.cff)|*.cff|All files (*.*)|*.*";
            ofd.Multiselect = false;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    CaesarFlashContainer.ExportCFFMemorySegments(ofd.FileName);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"CFF Export failed: {ex.Message}");
                }
            }
        }