Provides a text model that mixes code and data.
Inheritance: TextViewModel
コード例 #1
0
 public MixedCodeDataModel(MixedCodeDataModel that)
 {
     this.program      = that.program;
     this.addrCur      = that.addrCur;
     this.addrEnd      = that.addrEnd;
     this.instructions = that.instructions;
     this.LineCount    = that.LineCount;
 }
コード例 #2
0
ファイル: MixedCodeDataModel.cs プロジェクト: uxmal/reko
 public MixedCodeDataModel(MixedCodeDataModel that)
 {
     this.program = that.program;
     this.addrCur = that.addrCur;
     this.addrEnd = that.addrEnd;
     this.instructions = that.instructions;
     this.LineCount = that.LineCount;
 }
コード例 #3
0
        private void RefreshModel()
        {
            var currentAddress = Model.CurrentPosition;
            var model          = new MixedCodeDataModel(program);

            model.MoveToLine(currentAddress, 0);
            this.addrTop = model.CurrentPosition as Address;
            this.Model   = model;
        }
コード例 #4
0
 private void OnProgramChanged()
 {
     if (program != null)
     {
         Model   = new MixedCodeDataModel(program);
         addrTop = (Address)Model.CurrentPosition;
     }
     else
     {
         Model   = new EmptyEditorModel();
         addrTop = null;
     }
 }
コード例 #5
0
ファイル: MixedCodeDataControl.cs プロジェクト: relaxar/reko
 private void OnProgramChanged()
 {
     try
     {
         if (program != null)
         {
             Model = new MixedCodeDataModel(program);
             addrTop = Model.CurrentPosition as Address;
             return;
         }
     }
     catch (Exception ex)
     {
         Services.RequireService<IDiagnosticsService>().Error(ex, "An error occurred while displaying the program.");
     }
     Model = new EmptyEditorModel();
     addrTop = null;
 }
コード例 #6
0
 private void OnProgramChanged()
 {
     try
     {
         if (program != null)
         {
             Model   = new MixedCodeDataModel(program);
             addrTop = Model.CurrentPosition as Address;
             return;
         }
     }
     catch (Exception ex)
     {
         Services.RequireService <IDiagnosticsService>().Error(ex, "An error occurred while displaying the program.");
     }
     Model   = new EmptyEditorModel();
     addrTop = null;
 }
コード例 #7
0
ファイル: MixedCodeDataControl.cs プロジェクト: relaxar/reko
 private void RefreshModel()
 {
     var currentAddress = Model.CurrentPosition;
     var model = new MixedCodeDataModel(program);
     model.MoveToLine(currentAddress, 0);
     this.addrTop = model.CurrentPosition as Address;
     this.Model = model;
 }
コード例 #8
0
        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());
        }
コード例 #9
0
        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());
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        public void Mcdm_MoveFraction()
        {
            var addrBase = Address.Ptr32(0x40000);

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

            Given_CodeBlock(memText.BaseAddress, 4);

            mr.ReplayAll();

            var mcdm = new MixedCodeDataModel(program);
            Debug.Print("LineCount: {0}", mcdm.LineCount);
            mcdm.SetPositionAsFraction(0, 1);
            Assert.AreSame(mcdm.StartPosition, mcdm.CurrentPosition);
            mcdm.SetPositionAsFraction(2, 1);
            Assert.AreSame(mcdm.EndPosition, mcdm.CurrentPosition);
            mcdm.SetPositionAsFraction(1, 2);
            Assert.AreEqual("00042000", mcdm.CurrentPosition.ToString());
        }
コード例 #12
0
        public void Mcdm_GetPositionAsFraction()
        {
            var addrBase = Address.Ptr32(0x40000);

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

            var mcdm = new MixedCodeDataModel(program);
            var num_lines = 4;
            for(int i = 0; i <= num_lines; i++)
            {
                mcdm.MoveToLine(mcdm.StartPosition, i);
                var frac = mcdm.GetPositionAsFraction();

                var format = @"
  Expected: {0}/{1}
  But was:  {2}/{3}
";
                var msg = string.Format(format, i, num_lines, frac.Item1, frac.Item2);
                Assert.IsTrue((i * frac.Item2 == num_lines * frac.Item1), msg);
            }
        }
コード例 #13
0
        public void Mcdm_MoveToLastLineOfItem()
        {
            var addrBase = Address.Ptr32(0x40000);

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

            Given_CodeBlock(Address.Ptr32(0x40FF9), 4);

            mr.ReplayAll();

            var mcdm = new MixedCodeDataModel(program);

            mcdm.MoveToLine(mcdm.CurrentPosition, 2);
            var curPos = (Address)mcdm.CurrentPosition;

/*
            ***************start position**************************
            0x40FD5                FF FF FF FF FF FF FF FF FF FF FF
            0x40FE0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
            *********curent position after moving******************
            0x40FF0 FF FF FF FF FF FF FF FF FF
            0x40FF9 add r2,r2
            0x40FFA add r2,r2
*/

            Assert.AreEqual("00040FF0", curPos.ToString());
        }
コード例 #14
0
        public void Mcdm_MoveForward()
        {
            var addrBase = Address.Ptr32(0x40000);

            // 041000: inst0
            // 041002: inst1
            // 042000: data <16 bytes>
            // 042010: data <16 bytes>

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

            Given_CodeBlock(memText.BaseAddress, 4);

            mr.ReplayAll();

            var mcdm = new MixedCodeDataModel(program);
            // Advance 1 line into another piece of code.
            int delta = mcdm.MoveToLine(mcdm.CurrentPosition, 1);
            Assert.AreEqual(1, delta);
            // move another line of code and then into data.
            delta = mcdm.MoveToLine(mcdm.CurrentPosition, 2);
            Assert.AreEqual(2, delta);
            Assert.AreEqual("00042010", mcdm.CurrentPosition.ToString());
            // Another line of data
            delta = mcdm.MoveToLine(mcdm.CurrentPosition, 1);
            Assert.AreEqual("00042020", mcdm.CurrentPosition.ToString());
            Assert.AreEqual(1, delta);
            // Pegged at end
            delta = mcdm.MoveToLine(mcdm.CurrentPosition, 1);
            Assert.AreEqual("00042020", mcdm.CurrentPosition.ToString());
            Assert.AreEqual(0, delta);

            mcdm.MoveToLine(mcdm.StartPosition, 2);
            Assert.AreEqual("00042000", mcdm.CurrentPosition.ToString());
        }
コード例 #15
0
        private bool ShowItem(MixedCodeDataModel.DataItemNode item)
        {
            if (!showProcedures && item.Proc != null)
                return false;

            if (segment != null && !segment.IsInRange(item.StartAddress))
                return false;

            return true;
        }
コード例 #16
0
        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());
        }
コード例 #17
0
        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());
        }