/// <summary> /// Gets the disassembly lines. /// </summary> /// <param name="threadId">The thread identifier.</param> /// <param name="numInstructions">The number instructions.</param> /// <returns>IEnumerable<DisassemblyLine></returns> /// <exception cref="ArgumentOutOfRangeException">Number of instructions must be > 0</exception> public IEnumerable <DisassemblyLine> GetDisassemblyLines(int threadId, int numInstructions) { if (numInstructions <= 0) { throw new ArgumentOutOfRangeException(nameof(numInstructions), "Number of instructions must be > 0"); } var ipRegister = DebugEngineProxy.Is32Bit ? "eip" : "rip"; var instructionText = DebugEngineProxy.Execute(threadId, $"u {ipRegister} L{numInstructions:X}"); var matches = Regex.Matches(instructionText, @"(?<ip>[a-fA-F0-9`]+)\s+(?<opcode>[a-fA-F0-9]+)\s+(?<ins>\w+)\s+(?<extra>.+)?"); var list = new List <DisassemblyLine>(); foreach (var match in matches.Cast <Match>()) { var ip = match.Groups["ip"].Success ? Convert.ToUInt64(match.Groups["ip"].Value.Replace("`", ""), 16) : 0; byte[] opcode = null; if (match.Groups["opcode"].Success) { opcode = ByteArrayBuilder.StringToByteArray(match.Groups["opcode"].Value); } var instruction = match.Groups["ins"].Success ? match.Groups["ins"].Value : ""; var note = match.Groups["extra"].Success ? match.Groups["extra"].Value : ""; var newLine = new DisassemblyLine(ip, opcode, instruction, note); list.Add(newLine); } return(list); }
public void Get_The_Current_Frame_Correctly() { // arrange var engBuilder = new DebugEngineProxyBuilder(); engBuilder.WithExecuteResult("!positions", @">Thread ID=0x7590 - Position: 168CC:0 Thread ID=0x12A0 - Position: 211F5:0 Thread ID=0x6CDC - Position: 21D59:0 Thread ID=0x2984 - Position: 21DFE:0 Thread ID=0x3484 - Position: 21ECA:0 Thread ID=0x60B4 - Position: 2414F:0 Thread ID=0x1F54 - Position: 241DE:0 "); engBuilder.With32Bit(false); engBuilder.WithThreadId(0x7590); var stackBuilder = new StackFacadeBuilder(); var stackTrace = new StackTrace(new List <StackFrame>()); stackBuilder.WithGetCurrentStackTrace(stackTrace); var registerSet = new RegisterSet(); var registerBuilder = new RegisterFacadeBuilder(); registerBuilder.WithGetCurrentRegisterSet(Register.All, registerSet); var disassemblyLine = new DisassemblyLine(0x00007ffa51315595, ByteArrayBuilder.StringToByteArray("4d3bd1"), "cmp", "r10,r9"); var disBuilder = new DisassemblyFacadeBuilder(); disBuilder.WithGetDisassemblyLines(1, new[] { disassemblyLine }); var facade = new TimeTravelFacade { DebugEngineProxy = engBuilder.Build(), StackFacade = stackBuilder.Build(), RegisterFacade = registerBuilder.Build(), DisassemblyFacade = disBuilder.Build() }; // act var frame = facade.GetCurrentFrame(); // assert frame.Position.Should().Be(new Position(0x168CC, 0)); frame.DisassemblyLine.Should().Be(disassemblyLine); frame.RegisterSet.Should().Be(registerSet); frame.StackTrace.Should().Be(stackTrace); frame.ThreadId.Should().Be(0x7590); }
public void Exhibit_Value_Equality() { var line0 = new DisassemblyLine(0, new byte[0], "mov", ""); var line1 = new DisassemblyLine(0, new byte[0], "mov", ""); var line2 = new DisassemblyLine(0, new byte[0], "pop", ""); var line3 = new DisassemblyLine(0, new byte[0], "push", ""); var line4 = new DisassemblyLine(0, new byte[] { 0x10, 0x20 }, "mov", ""); var line5 = new DisassemblyLine(0, new byte[] { 0x10, 0x20 }, "mov", ""); line0.Equals(null).Should().BeFalse(); line0.Equals(new object()).Should().BeFalse(); line0.Equals(line0).Should().BeTrue(); line0.Equals(line1).Should().BeTrue(); line1.Equals(line2).Should().BeFalse(); line2.Equals(line3).Should().BeFalse(); line0.GetHashCode().Should().Be(line1.GetHashCode()); line0.GetHashCode().Should().NotBe(line2.GetHashCode()); line4.GetHashCode().Should().Be(line5.GetHashCode()); }