示例#1
0
        /// <summary>
        ///     Gets the ending position
        /// </summary>
        /// <returns>Position.</returns>
        public Position GetEndingPosition()
        {
            var end      = DebugEngineProxy.Execute("!tt 100"); // todo: get from trace_info
            var endMatch = Regex.Match(end, "Setting position: (?<pos>[A-F0-9]+:[A-F0-9]+)");

            return(Position.Parse(endMatch.Groups["pos"].Value));
        }
示例#2
0
        /// <summary>
        ///     Positionses this instance.
        /// </summary>
        /// <returns>PositionsResult.</returns>
        public PositionsResult Positions()
        {
            var positionsText = DebugEngineProxy.Execute("!positions");
            var records       = ParsePositionsCommandText(positionsText);

            return(new PositionsResult(records));
        }
示例#3
0
        /// <summary>
        ///     Gets the stack frames.
        /// </summary>
        /// <param name="threadId">The thread identifier.</param>
        /// <returns>IEnumerable&lt;StackFrame&gt;.</returns>
        public IEnumerable <StackFrame> GetStackFrames(int threadId)
        {
            var command = $"k";
            var raw     = DebugEngineProxy.Execute(threadId, command);

            return(ExtractStackFrames(raw));
        }
示例#4
0
        /// <summary>
        ///     Gets the disassembly lines.
        /// </summary>
        /// <param name="threadId">The thread identifier.</param>
        /// <param name="numInstructions">The number instructions.</param>
        /// <returns>IEnumerable&lt;DisassemblyLine&gt;</returns>
        /// <exception cref="ArgumentOutOfRangeException">Number of instructions must be &gt; 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);
        }
示例#5
0
        /// <summary>
        ///     Gets the current stack trace.
        /// </summary>
        /// <returns>StackTrace.</returns>
        public StackTrace GetCurrentStackTrace()
        {
            var stackTrace = DebugEngineProxy.Execute("k");
            var frames     = ExtractStackFrames(stackTrace);

            return(new StackTrace(frames));
        }
示例#6
0
 /// <summary>
 ///     Is32s the bit.
 /// </summary>
 /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
 internal bool Is32Bit()
 {
     if (!_is32Bit.HasValue)
     {
         _is32Bit = Regex.Match(DebugEngineProxy.Execute("!peb"), @"PEB at (?<peb>[a-fA-F0-9]+)").Groups["peb"]
                    .Value
                    .Length ==
                    8;
     }
     return(_is32Bit.Value);
 }
示例#7
0
        /// <summary>
        ///     Sets the position.
        /// </summary>
        /// <param name="position">The position.</param>
        public SetPositionResult SetPosition(Position position)
        {
            var result = new SetPositionResult();
            var output = DebugEngineProxy.Execute($"!tt {position}");
            var match  = Regex.Match(output, "Time Travel Position: (?<pos>[a-f0-9]+:[a-f0-9]+)", RegexOptions.IgnoreCase);

            if (!match.Success)
            {
                throw new ApplicationException(
                          $"Attempted to set position to {position}, but was unable to process the output");
            }
            result.ActualPosition = Position.Parse(match.Groups["pos"].Value);
            var breakpointMatch = Regex.Match(output, @"Breakpoint (?<bp>\d+) hit");

            if (breakpointMatch.Success)
            {
                result.BreakpointHit = Convert.ToInt32(breakpointMatch.Groups["bp"].Value);
            }
            return(result);
        }
示例#8
0
 /// <summary>
 ///     Sets the position.
 /// </summary>
 /// <param name="position">The position.</param>
 public void SetPosition(Position position)
 {
     DebugEngineProxy.Execute($"!tt {position}");
 }
示例#9
0
 /// <summary>
 ///     Sets the write access breakpoint.
 /// </summary>
 /// <param name="length">The length.</param>
 /// <param name="address">The address.</param>
 public void SetWriteAccessBreakpoint(int length, ulong address)
 {
     ValidateLength(length);
     DebugEngineProxy.Execute($"ba w{length} {address:X}");
 }
示例#10
0
 /// <summary>
 ///     Sets the breakpoint by mask.
 /// </summary>
 /// <param name="moduleMask">The module mask.</param>
 /// <param name="functionMask">The function mask.</param>
 public void SetBreakpointByMask(string moduleMask, string functionMask)
 {
     DebugEngineProxy.Execute($"bm {moduleMask}!{functionMask}");
 }
示例#11
0
 /// <summary>
 ///     Clears the breakpoints.
 /// </summary>
 public void ClearBreakpoints()
 {
     DebugEngineProxy.Execute($"bc *");
 }