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;
|
return false;
|
||||||
}
|
}
|
||||||
state.process.hProcess = pi.hProcess;
|
state.Process.hProcess = pi.hProcess;
|
||||||
state.process.hThread = pi.hThread;
|
state.Process.hThread = pi.hThread;
|
||||||
state.process.ProcessId = pi.dwProcessId;
|
state.Process.ProcessId = pi.dwProcessId;
|
||||||
state.process.MainThreadId = pi.dwThreadId;
|
state.Process.MainThreadId = pi.dwThreadId;
|
||||||
if (process)
|
if (process)
|
||||||
*process = state.process;
|
*process = state.Process;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Stop()
|
bool Stop()
|
||||||
{
|
{
|
||||||
return !!TerminateProcess(state.process.hProcess, 0);
|
return !!TerminateProcess(state.Process.hProcess, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Detach()
|
bool Detach()
|
||||||
{
|
{
|
||||||
return !!DebugActiveProcessStop(state.process.ProcessId);
|
return !!DebugActiveProcessStop(state.Process.ProcessId);
|
||||||
|
}
|
||||||
|
|
||||||
|
DebugState* State()
|
||||||
|
{
|
||||||
|
return &state;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -12,6 +12,7 @@ namespace Debugger
|
||||||
ProcessInfo* process);
|
ProcessInfo* process);
|
||||||
bool Stop();
|
bool Stop();
|
||||||
bool Detach();
|
bool Detach();
|
||||||
|
DebugState* State();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //_DEBUGGER_CORE_H
|
#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,6 +3,8 @@
|
||||||
|
|
||||||
#include "_global.h"
|
#include "_global.h"
|
||||||
|
|
||||||
|
namespace Debugger
|
||||||
|
{
|
||||||
struct ProcessInfo
|
struct ProcessInfo
|
||||||
{
|
{
|
||||||
HANDLE hProcess;
|
HANDLE hProcess;
|
||||||
|
|
@ -13,7 +15,11 @@ struct ProcessInfo
|
||||||
|
|
||||||
struct DebugState
|
struct DebugState
|
||||||
{
|
{
|
||||||
ProcessInfo process;
|
ProcessInfo Process;
|
||||||
|
DEBUG_EVENT DebugEvent;
|
||||||
|
DWORD ContinueStatus;
|
||||||
|
bool BreakDebugger;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //_DEBUG_STATE_H
|
#endif //_DEBUG_STATE_H
|
||||||
|
|
@ -65,11 +65,13 @@
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="Debugger.Core.cpp" />
|
<ClCompile Include="Debugger.Core.cpp" />
|
||||||
|
<ClCompile Include="Debugger.Loop.cpp" />
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
<ClCompile Include="_global.cpp" />
|
<ClCompile Include="_global.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Debugger.Core.h" />
|
<ClInclude Include="Debugger.Core.h" />
|
||||||
|
<ClInclude Include="Debugger.Loop.h" />
|
||||||
<ClInclude Include="Debugger.State.h" />
|
<ClInclude Include="Debugger.State.h" />
|
||||||
<ClInclude Include="_global.h" />
|
<ClInclude Include="_global.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,9 @@
|
||||||
<ClCompile Include="_global.cpp">
|
<ClCompile Include="_global.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="Debugger.Loop.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Debugger.Core.h">
|
<ClInclude Include="Debugger.Core.h">
|
||||||
|
|
@ -35,5 +38,8 @@
|
||||||
<ClInclude Include="Debugger.State.h">
|
<ClInclude Include="Debugger.State.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Debugger.Loop.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include "Debugger.Core.h"
|
#include "Debugger.Core.h"
|
||||||
|
#include "Debugger.Loop.h"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
wchar_t szFilePath[256] = L"c:\\CodeBlocks\\arma_cert_bin_info\\bin\\arma_cert_bin_info.exe";
|
wchar_t szFilePath[256] = L"c:\\CodeBlocks\\arma_cert_bin_info\\bin\\arma_cert_bin_info.exe";
|
||||||
wchar_t szCommandLine[256] = L"";
|
wchar_t szCommandLine[256] = L"";
|
||||||
wchar_t szCurrentDir[256] = L"c:\\CodeBlocks\\arma_cert_bin_info\\bin";
|
wchar_t szCurrentDir[256] = L"c:\\CodeBlocks\\arma_cert_bin_info\\bin";
|
||||||
ProcessInfo process;
|
Debugger::ProcessInfo process;
|
||||||
if (Debugger::Init(szFilePath, NULL, szCurrentDir, &process))
|
if (Debugger::Init(szFilePath, NULL, szCurrentDir, &process))
|
||||||
{
|
{
|
||||||
printf("Debugger::Init success! PID: %X\n", process.ProcessId);
|
printf("Debugger::Init success! PID: %X\n", process.ProcessId);
|
||||||
bool bDetached = Debugger::Detach();
|
Debugger::Loop();
|
||||||
printf("Debugger::Detach returned %s\n", bDetached ? "true" : "false");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue