mirror of https://github.com/x64dbg/GleeBug
implemented attach functionality
This commit is contained in:
parent
be4549a361
commit
56fe293287
|
|
@ -10,6 +10,10 @@ namespace GleeBug
|
||||||
mProcess->systemBreakpoint = true;
|
mProcess->systemBreakpoint = true;
|
||||||
mContinueStatus = DBG_CONTINUE;
|
mContinueStatus = DBG_CONTINUE;
|
||||||
|
|
||||||
|
//call the attach callback if appropriate
|
||||||
|
if(mAttachedToProcess && mProcess->dwProcessId == mMainProcess.dwProcessId)
|
||||||
|
cbAttachBreakpoint();
|
||||||
|
|
||||||
//call the callback
|
//call the callback
|
||||||
cbSystemBreakpoint();
|
cbSystemBreakpoint();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,15 @@ namespace GleeBug
|
||||||
{
|
{
|
||||||
void Debugger::createProcessEvent(const CREATE_PROCESS_DEBUG_INFO & createProcess)
|
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
|
//process housekeeping
|
||||||
mProcesses.insert({ mDebugEvent.dwProcessId,
|
mProcesses.insert({ mDebugEvent.dwProcessId,
|
||||||
Process(createProcess.hProcess,
|
Process(createProcess.hProcess,
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ namespace GleeBug
|
||||||
const wchar_t* szCommandLine,
|
const wchar_t* szCommandLine,
|
||||||
const wchar_t* szCurrentDirectory)
|
const wchar_t* szCurrentDirectory)
|
||||||
{
|
{
|
||||||
STARTUPINFOW si;
|
memset(&mMainStartupInfo, 0, sizeof(mMainStartupInfo));
|
||||||
memset(&si, 0, sizeof(si));
|
memset(&mMainProcess, 0, sizeof(mMainProcess));
|
||||||
const wchar_t* szFileNameCreateProcess;
|
const wchar_t* szFileNameCreateProcess;
|
||||||
wchar_t* szCommandLineCreateProcess;
|
wchar_t* szCommandLineCreateProcess;
|
||||||
wchar_t* szCreateWithCmdLine = nullptr;
|
wchar_t* szCreateWithCmdLine = nullptr;
|
||||||
|
|
@ -42,14 +42,28 @@ namespace GleeBug
|
||||||
DEBUG_PROCESS | CREATE_NEW_CONSOLE,
|
DEBUG_PROCESS | CREATE_NEW_CONSOLE,
|
||||||
nullptr,
|
nullptr,
|
||||||
szCurrentDirectory,
|
szCurrentDirectory,
|
||||||
&si,
|
&mMainStartupInfo,
|
||||||
&mMainProcess);
|
&mMainProcess);
|
||||||
|
|
||||||
delete[] szCreateWithCmdLine;
|
delete[] szCreateWithCmdLine;
|
||||||
|
mAttachedToProcess = false;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Debugger::Attach(DWORD processId)
|
||||||
|
{
|
||||||
|
//don't allow attaching when still debugging
|
||||||
|
if(mIsDebugging)
|
||||||
|
return false;
|
||||||
|
if(!DebugActiveProcess(processId))
|
||||||
|
return false;
|
||||||
|
mAttachedToProcess = true;
|
||||||
|
memset(&mMainStartupInfo, 0, sizeof(mMainStartupInfo));
|
||||||
|
memset(&mMainProcess, 0, sizeof(mMainProcess));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool Debugger::Stop() const
|
bool Debugger::Stop() const
|
||||||
{
|
{
|
||||||
return !!TerminateProcess(mMainProcess.hProcess, 0);
|
return !!TerminateProcess(mMainProcess.hProcess, 0);
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,13 @@ namespace GleeBug
|
||||||
const wchar_t* szCommandLine,
|
const wchar_t* szCommandLine,
|
||||||
const wchar_t* szCurrentDirectory);
|
const wchar_t* szCurrentDirectory);
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Attach to a debuggee.
|
||||||
|
\param processId Process to attach to.
|
||||||
|
\return true if the debuggee was attached to successfully, false otherwise.
|
||||||
|
*/
|
||||||
|
bool Attach(DWORD processId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Stops the debuggee (terminate the process)
|
\brief Stops the debuggee (terminate the process)
|
||||||
\return true if the debuggee was stopped correctly, false otherwise.
|
\return true if the debuggee was stopped correctly, false otherwise.
|
||||||
|
|
@ -161,6 +168,11 @@ namespace GleeBug
|
||||||
*/
|
*/
|
||||||
virtual void cbUnhandledException(const EXCEPTION_RECORD & exceptionRecord, bool firstChance) {};
|
virtual void cbUnhandledException(const EXCEPTION_RECORD & exceptionRecord, bool firstChance) {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Attach breakpoint callback. Called just before cbSystemBreakpoint, only for the process that was attached to. Provide an implementation to use this callback.
|
||||||
|
*/
|
||||||
|
virtual void cbAttachBreakpoint() {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief System breakpoint callback. Called after the event is internally processed. Provide an implementation to use this callback.
|
\brief System breakpoint callback. Called after the event is internally processed. Provide an implementation to use this callback.
|
||||||
*/
|
*/
|
||||||
|
|
@ -260,6 +272,7 @@ namespace GleeBug
|
||||||
virtual void exceptionHardwareBreakpoint(ptr exceptionAddress);
|
virtual void exceptionHardwareBreakpoint(ptr exceptionAddress);
|
||||||
|
|
||||||
protected: //variables
|
protected: //variables
|
||||||
|
STARTUPINFOW mMainStartupInfo;
|
||||||
PROCESS_INFORMATION mMainProcess;
|
PROCESS_INFORMATION mMainProcess;
|
||||||
uint32 mContinueStatus = DBG_EXCEPTION_NOT_HANDLED;
|
uint32 mContinueStatus = DBG_EXCEPTION_NOT_HANDLED;
|
||||||
bool mBreakDebugger = false;
|
bool mBreakDebugger = false;
|
||||||
|
|
@ -269,6 +282,7 @@ namespace GleeBug
|
||||||
bool mIsDebugging = false;
|
bool mIsDebugging = false;
|
||||||
bool mDetach = false;
|
bool mDetach = false;
|
||||||
bool mDetachAndBreak = false;
|
bool mDetachAndBreak = false;
|
||||||
|
bool mAttachedToProcess = false;
|
||||||
Capstone mCapstone;
|
Capstone mCapstone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue