fixed const correctness + removed default constructors from ProcessInfo, DllInfo and ThreadInfo + fixed copy constructor of ThreadInfo

This commit is contained in:
Mr. eXoDia 2015-07-15 07:27:31 +02:00
parent 3342bd19ad
commit 59574f105f
14 changed files with 58 additions and 82 deletions

View File

@ -2,10 +2,6 @@
namespace GleeBug
{
DllInfo::DllInfo()
{
}
DllInfo::DllInfo(LPVOID lpBaseOfDll, ptr sizeOfImage, LPVOID entryPoint)
{
this->lpBaseOfDll = ptr(lpBaseOfDll);

View File

@ -15,11 +15,6 @@ namespace GleeBug
ptr sizeOfImage;
ptr entryPoint;
/**
\brief Default constructor.
*/
DllInfo();
/**
\brief Constructor.
\param lpBaseOfDll The base of DLL.

View File

@ -8,7 +8,7 @@ namespace GleeBug
MODULEINFO modinfo;
memset(&modinfo, 0, sizeof(MODULEINFO));
GetModuleInformation(_process->hProcess,
reinterpret_cast<HMODULE>(loadDll.lpBaseOfDll),
HMODULE(loadDll.lpBaseOfDll),
&modinfo,
sizeof(MODULEINFO));
DllInfo dll(loadDll.lpBaseOfDll, modinfo.SizeOfImage, modinfo.EntryPoint);

View File

@ -5,19 +5,19 @@ namespace GleeBug
void Debugger::createProcessEvent(const CREATE_PROCESS_DEBUG_INFO & createProcess)
{
//process housekeeping
ProcessInfo process(_debugEvent.dwProcessId,
_processes.insert({ _debugEvent.dwProcessId,
ProcessInfo(_debugEvent.dwProcessId,
createProcess.hProcess,
_debugEvent.dwThreadId);
_processes.insert({ process.dwProcessId, process });
_process = &_processes.find(process.dwProcessId)->second;
_debugEvent.dwThreadId) });
_process = &_processes.find(_debugEvent.dwProcessId)->second;
//thread housekeeping (main thread is created implicitly)
ThreadInfo thread(_debugEvent.dwThreadId,
_process->threads.insert({ _debugEvent.dwThreadId,
ThreadInfo(_debugEvent.dwThreadId,
createProcess.hThread,
createProcess.lpThreadLocalBase,
createProcess.lpStartAddress);
_process->threads.insert({ thread.dwThreadId, thread });
_thread = _process->thread = &_process->threads.find(thread.dwThreadId)->second;
createProcess.lpStartAddress) });
_thread = _process->thread = &_process->threads.find(_debugEvent.dwThreadId)->second;
_registers = &_thread->registers;
//read thread context from main thread

View File

@ -6,7 +6,10 @@ namespace GleeBug
{
//thread housekeeping
_process->threads.insert({ _debugEvent.dwThreadId,
ThreadInfo(_debugEvent.dwThreadId, createThread.hThread, createThread.lpThreadLocalBase, createThread.lpStartAddress) });
ThreadInfo(_debugEvent.dwThreadId,
createThread.hThread,
createThread.lpThreadLocalBase,
createThread.lpStartAddress) });
//set the current thread
_thread = _process->thread = &_process->threads.find(_debugEvent.dwThreadId)->second;

View File

@ -19,12 +19,14 @@ namespace GleeBug
_continueStatus = DBG_EXCEPTION_NOT_HANDLED;
//set the current process and thread
if (_processes.count(_debugEvent.dwProcessId))
auto processFound = _processes.find(_debugEvent.dwProcessId);
if (processFound != _processes.end())
{
_process = &_processes[_debugEvent.dwProcessId];
if (_process->threads.count(_debugEvent.dwThreadId))
_process = &processFound->second;
auto threadFound = _process->threads.find(_debugEvent.dwThreadId);
if (threadFound != _process->threads.end())
{
_thread = _process->thread = &_process->threads[_debugEvent.dwThreadId];
_thread = _process->thread = &threadFound->second;
_registers = &_thread->registers;
if (!_thread->RegReadContext())
cbInternalError("ThreadInfo::RegReadContext() failed!");
@ -37,9 +39,13 @@ namespace GleeBug
}
else
{
_process = nullptr;
_thread = nullptr;
_registers = nullptr;
_thread = nullptr;
if (_process)
{
_process->thread = nullptr;
_process = nullptr;
}
}
//dispatch the debug event

View File

@ -2,13 +2,6 @@
namespace GleeBug
{
ProcessInfo::ProcessInfo()
{
this->thread = nullptr;
this->systemBreakpoint = false;
this->hProcess = INVALID_HANDLE_VALUE;
}
ProcessInfo::ProcessInfo(uint32 dwProcessId, HANDLE hProcess, uint32 dwMainThreadId)
{
this->systemBreakpoint = false;
@ -17,12 +10,12 @@ namespace GleeBug
this->dwMainThreadId = dwMainThreadId;
}
bool ProcessInfo::MemRead(ptr address, const size_t size, void* buffer)
bool ProcessInfo::MemRead(ptr address, void* buffer, const size_t size) const
{
return !!ReadProcessMemory(this->hProcess, reinterpret_cast<const void*>(address), buffer, size, nullptr);
}
bool ProcessInfo::MemWrite(ptr address, const size_t size, const void* buffer)
bool ProcessInfo::MemWrite(ptr address, const void* buffer, const size_t size) const
{
return !!WriteProcessMemory(this->hProcess, reinterpret_cast<void*>(address), buffer, size, nullptr);
}

View File

@ -23,11 +23,6 @@ namespace GleeBug
ThreadMap threads;
DllMap dlls;
/**
\brief Default constructor.
*/
ProcessInfo();
/**
\brief Constructor.
\param dwProcessId Identifier for the process.
@ -38,20 +33,20 @@ namespace GleeBug
/**
\brief Read memory from the process.
\param address The virtual address to read from.
\param size The size to read.
\param [out] buffer Destination buffer. Cannot be null. May be filled partially on failure.
\param size The size to read.
\return true if it succeeds, false if it fails.
*/
bool MemRead(ptr address, const size_t size, void* buffer);
bool MemRead(ptr address, void* buffer, const size_t size) const;
/**
\brief Write memory to the process.
\param address The virtual address to write to.
\param size The size to write.
\param [in] buffer Source buffer. Cannot be null.
\param size The size to write.
\return true if it succeeds, false if it fails.
*/
bool MemWrite(ptr address, const size_t size, const void* buffer);
bool MemWrite(ptr address, const void* buffer, const size_t size) const;
};
};

View File

@ -257,7 +257,7 @@ namespace GleeBug
break;
case R::EFlags:
_context.EFlags = (DWORD)value;
_context.EFlags = uint32(value);
break;
case R::EAX:

View File

@ -194,12 +194,12 @@ public:
return operator++();
}
bool operator==(const Type & other)
bool operator==(const Type & other) const
{
return Get() == other;
}
bool operator!=(const Type & other)
bool operator!=(const Type & other) const
{
return !operator==(other);
}

View File

@ -11,6 +11,11 @@ namespace GleeBug
class Registers
{
public:
/**
\brief Default constructor.
*/
Registers();
#include "Debugger.Thread.Registers.Register.h"
Register<R::DR0, ptr> Dr0;
@ -111,11 +116,6 @@ namespace GleeBug
Flag<F::Trap> TrapFlag;
Flag<F::Resume> ResumeFlag;
/**
\brief Default constructor.
*/
Registers();
/**
\brief Gets the given register.
\param reg The register to get.

View File

@ -2,11 +2,6 @@
namespace GleeBug
{
ThreadInfo::ThreadInfo()
{
this->hThread = INVALID_HANDLE_VALUE;
}
ThreadInfo::ThreadInfo(uint32 dwThreadId, HANDLE hThread, LPVOID lpThreadLocalBase, LPVOID lpStartAddress)
{
this->dwThreadId = dwThreadId;
@ -15,6 +10,17 @@ namespace GleeBug
this->lpStartAddress = ptr(lpStartAddress);
}
ThreadInfo::ThreadInfo(const ThreadInfo & other) :
dwThreadId(other.dwThreadId),
hThread(other.hThread),
lpThreadLocalBase(other.lpThreadLocalBase),
lpStartAddress(other.lpStartAddress),
registers(), //create new registers
stepCallbacks(other.stepCallbacks),
isSingleStepping(other.isSingleStepping)
{
}
bool ThreadInfo::RegReadContext()
{
SuspendThread(this->hThread);
@ -30,7 +36,7 @@ namespace GleeBug
return bReturn;
}
bool ThreadInfo::RegWriteContext()
bool ThreadInfo::RegWriteContext() const
{
//check if something actually changed
if (memcmp(&this->_oldContext, this->registers.GetContext(), sizeof(CONTEXT)) == 0)

View File

@ -21,11 +21,6 @@ namespace GleeBug
StepCallbackVector stepCallbacks;
bool isSingleStepping;
/**
\brief Default constructor.
*/
ThreadInfo();
/**
\brief Constructor.
\param dwThreadId Identifier for the thread.
@ -34,6 +29,11 @@ namespace GleeBug
*/
ThreadInfo(uint32 dwThreadId, HANDLE hThread, LPVOID lpThreadLocalBase, LPVOID lpStartAddress);
/**
\brief Copy constructor.
*/
ThreadInfo(const ThreadInfo & other);
/**
\brief Read the register context from the thread. This fills the RegistersInfo member.
\return true if it succeeds, false if it fails.
@ -41,10 +41,10 @@ namespace GleeBug
bool RegReadContext();
/**
\brief Write the register context to the thread. This does nothing if the RegistersInfo member did not change.
\brief Write the register context to the thread. This does nothing if the registers did not change.
\return true if it succeeds, false if it fails.
*/
bool RegWriteContext();
bool RegWriteContext() const;
/**
\brief Step into.

View File

@ -85,24 +85,6 @@ protected:
void cbSystemBreakpoint() override
{
printf("%p\n", _registers->Gcx());
gax();
_registers->Gax.Set(123);
gax();
_registers->Gax = 0x1234;
if (_registers->Gax == _registers->Gcx())
{
puts("test== okay!");
}
if (_registers->Gax != 1)
puts("test!= okay!");
gax();
_registers->Gax++;
gax();
++_registers->Gax;
gax();
printf("System breakpoint reached, CIP: 0x%p\n",
_registers->Gip.Get());
_thread->StepInto(BIND(this, MyDebugger::boobs));