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; }
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_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); } }
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()); }
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()); }
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()); }