massive cleanup + fixed various code problems

This commit is contained in:
Mr. eXoDia 2015-07-15 02:48:11 +02:00
parent 3ce2a318ca
commit 2481e33abd
22 changed files with 928 additions and 914 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ Release/
*.suo
*.sdf
*.opensdf
*.orig

View File

@ -6,10 +6,10 @@ namespace GleeBug
{
}
DllInfo::DllInfo(LPVOID lpBaseOfDll, DWORD sizeOfImage, LPVOID entryPoint)
DllInfo::DllInfo(LPVOID lpBaseOfDll, ULONG_PTR sizeOfImage, LPVOID entryPoint)
{
this->lpBaseOfDll = (ULONG_PTR)lpBaseOfDll;
this->lpBaseOfDll = reinterpret_cast<ULONG_PTR>(lpBaseOfDll);
this->sizeOfImage = sizeOfImage;
this->entryPoint = (ULONG_PTR)entryPoint;
this->entryPoint = reinterpret_cast<ULONG_PTR>(entryPoint);
}
};

View File

@ -12,7 +12,7 @@ namespace GleeBug
{
public:
ULONG_PTR lpBaseOfDll;
DWORD sizeOfImage;
ULONG_PTR sizeOfImage;
ULONG_PTR entryPoint;
/**
@ -26,7 +26,7 @@ namespace GleeBug
\param sizeOfImage Size of the image.
\param entryPoint The entry point.
*/
DllInfo(LPVOID lpBaseOfDll, DWORD sizeOfImage, LPVOID entryPoint);
DllInfo(LPVOID lpBaseOfDll, ULONG_PTR sizeOfImage, LPVOID entryPoint);
};
};

View File

@ -8,7 +8,7 @@ namespace GleeBug
MODULEINFO modinfo;
memset(&modinfo, 0, sizeof(MODULEINFO));
GetModuleInformation(_process->hProcess,
(HMODULE)loadDll.lpBaseOfDll,
reinterpret_cast<HMODULE>(loadDll.lpBaseOfDll),
&modinfo,
sizeof(MODULEINFO));
DllInfo dll(loadDll.lpBaseOfDll, modinfo.SizeOfImage, modinfo.EntryPoint);
@ -24,12 +24,12 @@ namespace GleeBug
void Debugger::unloadDllEvent(const UNLOAD_DLL_DEBUG_INFO & unloadDll)
{
//call the debug event callback
ULONG_PTR lpBaseOfDll = (ULONG_PTR)unloadDll.lpBaseOfDll;
ULONG_PTR lpBaseOfDll = reinterpret_cast<ULONG_PTR>(unloadDll.lpBaseOfDll);
auto dll = _process->dlls.find(Range(lpBaseOfDll, lpBaseOfDll));
if (dll != _process->dlls.end())
cbUnloadDllEvent(unloadDll, dll->second);
else
cbUnloadDllEvent(unloadDll, DllInfo(unloadDll.lpBaseOfDll, 0, 0));
cbUnloadDllEvent(unloadDll, DllInfo(unloadDll.lpBaseOfDll, 0, nullptr));
//DLL housekeeping
if (dll != _process->dlls.end())

View File

@ -12,9 +12,6 @@ namespace GleeBug
//call the callback
cbSystemBreakpoint();
}
else //handle other breakpoint exceptions
{
}
}
void Debugger::exceptionSingleStep(const EXCEPTION_RECORD & exceptionRecord, const bool firstChance)

View File

@ -19,11 +19,11 @@ namespace GleeBug
bool ProcessInfo::MemRead(ULONG_PTR address, const size_t size, void* buffer)
{
return !!ReadProcessMemory(this->hProcess, (const void*)address, buffer, size, NULL);
return !!ReadProcessMemory(this->hProcess, reinterpret_cast<const void*>(address), buffer, size, nullptr);
}
bool ProcessInfo::MemWrite(ULONG_PTR address, const size_t size, const void* buffer)
{
return !!WriteProcessMemory(this->hProcess, (void*)address, buffer, size, NULL);
return !!WriteProcessMemory(this->hProcess, reinterpret_cast<void*>(address), buffer, size, nullptr);
}
};

View File

@ -11,8 +11,8 @@ namespace GleeBug
{
this->dwThreadId = dwThreadId;
this->hThread = hThread;
this->lpThreadLocalBase = (ULONG_PTR)lpThreadLocalBase;
this->lpStartAddress = (ULONG_PTR)lpStartAddress;
this->lpThreadLocalBase = reinterpret_cast<ULONG_PTR>(lpThreadLocalBase);
this->lpStartAddress = reinterpret_cast<ULONG_PTR>(lpStartAddress);
}
bool ThreadInfo::RegReadContext()
@ -42,7 +42,7 @@ namespace GleeBug
return bReturn;
}
void ThreadInfo::StepInto(StepCallback cbStep)
void ThreadInfo::StepInto(const StepCallback & cbStep)
{
StepInto();
stepCallbacks.push_back(cbStep);

View File

@ -55,7 +55,7 @@ namespace GleeBug
\brief Step into.
\param cbStep StepCallback. Can be written using BIND(this, MyDebugger::cb).
*/
void StepInto(StepCallback cbStep);
void StepInto(const StepCallback & cbStep);
/**
\brief Step into.

View File

@ -7,6 +7,10 @@ namespace GleeBug
_processes.clear();
}
Debugger::~Debugger()
{
}
bool Debugger::Init(const wchar_t* szFilePath,
const wchar_t* szCommandLine,
const wchar_t* szCurrentDirectory)
@ -14,30 +18,37 @@ namespace GleeBug
STARTUPINFOW si;
memset(&si, 0, sizeof(si));
const wchar_t* szFileNameCreateProcess;
wchar_t* szCommandLineCreateProcess;
if (szCommandLine == NULL || !wcslen(szCommandLine))
wchar_t* szCommandLineCreateProcess = nullptr;
wchar_t* szCreateWithCmdLine = nullptr;
if (szCommandLine == nullptr || !wcslen(szCommandLine))
{
szCommandLineCreateProcess = 0;
szCommandLineCreateProcess = nullptr;
szFileNameCreateProcess = szFilePath;
}
else
{
wchar_t szCreateWithCmdLine[1024];
swprintf_s(szCreateWithCmdLine, L"\"%s\" %s", szFilePath, szCommandLine);
auto size = 1 + wcslen(szFilePath) + 2 + wcslen(szCommandLine) + 1;
szCreateWithCmdLine = new wchar_t[size];
swprintf_s(szCreateWithCmdLine, size, L"\"%s\" %s", szFilePath, szCommandLine);
szCommandLineCreateProcess = szCreateWithCmdLine;
szFileNameCreateProcess = 0;
szFileNameCreateProcess = nullptr;
}
return !!CreateProcessW(szFileNameCreateProcess,
bool result = !!CreateProcessW(szFileNameCreateProcess,
szCommandLineCreateProcess,
NULL,
NULL,
nullptr,
nullptr,
FALSE,
DEBUG_PROCESS | CREATE_NEW_CONSOLE,
NULL,
nullptr,
szCurrentDirectory,
&si,
&_mainProcess);
if (szCreateWithCmdLine)
delete[] szCreateWithCmdLine;
return result;
}
bool Debugger::Stop()

View File

@ -17,6 +17,11 @@ namespace GleeBug
*/
Debugger();
/**
\brief Destructs the Debugger instance.
*/
virtual ~Debugger();
/**
\brief Start the debuggee.
\param szFilePath Full pathname of the file to debug.

View File

@ -9,10 +9,6 @@
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Debugger.cpp">

View File

@ -8,81 +8,85 @@ using namespace GleeBug;
class MyDebugger : public Debugger
{
protected:
virtual void cbCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO & createProcess, const ProcessInfo & process)
void cbCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO & createProcess, const ProcessInfo & process) override
{
printf("Process %d created with entry 0x%p\n",
_debugEvent.dwProcessId,
createProcess.lpStartAddress);
};
}
virtual void cbExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO & exitProcess, const ProcessInfo & process)
void cbExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO & exitProcess, const ProcessInfo & process) override
{
printf("Process %d terminated with exit code 0x%08X\n",
printf("Process %u terminated with exit code 0x%08X\n",
_debugEvent.dwProcessId,
exitProcess.dwExitCode);
}
virtual void cbCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO & createThread, const ThreadInfo & thread)
void cbCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO & createThread, const ThreadInfo & thread) override
{
printf("Thread %d created with entry 0x%p\n",
printf("Thread %u created with entry 0x%p\n",
_debugEvent.dwThreadId,
createThread.lpStartAddress);
};
}
virtual void cbExitThreadEvent(const EXIT_THREAD_DEBUG_INFO & exitThread, const ThreadInfo & thread)
void cbExitThreadEvent(const EXIT_THREAD_DEBUG_INFO & exitThread, const ThreadInfo & thread) override
{
printf("Thread %d terminated with exit code 0x%08X\n",
printf("Thread %u terminated with exit code 0x%08X\n",
_debugEvent.dwThreadId,
exitThread.dwExitCode);
};
}
virtual void cbLoadDllEvent(const LOAD_DLL_DEBUG_INFO & loadDll, const DllInfo & dll)
void cbLoadDllEvent(const LOAD_DLL_DEBUG_INFO & loadDll, const DllInfo & dll) override
{
printf("DLL loaded at 0x%p\n",
loadDll.lpBaseOfDll);
};
}
virtual void cbUnloadDllEvent(const UNLOAD_DLL_DEBUG_INFO & unloadDll, const DllInfo & dll)
void cbUnloadDllEvent(const UNLOAD_DLL_DEBUG_INFO & unloadDll, const DllInfo & dll) override
{
printf("DLL 0x%p unloaded\n",
unloadDll.lpBaseOfDll);
};
}
virtual void cbExceptionEvent(const EXCEPTION_DEBUG_INFO & exceptionInfo)
void cbExceptionEvent(const EXCEPTION_DEBUG_INFO & exceptionInfo) override
{
printf("Exception with code 0x%08X at 0x%p\n",
exceptionInfo.ExceptionRecord.ExceptionCode,
exceptionInfo.ExceptionRecord.ExceptionAddress);
};
}
virtual void cbDebugStringEvent(const OUTPUT_DEBUG_STRING_INFO & debugString)
void cbDebugStringEvent(const OUTPUT_DEBUG_STRING_INFO & debugString) override
{
printf("Debug string at 0x%p with length %d\n",
debugString.lpDebugStringData,
debugString.nDebugStringLength);
};
}
virtual void cbRipEvent(const RIP_INFO & rip)
void cbRipEvent(const RIP_INFO & rip) override
{
printf("RIP event type 0x%X, error 0x%X",
rip.dwType,
rip.dwError);
};
}
void boobs()
{
printf("(.)Y(.) 0x%p\n",
#ifdef _WIN64
_thread->registers.Rip);
#else //x32
_thread->registers.Eip);
#endif //_WIN64
}
virtual void cbSystemBreakpoint()
void cbSystemBreakpoint() override
{
printf("System breakpoint reached, CIP: 0x%p\n",
_thread->registers.Rip);
_thread->StepInto(BIND(this, MyDebugger::boobs));
}
virtual void cbInternalError(const std::string & error)
void cbInternalError(const std::string & error) override
{
printf("Internal Error: %s\n",
error.c_str());