mirror of https://github.com/x64dbg/GleeBug
debug loop
This commit is contained in:
parent
41cc59a291
commit
946abf3aed
|
|
@ -42,22 +42,27 @@ namespace Debugger
|
|||
{
|
||||
return false;
|
||||
}
|
||||
state.process.hProcess = pi.hProcess;
|
||||
state.process.hThread = pi.hThread;
|
||||
state.process.ProcessId = pi.dwProcessId;
|
||||
state.process.MainThreadId = pi.dwThreadId;
|
||||
state.Process.hProcess = pi.hProcess;
|
||||
state.Process.hThread = pi.hThread;
|
||||
state.Process.ProcessId = pi.dwProcessId;
|
||||
state.Process.MainThreadId = pi.dwThreadId;
|
||||
if (process)
|
||||
*process = state.process;
|
||||
*process = state.Process;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Stop()
|
||||
{
|
||||
return !!TerminateProcess(state.process.hProcess, 0);
|
||||
return !!TerminateProcess(state.Process.hProcess, 0);
|
||||
}
|
||||
|
||||
bool Detach()
|
||||
{
|
||||
return !!DebugActiveProcessStop(state.process.ProcessId);
|
||||
return !!DebugActiveProcessStop(state.Process.ProcessId);
|
||||
}
|
||||
|
||||
DebugState* State()
|
||||
{
|
||||
return &state;
|
||||
}
|
||||
};
|
||||
|
|
@ -12,6 +12,7 @@ namespace Debugger
|
|||
ProcessInfo* process);
|
||||
bool Stop();
|
||||
bool Detach();
|
||||
DebugState* State();
|
||||
};
|
||||
|
||||
#endif //_DEBUGGER_CORE_H
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
#include "Debugger.Loop.h"
|
||||
#include "Debugger.Core.h"
|
||||
|
||||
namespace Debugger
|
||||
{
|
||||
static void CreateProcessEvent(CREATE_PROCESS_DEBUG_INFO* CreateProcess, DebugState* state)
|
||||
{
|
||||
puts("> CreateProcessEvent");
|
||||
}
|
||||
|
||||
static void ExitProcessEvent(EXIT_PROCESS_DEBUG_INFO* ExitProcess, DebugState* state)
|
||||
{
|
||||
puts("> ExitProcessEvent");
|
||||
if (state->DebugEvent.dwProcessId == state->Process.ProcessId)
|
||||
{
|
||||
state->BreakDebugger = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void CreateThreadEvent(CREATE_THREAD_DEBUG_INFO* CreateThread, DebugState* state)
|
||||
{
|
||||
puts("> CreateThreadEvent");
|
||||
}
|
||||
|
||||
static void ExitThreadEvent(EXIT_THREAD_DEBUG_INFO* ExitThread, DebugState* state)
|
||||
{
|
||||
puts("> ExitThreadEvent");
|
||||
}
|
||||
|
||||
static void LoadDllEvent(LOAD_DLL_DEBUG_INFO* LoadDll, DebugState* state)
|
||||
{
|
||||
puts("> LoadDllEvent");
|
||||
}
|
||||
|
||||
static void UnloadDllEvent(UNLOAD_DLL_DEBUG_INFO* UnloadDll, DebugState* state)
|
||||
{
|
||||
puts("> UnloadDllEvent");
|
||||
}
|
||||
|
||||
static void ExceptionEvent(EXCEPTION_DEBUG_INFO* Exception, DebugState* state)
|
||||
{
|
||||
puts("> ExceptionEvent");
|
||||
}
|
||||
|
||||
static void DebugStringEvent(OUTPUT_DEBUG_STRING_INFO* DebugString, DebugState* state)
|
||||
{
|
||||
puts("> DebugStringEvent");
|
||||
}
|
||||
|
||||
static void RipEvent(RIP_INFO* Rip, DebugState* state)
|
||||
{
|
||||
puts("> RipEvent");
|
||||
}
|
||||
|
||||
void Loop()
|
||||
{
|
||||
DebugState* state = State();
|
||||
state->ContinueStatus = DBG_EXCEPTION_NOT_HANDLED;
|
||||
while (!state->BreakDebugger)
|
||||
{
|
||||
if (!WaitForDebugEvent(&state->DebugEvent, INFINITE))
|
||||
break;
|
||||
|
||||
switch (state->DebugEvent.dwDebugEventCode)
|
||||
{
|
||||
case CREATE_PROCESS_DEBUG_EVENT:
|
||||
CreateProcessEvent(&state->DebugEvent.u.CreateProcessInfo, state);
|
||||
break;
|
||||
case EXIT_PROCESS_DEBUG_EVENT:
|
||||
ExitProcessEvent(&state->DebugEvent.u.ExitProcess, state);
|
||||
break;
|
||||
case CREATE_THREAD_DEBUG_EVENT:
|
||||
CreateThreadEvent(&state->DebugEvent.u.CreateThread, state);
|
||||
break;
|
||||
case EXIT_THREAD_DEBUG_EVENT:
|
||||
ExitThreadEvent(&state->DebugEvent.u.ExitThread, state);
|
||||
break;
|
||||
case LOAD_DLL_DEBUG_EVENT:
|
||||
LoadDllEvent(&state->DebugEvent.u.LoadDll, state);
|
||||
break;
|
||||
case UNLOAD_DLL_DEBUG_EVENT:
|
||||
UnloadDllEvent(&state->DebugEvent.u.UnloadDll, state);
|
||||
break;
|
||||
case EXCEPTION_DEBUG_EVENT:
|
||||
ExceptionEvent(&state->DebugEvent.u.Exception, state);
|
||||
break;
|
||||
case OUTPUT_DEBUG_STRING_EVENT:
|
||||
DebugStringEvent(&state->DebugEvent.u.DebugString, state);
|
||||
break;
|
||||
case RIP_EVENT:
|
||||
RipEvent(&state->DebugEvent.u.RipInfo, state);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!ContinueDebugEvent(state->DebugEvent.dwProcessId, state->DebugEvent.dwThreadId, state->ContinueStatus))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef _DEBUGGER_LOOP_H
|
||||
#define _DEBUGGER_LOOP_H
|
||||
|
||||
#include "_global.h"
|
||||
|
||||
namespace Debugger
|
||||
{
|
||||
void Loop();
|
||||
};
|
||||
|
||||
#endif //_DEBUGGER_LOOP_H
|
||||
|
|
@ -3,17 +3,23 @@
|
|||
|
||||
#include "_global.h"
|
||||
|
||||
struct ProcessInfo
|
||||
namespace Debugger
|
||||
{
|
||||
struct ProcessInfo
|
||||
{
|
||||
HANDLE hProcess;
|
||||
HANDLE hThread;
|
||||
DWORD ProcessId;
|
||||
DWORD MainThreadId;
|
||||
};
|
||||
};
|
||||
|
||||
struct DebugState
|
||||
{
|
||||
ProcessInfo process;
|
||||
struct DebugState
|
||||
{
|
||||
ProcessInfo Process;
|
||||
DEBUG_EVENT DebugEvent;
|
||||
DWORD ContinueStatus;
|
||||
bool BreakDebugger;
|
||||
};
|
||||
};
|
||||
|
||||
#endif //_DEBUG_STATE_H
|
||||
|
|
@ -65,11 +65,13 @@
|
|||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Debugger.Core.cpp" />
|
||||
<ClCompile Include="Debugger.Loop.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="_global.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Debugger.Core.h" />
|
||||
<ClInclude Include="Debugger.Loop.h" />
|
||||
<ClInclude Include="Debugger.State.h" />
|
||||
<ClInclude Include="_global.h" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@
|
|||
<ClCompile Include="_global.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Debugger.Loop.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Debugger.Core.h">
|
||||
|
|
@ -35,5 +38,8 @@
|
|||
<ClInclude Include="Debugger.State.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Debugger.Loop.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -1,17 +1,17 @@
|
|||
#include <cstdio>
|
||||
#include "Debugger.Core.h"
|
||||
#include "Debugger.Loop.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
wchar_t szFilePath[256] = L"c:\\CodeBlocks\\arma_cert_bin_info\\bin\\arma_cert_bin_info.exe";
|
||||
wchar_t szCommandLine[256] = L"";
|
||||
wchar_t szCurrentDir[256] = L"c:\\CodeBlocks\\arma_cert_bin_info\\bin";
|
||||
ProcessInfo process;
|
||||
Debugger::ProcessInfo process;
|
||||
if (Debugger::Init(szFilePath, NULL, szCurrentDir, &process))
|
||||
{
|
||||
printf("Debugger::Init success! PID: %X\n", process.ProcessId);
|
||||
bool bDetached = Debugger::Detach();
|
||||
printf("Debugger::Detach returned %s\n", bDetached ? "true" : "false");
|
||||
Debugger::Loop();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue