mirror of https://github.com/x64dbg/GleeBug
Added Some of the breakpoint code. It is not finished yet, and I am not sure the code would compile
This commit is contained in:
parent
7bd8d6c086
commit
c46552c873
|
|
@ -0,0 +1,11 @@
|
||||||
|
#ifndef DEBUGGER_BREAKPOINT_TYPES
|
||||||
|
#define DEBUGGER_BREAKPOINT_TYPES
|
||||||
|
|
||||||
|
/*
|
||||||
|
Needs more work here.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define SOFT_BP 0xcc
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,97 @@
|
||||||
|
#ifndef DEBUGGER_BREAKPOINTS_H
|
||||||
|
#define DEBUGGER_BREAKPOINTS_H
|
||||||
|
|
||||||
|
#include "Debugger.Global.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Incomplete Job. I'll Continue Later.
|
||||||
|
*/
|
||||||
|
namespace GleeBug{
|
||||||
|
|
||||||
|
|
||||||
|
typedef std::tuple<uint32_t, LPVOID, uint32_t> breakpoint;
|
||||||
|
typedef std::unordered_map<breakpoint, uint8_t> bpmap;
|
||||||
|
|
||||||
|
struct BreakPointManager{
|
||||||
|
|
||||||
|
bpmap breakpoints;
|
||||||
|
|
||||||
|
BreakPointManager(){
|
||||||
|
breakpoints = bpmap{};
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AddBp(LPPROCESS_INFORMATION procinfo, LPVOID addr, uint32_t type){
|
||||||
|
|
||||||
|
uint8_t bp_type;
|
||||||
|
SIZE_T nbytes_written = 0;
|
||||||
|
|
||||||
|
breakpoint bp( procinfo->dwProcessId, addr, type );
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case SOFT_BP:
|
||||||
|
bp_type = 0xcc;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ReadProcessMemory(procinfo->hProcess, addr, &bp_type, 1, &nbytes_written) == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nbytes_written != 1){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
breakpoints[bp] = bp_type;
|
||||||
|
|
||||||
|
|
||||||
|
if (WriteProcessMemory(procinfo->hProcess, addr, &bp_type, 1, &nbytes_written) == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nbytes_written != 1){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RemoveBp(LPPROCESS_INFORMATION proc_info, breakpoint bp){
|
||||||
|
uint8_t original_instruction;
|
||||||
|
SIZE_T nbytes_written = 0;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
original_instruction = breakpoints[bp];
|
||||||
|
}
|
||||||
|
catch (const std::out_of_range& oor){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (WriteProcessMemory(proc_info->hProcess, std::get<1>(bp), &std::get<2>(bp), 1, &nbytes_written) == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (nbytes_written != 1){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DeleteBp(LPPROCESS_INFORMATION proc_info, breakpoint bp){
|
||||||
|
bool success;
|
||||||
|
|
||||||
|
success = RemoveBp(proc_info, bp);
|
||||||
|
breakpoints.erase(bp);
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DisableAll()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
@ -6,9 +6,10 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <stdint.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <psapi.h>
|
#include <psapi.h>
|
||||||
|
#include "Debugger.Breakpoint.Types.h"
|
||||||
|
|
||||||
namespace GleeBug
|
namespace GleeBug
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ namespace GleeBug
|
||||||
const wchar_t* szCommandLine,
|
const wchar_t* szCommandLine,
|
||||||
const wchar_t* szCurrentDirectory)
|
const wchar_t* szCurrentDirectory)
|
||||||
{
|
{
|
||||||
|
_breakPoints = BreakPointManager();
|
||||||
|
|
||||||
STARTUPINFOW si;
|
STARTUPINFOW si;
|
||||||
memset(&si, 0, sizeof(si));
|
memset(&si, 0, sizeof(si));
|
||||||
const wchar_t* szFileNameCreateProcess;
|
const wchar_t* szFileNameCreateProcess;
|
||||||
|
|
@ -49,4 +51,13 @@ namespace GleeBug
|
||||||
{
|
{
|
||||||
return !!DebugActiveProcessStop(_mainProcess.dwProcessId);
|
return !!DebugActiveProcessStop(_mainProcess.dwProcessId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Debugger::SetBreakPointMainProcess(LPVOID address, uint32_t bp_type){
|
||||||
|
return _breakPoints.AddBp(&_mainProcess, address, bp_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Debugger::DelBreakPointMainProcess(LPVOID address, uint32_t bp_type){
|
||||||
|
breakpoint temp(_mainProcess.dwProcessId, address, bp_type);
|
||||||
|
return _breakPoints.DeleteBp(&_mainProcess, temp);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "Debugger.Global.h"
|
#include "Debugger.Global.h"
|
||||||
#include "Debugger.Process.h"
|
#include "Debugger.Process.h"
|
||||||
|
#include "Debugger.Breakpoints.h"
|
||||||
|
|
||||||
namespace GleeBug
|
namespace GleeBug
|
||||||
{
|
{
|
||||||
|
|
@ -45,6 +46,11 @@ namespace GleeBug
|
||||||
*/
|
*/
|
||||||
void Start();
|
void Start();
|
||||||
|
|
||||||
|
/*
|
||||||
|
adds a brakpoint on the main process being debugger;
|
||||||
|
*/
|
||||||
|
bool SetBreakPointMainProcess(LPVOID address, uint32_t bp_type);
|
||||||
|
bool DelBreakPointMainProcess(LPVOID address, uint32_t bp_type);
|
||||||
protected: //debug event callbacks
|
protected: //debug event callbacks
|
||||||
/**
|
/**
|
||||||
\brief Process creation debug event callback. Provide an implementation to use this callback.
|
\brief Process creation debug event callback. Provide an implementation to use this callback.
|
||||||
|
|
@ -184,6 +190,7 @@ namespace GleeBug
|
||||||
virtual void exceptionSingleStep(const EXCEPTION_RECORD & exceptionRecord, const bool firstChance);
|
virtual void exceptionSingleStep(const EXCEPTION_RECORD & exceptionRecord, const bool firstChance);
|
||||||
|
|
||||||
protected: //variables
|
protected: //variables
|
||||||
|
BreakPointManager _breakPoints;
|
||||||
PROCESS_INFORMATION _mainProcess;
|
PROCESS_INFORMATION _mainProcess;
|
||||||
DWORD _continueStatus;
|
DWORD _continueStatus;
|
||||||
bool _breakDebugger;
|
bool _breakDebugger;
|
||||||
|
|
|
||||||
|
|
@ -159,6 +159,8 @@
|
||||||
<ClCompile Include="Debugger.Thread.cpp" />
|
<ClCompile Include="Debugger.Thread.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="Debugger.Breakpoint.Types.h" />
|
||||||
|
<ClInclude Include="Debugger.Breakpoints.h" />
|
||||||
<ClInclude Include="Debugger.Dll.h" />
|
<ClInclude Include="Debugger.Dll.h" />
|
||||||
<ClInclude Include="Debugger.Process.h" />
|
<ClInclude Include="Debugger.Process.h" />
|
||||||
<ClInclude Include="Debugger.h" />
|
<ClInclude Include="Debugger.h" />
|
||||||
|
|
|
||||||
|
|
@ -65,5 +65,11 @@
|
||||||
<ClInclude Include="Debugger.Global.h">
|
<ClInclude Include="Debugger.Global.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Debugger.Breakpoints.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Debugger.Breakpoint.Types.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -6,10 +6,10 @@ int main()
|
||||||
#ifdef _WIN64
|
#ifdef _WIN64
|
||||||
wchar_t szFilePath[256] = L"c:\\test64.exe";
|
wchar_t szFilePath[256] = L"c:\\test64.exe";
|
||||||
#else //x86
|
#else //x86
|
||||||
wchar_t szFilePath[256] = L"c:\\test32.exe";
|
wchar_t szFilePath[256] = L"C:\\Users\\JOAO\\Favorites\\Desktop\\crackmes\\chakravyuha\\_sol\\CHAKRAVYUHA.exe";
|
||||||
#endif //_WIN64
|
#endif //_WIN64
|
||||||
wchar_t szCommandLine[256] = L"";
|
wchar_t szCommandLine[256] = L"";
|
||||||
wchar_t szCurrentDir[256] = L"c:\\";
|
wchar_t szCurrentDir[256] = L"C:\\Users\\JOAO\\Favorites\\Desktop\\crackmes\\chakravyuha\\_sol\\";
|
||||||
MyDebugger dbg;
|
MyDebugger dbg;
|
||||||
if (dbg.Init(szFilePath, szCommandLine, szCurrentDir))
|
if (dbg.Init(szFilePath, szCommandLine, szCurrentDir))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue