mirror of https://github.com/x64dbg/GleeBug
flags class for direct flags access
This commit is contained in:
parent
655dd78d4c
commit
3342bd19ad
|
|
@ -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<F FlagIndex>
|
||||
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<FlagIndex> & operator=(const bool & other)
|
||||
{
|
||||
Set(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator bool() const
|
||||
{
|
||||
return Get();
|
||||
}
|
||||
|
||||
private:
|
||||
Registers* _registers;
|
||||
};
|
||||
|
||||
#endif //_DEBUGGER_THREAD_REGISTERS_FLAG_H
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
@ -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<R::DR0, ptr> Dr0;
|
||||
|
|
@ -202,6 +106,11 @@ namespace GleeBug
|
|||
Register<R::GSP, ptr> Gsp;
|
||||
Register<R::GIP, ptr> Gip;
|
||||
|
||||
#include "Debugger.Thread.Registers.Flag.h"
|
||||
|
||||
Flag<F::Trap> TrapFlag;
|
||||
Flag<F::Resume> 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;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ namespace GleeBug
|
|||
|
||||
void ThreadInfo::StepInto()
|
||||
{
|
||||
registers.SetTrapFlag();
|
||||
registers.TrapFlag.Set();
|
||||
isSingleStepping = true;
|
||||
}
|
||||
};
|
||||
|
|
@ -166,6 +166,7 @@
|
|||
<ClInclude Include="Debugger.h" />
|
||||
<ClInclude Include="Debugger.Thread.h" />
|
||||
<ClInclude Include="Debugger.Global.h" />
|
||||
<ClInclude Include="Debugger.Thread.Registers.Flag.h" />
|
||||
<ClInclude Include="Debugger.Thread.Registers.h" />
|
||||
<ClInclude Include="Debugger.Thread.Registers.Register.h" />
|
||||
<ClInclude Include="GleeBug.h" />
|
||||
|
|
|
|||
|
|
@ -76,5 +76,8 @@
|
|||
<ClInclude Include="GleeBug.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Debugger.Thread.Registers.Flag.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Loading…
Reference in New Issue