Beispiel #1
0
        /// <summary>
        /// Extract type from binary and compare it to expected
        /// </summary>
        /// <param name="binary">Binary to extract type from</param>
        /// <param name="expectedType">Expected type</param>
        private void AssertType(byte[] binary, string expectedType)
        {
            var dump = new RamDump(binary);

            Assert.NotNull(dump.Type);
            Assert.AreEqual(expectedType, dump.Type.Name);
        }
Beispiel #2
0
        /// <summary>
        /// Extract CRC from binary and compare it to expected
        /// </summary>
        /// <param name="binary">Binary to extract CRC from</param>
        /// <param name="expectedFirst">Expected first byte of CRC</param>
        /// <param name="expectedSecond">Expected second byte of CRC</param>
        private void AssertActualCRC(byte[] binary, byte expectedFirst, byte expectedSecond)
        {
            var dump = new RamDump(binary);

            Assert.NotNull(dump.ActualCrc);
            Assert.AreEqual(2, dump.ActualCrc.Length);
            Assert.AreEqual(expectedFirst, dump.ActualCrc[0]);
            Assert.AreEqual(expectedSecond, dump.ActualCrc[1]);
        }
Beispiel #3
0
        /// <summary>
        /// Calculate CRC and compare with actual
        /// </summary>
        /// <param name="binary">Binary dump</param>
        private void AssertCrc(byte[] binary)
        {
            var dump   = new RamDump(binary);
            var hasher = new XModemHasher(dump.Bytes);
            var crc    = hasher.Calculate(dump.CrcUpTo);

            Assert.NotNull(crc);
            Assert.AreEqual(2, crc.Length);
            Assert.AreEqual(dump.ActualCrc[0], crc[0]);
            Assert.AreEqual(dump.ActualCrc[1], crc[1]);
        }
Beispiel #4
0
        /// <summary>
        /// Change type and compare
        /// </summary>
        /// <param name="binary">Binary dump</param>
        /// <param name="expectedType">Expected type</param>
        private void AssertSwitch(byte[] binary, string expectedType)
        {
            var dump     = new RamDump(binary);
            var switcher = RamTypeSwitcherFactory.CreateForSource(dump.Type);
            var changed  = switcher.SwitchType(dump);

            Assert.AreEqual(expectedType, changed.Type.Name);

            Assert.AreEqual(2, changed.ActualCrc.Length);
            Assert.AreNotEqual(dump.ActualCrc[0], changed.ActualCrc[0]);
            Assert.AreNotEqual(dump.ActualCrc[1], changed.ActualCrc[1]);
        }
Beispiel #5
0
 /// <summary>
 /// Notify incoming file read
 /// </summary>
 public void OnIncomingFileSelected(object sender, EventArgs e)
 {
     if (e is PathEventArgs)
     {
         try {
             var path = e.ToString();
             this._dump = RamDump.FromFile(path);
             DumpLoaded?.Invoke(this, new TypeEventArgs(this._dump.Type));
         } catch (Exception ex) {
             MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Beispiel #6
0
        /// <summary>
        /// Change to type to target.
        /// </summary>
        /// <param name="dump">Binary dump</param>
        /// <returns>New dump with changed type</returns>
        public RamDump SwitchType(RamDump dump)
        {
            // Set new type
            var changed = new RamDump(dump)
            {
                Type = TargetType
            };

            // Recalculate hash
            var hasher = new XModemHasher(changed.Bytes);

            changed.ActualCrc = hasher.Calculate(changed.CrcUpTo);

            return(changed);
        }