public void Mcdm_AddDasm()
        {
            var addrBase = Address.Ptr32(0x40000);

            var memText = new MemoryArea(Address.Ptr32(0x41000), new byte[8]);
            var memData = new MemoryArea(Address.Ptr32(0x42000), new byte[8]);
            this.segmentMap = new SegmentMap(
                addrBase,
                new ImageSegment(".text", memText, AccessMode.ReadExecute),
                new ImageSegment(".data", memData, AccessMode.ReadWriteExecute));
            Given_Program();
            Given_CodeBlock(memText.BaseAddress, 2);
            mr.ReplayAll();

            var mcdm = new MixedCodeDataModel(program);
            var lines = mcdm.GetLineSpans(2);
            Assert.AreEqual(2, lines.Length);
        }
        public void Mcdm_MoveToLine_FromInvalidPosition()
        {
            var addrBase = Address.Ptr32(0x40000);

            var memText = new MemoryArea(Address.Ptr32(0x41000), new byte[100]);
            var memData = new MemoryArea(Address.Ptr32(0x42000), new byte[8]);
            this.segmentMap = new SegmentMap(
                addrBase,
                new ImageSegment(".text", memText, AccessMode.ReadExecute) { Size = 4 },
                new ImageSegment(".data", memData, AccessMode.ReadWriteExecute));
            Given_Program();
            Given_CodeBlock(memText.BaseAddress, 4);

            mr.ReplayAll();

            var mcdm = new MixedCodeDataModel(program);

            // Read the two instructions, placing curpos in the 'gap'
            // of invalid addresses between the .text and .data segments
            // GetLineSpans should Sanitize the addres and move it to
            // the beginning of .data
            var lines = mcdm.GetLineSpans(2);
            Assert.AreEqual(2, lines.Length);
            Assert.AreEqual("00042000", mcdm.CurrentPosition.ToString());

            // Advance a line. 
            int cLines = mcdm.MoveToLine(mcdm.CurrentPosition, 1);
            Assert.AreEqual(1, cLines);
            Assert.AreEqual("00042008", mcdm.CurrentPosition.ToString());
        }
        public void Mcdm_GetLineSpans_AllLines()
        {
            var addrBase = Address.Ptr32(0x40000);

            var memText = new MemoryArea(Address.Ptr32(0x41000), new byte[100]);
            var memData = new MemoryArea(Address.Ptr32(0x42000), new byte[8]);
            this.segmentMap = new SegmentMap(
                addrBase,
                new ImageSegment(".text", memText, AccessMode.ReadExecute) { Size = 4 },
                new ImageSegment(".data", memData, AccessMode.ReadWriteExecute));
            Given_Program();
            Given_CodeBlock(memText.BaseAddress, 4);
            Given_CodeBlock(Address.Ptr32(0x42004), 4);

            mr.ReplayAll();

            var mcdm = new MixedCodeDataModel(program);

            // Read all lines
            var lines = mcdm.GetLineSpans(5);
            Assert.AreEqual(5, lines.Length);
            Assert.AreEqual("00041000", lines[0].Position.ToString());
            Assert.AreEqual("00041002", lines[1].Position.ToString());
            Assert.AreEqual("00042000", lines[2].Position.ToString());
            Assert.AreEqual("00042004", lines[3].Position.ToString());
            Assert.AreEqual("00042006", lines[4].Position.ToString());
            Assert.AreEqual("00042008", mcdm.CurrentPosition.ToString());
        }
        public void Mcdm_GetLineSpans_InvalidAddress()
        {
            var addrBase = Address.Ptr32(0x40000);

            var memText = new MemoryArea(Address.Ptr32(0x41000), new byte[8]);
            var memData = new MemoryArea(Address.Ptr32(0x42000), new byte[8]);
            this.segmentMap = new SegmentMap(
                addrBase,
                new ImageSegment(".text", memText, AccessMode.ReadExecute),
                new ImageSegment(".data", memData, AccessMode.ReadWriteExecute));
            var program = new Program(segmentMap, arch, platform);

            mr.ReplayAll();

            var mcdm = new MixedCodeDataModel(program);

            // This places the curpos right after the last item in the .text
            // segment.
            mcdm.MoveToLine(Address.Ptr32(0x41008), 0);

            // This should return the first line of the .data segment.
            var lines = mcdm.GetLineSpans(1);
            Assert.AreEqual(1, lines.Length);
            Assert.AreEqual("00042000", lines[0].Position.ToString());
            Assert.AreEqual("00042008", mcdm.CurrentPosition.ToString());
        }
        public void Mcdm_GetLineSpans_MemoryAreaIsLargerThanSegment()
        {
            var addrBase = Address.Ptr32(0x40000);

            var memText = new MemoryArea(Address.Ptr32(0x41000), new byte[100]);
            var memData = new MemoryArea(Address.Ptr32(0x42000), new byte[8]);
            this.segmentMap = new SegmentMap(
                addrBase,
                new ImageSegment(".text", memText, AccessMode.ReadExecute) { Size = 4 },
                new ImageSegment(".data", memData, AccessMode.ReadWriteExecute));
            Given_Program();

            Given_CodeBlock(memText.BaseAddress, 4);

            mr.ReplayAll();

            var mcdm = new MixedCodeDataModel(program);

            // Read the first instruction
            var lines = mcdm.GetLineSpans(1);
            Assert.AreEqual(1, lines.Length);
            Assert.AreEqual("00041000", lines[0].Position.ToString());
            Assert.AreEqual("00041002", mcdm.CurrentPosition.ToString());

            // Read the second and last instruction.
            lines = mcdm.GetLineSpans(1);
            Assert.AreEqual(1, lines.Length);
            Assert.AreEqual("00041002", lines[0].Position.ToString());
            Assert.AreEqual("00042000", mcdm.CurrentPosition.ToString());

            // Read the 8 remaining bytes from .data
            lines = mcdm.GetLineSpans(1);
            Assert.AreEqual(1, lines.Length);
            Assert.AreEqual("00042000", lines[0].Position.ToString());
            Assert.AreEqual("00042008", mcdm.CurrentPosition.ToString());
        }