mirror of https://github.com/x64dbg/GleeBug
61 lines
2.1 KiB
C++
61 lines
2.1 KiB
C++
#include "Debugger.h"
|
|
|
|
namespace GleeBug
|
|
{
|
|
void Debugger::createProcessEvent(const CREATE_PROCESS_DEBUG_INFO & createProcess)
|
|
{
|
|
//initial attach housekeeping
|
|
if(mAttachedToProcess && !mMainProcess.dwProcessId)
|
|
{
|
|
mMainProcess.hProcess = createProcess.hProcess;
|
|
mMainProcess.hThread = createProcess.hThread;
|
|
mMainProcess.dwProcessId = mDebugEvent.dwProcessId;
|
|
mMainProcess.dwThreadId = mDebugEvent.dwThreadId;
|
|
}
|
|
|
|
//process housekeeping
|
|
mProcesses.insert({ mDebugEvent.dwProcessId,
|
|
Process(createProcess.hProcess,
|
|
mDebugEvent.dwProcessId,
|
|
mDebugEvent.dwThreadId,
|
|
createProcess) });
|
|
mProcess = &mProcesses.find(mDebugEvent.dwProcessId)->second;
|
|
|
|
//thread housekeeping (main thread is created implicitly)
|
|
mProcess->threads.insert({ mDebugEvent.dwThreadId,
|
|
Thread(createProcess.hThread,
|
|
mDebugEvent.dwThreadId,
|
|
createProcess.lpThreadLocalBase,
|
|
createProcess.lpStartAddress) });
|
|
mThread = mProcess->thread = &mProcess->threads.find(mDebugEvent.dwThreadId)->second;
|
|
mRegisters = &mThread->registers;
|
|
|
|
//read thread context from main thread
|
|
if (!mThread->RegReadContext())
|
|
cbInternalError("Thread::RegReadContext() failed!");
|
|
|
|
//call the debug event callback
|
|
cbCreateProcessEvent(createProcess, *mProcess);
|
|
|
|
//close the file handle
|
|
CloseHandle(createProcess.hFile);
|
|
}
|
|
|
|
void Debugger::exitProcessEvent(const EXIT_PROCESS_DEBUG_INFO & exitProcess)
|
|
{
|
|
//check if the terminated process is the main debuggee
|
|
if (mDebugEvent.dwProcessId == mMainProcess.dwProcessId)
|
|
mBreakDebugger = true;
|
|
|
|
//call the debug event callback
|
|
cbExitProcessEvent(exitProcess, *mProcess);
|
|
|
|
//process housekeeping
|
|
mProcesses.erase(mDebugEvent.dwProcessId);
|
|
|
|
//set the current process
|
|
mProcess = nullptr;
|
|
mThread = nullptr;
|
|
mRegisters = nullptr;
|
|
}
|
|
}; |