diff --git a/GleeBug/Debugger.Thread.Registers.Flag.h b/GleeBug/Debugger.Thread.Registers.Flag.h new file mode 100644 index 0000000..b9c2579 --- /dev/null +++ b/GleeBug/Debugger.Thread.Registers.Flag.h @@ -0,0 +1,56 @@ +#ifndef _DEBUGGER_THREAD_REGISTERS_FLAG_H +#define _DEBUGGER_THREAD_REGISTERS_FLAG_H + +#include "Debugger.Thread.Registers.h" + +/** +\brief Flags enum. +*/ +enum class F +{ + Trap = 0x100, + Resume = 0x10000 +}; //F + +/** +\brief Class that represents a flag. +\tparam FlagIndex The enum index of the flag. +\tparam ThisPtr Pointer to the Registers class. +*/ +template +class Flag +{ +public: + explicit Flag(Registers* registers) : _registers(registers) {} + + bool Get() const + { + return _registers->GetFlag(FlagIndex); + } + + void Set(bool value = true) + { + _registers->SetFlag(FlagIndex, value); + } + + bool operator()() const + { + return Get(); + } + + Flag & operator=(const bool & other) + { + Set(other); + return *this; + } + + operator bool() const + { + return Get(); + } + +private: + Registers* _registers; +}; + +#endif //_DEBUGGER_THREAD_REGISTERS_FLAG_H \ No newline at end of file diff --git a/GleeBug/Debugger.Thread.Registers.GetSet.cpp b/GleeBug/Debugger.Thread.Registers.GetSet.cpp index d3892de..11131f5 100644 --- a/GleeBug/Debugger.Thread.Registers.GetSet.cpp +++ b/GleeBug/Debugger.Thread.Registers.GetSet.cpp @@ -40,6 +40,9 @@ #define set_uint8_hi(x, y) x = (x & ~0xFF00) | (uint8_lo(y) << 8) #define set_uint8_lo(x, y) x = (x & ~0xFF) | uint8_lo(y) +#define TRAP_FLAG 0x100 +#define RESUME_FLAG 0x10000 + namespace GleeBug { ptr Registers::Get(R reg) const @@ -500,4 +503,17 @@ namespace GleeBug break; } } + + bool Registers::GetFlag(F flag) const + { + return (_context.EFlags & ptr(flag)) == ptr(flag); + } + + void Registers::SetFlag(F flag, bool set) + { + if (set) + _context.EFlags |= ptr(flag); + else + _context.EFlags &= ~ptr(flag); + } } \ No newline at end of file diff --git a/GleeBug/Debugger.Thread.Registers.Register.h b/GleeBug/Debugger.Thread.Registers.Register.h index 7e06178..8489089 100644 --- a/GleeBug/Debugger.Thread.Registers.Register.h +++ b/GleeBug/Debugger.Thread.Registers.Register.h @@ -3,6 +3,105 @@ #include "Debugger.Thread.Registers.h" +/** +\brief Registers enum. +*/ +enum class R +{ + DR0, + DR1, + DR2, + DR3, + DR6, + DR7, + + EFlags, + + EAX, + AX, + AH, + AL, + EBX, + BX, + BH, + BL, + ECX, + CX, + CH, + CL, + EDX, + DX, + DH, + DL, + EDI, + DI, + ESI, + SI, + EBP, + BP, + ESP, + SP, + EIP, + +#ifdef _WIN64 + RAX, + RBX, + RCX, + RDX, + RSI, + SIL, + RDI, + DIL, + RBP, + BPL, + RSP, + SPL, + RIP, + R8, + R8D, + R8W, + R8B, + R9, + R9D, + R9W, + R9B, + R10, + R10D, + R10W, + R10B, + R11, + R11D, + R11W, + R11B, + R12, + R12D, + R12W, + R12B, + R13, + R13D, + R13W, + R13B, + R14, + R14D, + R14W, + R14B, + R15, + R15D, + R15W, + R15B, +#endif //_WIN64 + + GAX, + GBX, + GCX, + GDX, + GDI, + GSI, + GBP, + GSP, + GIP, +}; //R + /** \brief Class that represents a register. \tparam RegisterIndex The enum index of the register. diff --git a/GleeBug/Debugger.Thread.Registers.cpp b/GleeBug/Debugger.Thread.Registers.cpp index da8b240..f22c845 100644 --- a/GleeBug/Debugger.Thread.Registers.cpp +++ b/GleeBug/Debugger.Thread.Registers.cpp @@ -94,7 +94,10 @@ namespace GleeBug Gsi(this), Gbp(this), Gsp(this), - Gip(this) + Gip(this), + + TrapFlag(this), + ResumeFlag(this) { memset(&this->_context, 0, sizeof(CONTEXT)); } @@ -108,32 +111,4 @@ namespace GleeBug { this->_context = context; } - - void Registers::SetTrapFlag(bool set) - { - /*if (set) - this->EFlags |= TRAP_FLAG; - else - this->EFlags &= ~TRAP_FLAG;*/ - } - - bool Registers::GetTrapFlag() const - { - return true; - //return (this->EFlags & TRAP_FLAG) == TRAP_FLAG; - } - - void Registers::SetResumeFlag(bool set) - { - /*if (set) - this->EFlags |= RESUME_FLAG; - else - this->EFlags &= ~RESUME_FLAG;*/ - } - - bool Registers::GetResumeFlag() const - { - return true; - //return (this->EFlags & RESUME_FLAG) == RESUME_FLAG; - } }; \ No newline at end of file diff --git a/GleeBug/Debugger.Thread.Registers.h b/GleeBug/Debugger.Thread.Registers.h index b3372a4..d183cfa 100644 --- a/GleeBug/Debugger.Thread.Registers.h +++ b/GleeBug/Debugger.Thread.Registers.h @@ -11,102 +11,6 @@ namespace GleeBug class Registers { public: - enum class R - { - DR0, - DR1, - DR2, - DR3, - DR6, - DR7, - - EFlags, - - EAX, - AX, - AH, - AL, - EBX, - BX, - BH, - BL, - ECX, - CX, - CH, - CL, - EDX, - DX, - DH, - DL, - EDI, - DI, - ESI, - SI, - EBP, - BP, - ESP, - SP, - EIP, - -#ifdef _WIN64 - RAX, - RBX, - RCX, - RDX, - RSI, - SIL, - RDI, - DIL, - RBP, - BPL, - RSP, - SPL, - RIP, - R8, - R8D, - R8W, - R8B, - R9, - R9D, - R9W, - R9B, - R10, - R10D, - R10W, - R10B, - R11, - R11D, - R11W, - R11B, - R12, - R12D, - R12W, - R12B, - R13, - R13D, - R13W, - R13B, - R14, - R14D, - R14W, - R14B, - R15, - R15D, - R15W, - R15B, -#endif //_WIN64 - - GAX, - GBX, - GCX, - GDX, - GDI, - GSI, - GBP, - GSP, - GIP, - }; //RegisterEnum - #include "Debugger.Thread.Registers.Register.h" Register Dr0; @@ -202,6 +106,11 @@ namespace GleeBug Register Gsp; Register Gip; +#include "Debugger.Thread.Registers.Flag.h" + + Flag TrapFlag; + Flag ResumeFlag; + /** \brief Default constructor. */ @@ -221,6 +130,19 @@ namespace GleeBug */ void Set(R reg, ptr value); + /** + \brief Gets a flag. + \param flag The flag to get. + \return true if the flag is set, false otherwise. + */ + bool GetFlag(F flag) const; + + /** + \brief Sets a flag. + \param set (Optional) true to set the flag, false to unset the flag. + */ + void SetFlag(F flag, bool set = true); + /** \brief Gets a pointer to the context object. \return This function will never return a nullptr. @@ -233,34 +155,8 @@ namespace GleeBug */ void SetContext(const CONTEXT & context); - /** - \brief Sets trap flag. - \param set (Optional) true to set, false to unset. - */ - void SetTrapFlag(bool set = true); - - /** - \brief Gets trap flag. - \return true if the flag is set, false otherwise. - */ - bool GetTrapFlag() const; - - /** - \brief Sets resume flag. - \param set (Optional) true to set, false to unset. - */ - void SetResumeFlag(bool set = true); - - /** - \brief Gets resume flag. - \return true if the flag is set, false otherwise. - */ - bool GetResumeFlag() const; - private: CONTEXT _context; - const int TRAP_FLAG = 0x100; - const int RESUME_FLAG = 0x10000; }; }; diff --git a/GleeBug/Debugger.Thread.cpp b/GleeBug/Debugger.Thread.cpp index 59552bb..97d1d8e 100644 --- a/GleeBug/Debugger.Thread.cpp +++ b/GleeBug/Debugger.Thread.cpp @@ -50,7 +50,7 @@ namespace GleeBug void ThreadInfo::StepInto() { - registers.SetTrapFlag(); + registers.TrapFlag.Set(); isSingleStepping = true; } }; \ No newline at end of file diff --git a/GleeBug/GleeBug.vcxproj b/GleeBug/GleeBug.vcxproj index ceaa87c..0536743 100644 --- a/GleeBug/GleeBug.vcxproj +++ b/GleeBug/GleeBug.vcxproj @@ -166,6 +166,7 @@ + diff --git a/GleeBug/GleeBug.vcxproj.filters b/GleeBug/GleeBug.vcxproj.filters index 651ccea..c61c0e4 100644 --- a/GleeBug/GleeBug.vcxproj.filters +++ b/GleeBug/GleeBug.vcxproj.filters @@ -76,5 +76,8 @@ Header Files + + Header Files + \ No newline at end of file