コード例 #1
0
ファイル: CodeTraceResult.cs プロジェクト: zanzo420/Squalr
        public CodeTraceResult(CodeTraceInfo codeTraceInfo)
        {
            this.codeTraceInfo = codeTraceInfo;

            this.Address     = codeTraceInfo.Instruction.Address;
            this.Instruction = codeTraceInfo.Instruction.Mnemonic;
            this.Count       = 1;
        }
コード例 #2
0
ファイル: EventCallBacks.cs プロジェクト: zanzo420/Squalr
        public Int32 Breakpoint([In, MarshalAs(UnmanagedType.Interface)] IDebugBreakpoint2 bp)
        {
            // Output.Output.Log(Output.LogLevel.Debug, "Breakpoint Hit");
            this.Control.SetExecutionStatus(DEBUG_STATUS.GO_HANDLED);

            CodeTraceInfo codeTraceInfo = new CodeTraceInfo();

            String[] registers;
            Boolean  isProcess32Bit = Processes.Default.IsOpenedProcess32Bit();

            if (isProcess32Bit)
            {
                registers = this.Registers32;
            }
            else
            {
                registers = this.Registers64;
            }

            // Prepare register indicies for DbgEng register value call call
            UInt32[] registerIndicies = new UInt32[registers.Length];

            for (Int32 index = 0; index < registers.Length; index++)
            {
                this.Registers.GetIndexByName(registers[index], out registerIndicies[index]);
            }

            // Get register values
            DEBUG_VALUE[] values = new DEBUG_VALUE[registers.Length];
            this.Registers.GetValues((UInt32)registers.Length, registerIndicies, 0, values);

            // Copy to code trace info
            for (Int32 index = 0; index < registers.Length; index++)
            {
                codeTraceInfo.IntRegisters.Add(registers[index], values[index].I64);
            }

            // Get the current instruction address
            UInt64 address;

            this.Registers.GetInstructionOffset(out address);

            // TEMP: Correct the traced address
            // TODO: Remove this once we figure out how to trigger breakpoint callbacks BEFORE EIP is updated
            address = this.CorrectAddress(address);

            // Disassemble instruction
            Byte[] bytes = Memory.Reader.Default.ReadBytes(address, 15, out _);
            codeTraceInfo.Instruction = Engine.Architecture.Disassembler.Default.Disassemble(bytes, isProcess32Bit, address).FirstOrDefault();

            // Invoke callbacks
            this.ReadCallback?.Invoke(codeTraceInfo);
            this.WriteCallback?.Invoke(codeTraceInfo);
            this.AccessCallback?.Invoke(codeTraceInfo);

            // Output.Output.Log(Output.LogLevel.Debug, "Breakpoint Hit: " + codeTraceInfo.Address);
            return((Int32)DEBUG_STATUS.BREAK);
        }
コード例 #3
0
        private void CodeTraceEvent(CodeTraceInfo codeTraceInfo)
        {
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                CodeTraceResult result = this.Results.FirstOrDefault(results => results.Address == codeTraceInfo.Instruction.Address);

                // Insert or increment
                if (result != null)
                {
                    result.Count++;
                }
                else
                {
                    this.Results.Add(new CodeTraceResult(codeTraceInfo));
                }
            }));
        }
コード例 #4
0
        public Int32 Breakpoint([In, MarshalAs(UnmanagedType.Interface)] IDebugBreakpoint2 bp)
        {
            // Output.Output.Log(Output.LogLevel.Debug, "Breakpoint Hit");
            this.Control.SetExecutionStatus(DEBUG_STATUS.GO_HANDLED);

            CodeTraceInfo codeTraceInfo = new CodeTraceInfo();

            String[] registers;
            throw new NotImplementedException();

            /*
             * Boolean isProcess32Bit = false;// ProcessQuery.Instance.IsProcessWindowed();
             *
             * if (isProcess32Bit)
             * {
             *  registers = this.Registers32;
             * }
             * else
             * {
             *  registers = this.Registers64;
             * }
             *
             * // Prepare register indicies for DbgEng register value call call
             * UInt32[] registerIndicies = new UInt32[registers.Length];
             *
             * for (Int32 index = 0; index < registers.Length; index++)
             * {
             *  this.Registers.GetIndexByName(registers[index], out registerIndicies[index]);
             * }
             *
             * // Get register values
             * DEBUG_VALUE[] values = new DEBUG_VALUE[registers.Length];
             * this.Registers.GetValues((UInt32)registers.Length, registerIndicies, 0, values);
             *
             * // Copy to code trace info
             * for (Int32 index = 0; index < registers.Length; index++)
             * {
             *  codeTraceInfo.IntRegisters.Add(registers[index], values[index].I64);
             * }
             *
             * // Get the current instruction address
             * UInt64 address;
             * this.Registers.GetInstructionOffset(out address);
             *
             * // TEMP: Correct the traced address
             * // TODO: Remove this once we figure out how to trigger breakpoint callbacks BEFORE EIP is updated
             * address = this.CorrectAddress(address);
             *
             * // Disassemble instruction
             * Byte[] bytes = null; // MemoryReader.Instance.ReadBytes(address, 15, out _);
             * throw new NotImplementedException();
             * codeTraceInfo.Instruction = Engine.Architecture.Disassembler.Default.Disassemble(bytes, isProcess32Bit, address).FirstOrDefault();
             *
             * // Invoke callbacks
             * this.ReadCallback?.Invoke(codeTraceInfo);
             * this.WriteCallback?.Invoke(codeTraceInfo);
             * this.AccessCallback?.Invoke(codeTraceInfo);
             *
             * // Output.Output.Log(Output.LogLevel.Debug, "Breakpoint Hit: " + codeTraceInfo.Address);
             * return (Int32)DEBUG_STATUS.BREAK;
             */
        }