mirror of https://github.com/x64dbg/TitanEngine
Put a critical section around StepInto to make it thread-safe
This commit is contained in:
parent
1a76d61ef6
commit
fb1babcbb3
|
|
@ -40,6 +40,7 @@ LPVOID engineAttachedProcessDebugInfo = NULL;
|
|||
wchar_t szDebuggerName[512];
|
||||
bool DebugStepFinal = false;
|
||||
LPVOID StepOutCallBack = NULL;
|
||||
CRITICAL_SECTION engineStepActiveCr;
|
||||
|
||||
// Global.Debugger.functions:
|
||||
long DebugLoopInSecondThread(LPVOID InputParameter)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define _GLOBAL_DEBUGGER_H
|
||||
|
||||
#include <vector>
|
||||
#include <Windows.h>
|
||||
|
||||
extern HARDWARE_DATA DebugRegister[4];
|
||||
extern PROCESS_INFORMATION dbgProcessInformation;
|
||||
|
|
@ -39,6 +40,7 @@ extern LPVOID engineAttachedProcessDebugInfo;
|
|||
extern wchar_t szDebuggerName[512];
|
||||
extern bool DebugStepFinal;
|
||||
extern LPVOID StepOutCallBack;
|
||||
extern CRITICAL_SECTION engineStepActiveCr;
|
||||
|
||||
long DebugLoopInSecondThread(LPVOID InputParameter);
|
||||
void DebuggerReset();
|
||||
|
|
|
|||
|
|
@ -37,13 +37,16 @@ __declspec(dllexport) void TITCALL ForceClose()
|
|||
|
||||
__declspec(dllexport) void TITCALL StepInto(LPVOID StepCallBack)
|
||||
{
|
||||
EnterCriticalSection(&engineStepActiveCr);
|
||||
if (!engineStepActive)
|
||||
{
|
||||
ULONG_PTR ueCurrentPosition = GetContextData(UE_CIP);
|
||||
unsigned char instr[16];
|
||||
MemoryReadSafe(dbgProcessInformation.hProcess, (void*)ueCurrentPosition, instr, sizeof(instr), 0);
|
||||
char* DisassembledString = (char*)StaticDisassembleEx(ueCurrentPosition, (LPVOID)instr);
|
||||
if(strstr(DisassembledString, "PUSHF"))
|
||||
if (strstr(DisassembledString, "PUSHF"))
|
||||
StepOver(StepCallBack);
|
||||
else if(strstr(DisassembledString, "POP SS") || strstr(DisassembledString, "MOV SS")) //prevent the 'PUSH SS', 'POP SS' step trick
|
||||
else if (strstr(DisassembledString, "POP SS") || strstr(DisassembledString, "MOV SS")) //prevent the 'PUSH SS', 'POP SS' step trick
|
||||
{
|
||||
ueCurrentPosition += StaticLengthDisassemble((void*)instr);
|
||||
SetBPX(ueCurrentPosition, UE_BREAKPOINT_TYPE_INT3 + UE_SINGLESHOOT, StepCallBack);
|
||||
|
|
@ -61,6 +64,8 @@ __declspec(dllexport) void TITCALL StepInto(LPVOID StepCallBack)
|
|||
engineStepCallBack = StepCallBack;
|
||||
engineStepCount = 0;
|
||||
}
|
||||
}
|
||||
LeaveCriticalSection(&engineStepActiveCr);
|
||||
}
|
||||
|
||||
__declspec(dllexport) void TITCALL StepOver(LPVOID StepCallBack)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,33 @@
|
|||
#define UE_MODULEx86 0x2000;
|
||||
#define UE_MODULEx64 0x2000;
|
||||
|
||||
static void engineStep()
|
||||
{
|
||||
EnterCriticalSection(&engineStepActiveCr);
|
||||
if (engineStepActive)
|
||||
{
|
||||
DBGCode = DBG_CONTINUE;
|
||||
if (engineStepCount == 0)
|
||||
{
|
||||
typedef void(TITCALL* fCustomBreakPoint)(void);
|
||||
auto cbStep = fCustomBreakPoint(engineStepCallBack);
|
||||
engineStepActive = false;
|
||||
engineStepCallBack = NULL;
|
||||
LeaveCriticalSection(&engineStepActiveCr);
|
||||
cbStep();
|
||||
}
|
||||
else
|
||||
{
|
||||
SingleStep(engineStepCount, engineStepCallBack);
|
||||
LeaveCriticalSection(&engineStepActiveCr);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LeaveCriticalSection(&engineStepActiveCr);
|
||||
}
|
||||
}
|
||||
|
||||
__declspec(dllexport) void TITCALL DebugLoop()
|
||||
{
|
||||
bool FirstBPX = true;
|
||||
|
|
@ -642,20 +669,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
|
|||
EnableBPX(ResetBPXAddressTo);
|
||||
ResetBPXAddressTo = NULL;
|
||||
ResetBPX = false;
|
||||
if(engineStepActive)
|
||||
{
|
||||
if(engineStepCount == 0)
|
||||
{
|
||||
myCustomBreakPoint = (fCustomBreakPoint)(engineStepCallBack);
|
||||
engineStepActive = false;
|
||||
engineStepCallBack = NULL;
|
||||
myCustomBreakPoint();
|
||||
}
|
||||
else
|
||||
{
|
||||
SingleStep(engineStepCount, engineStepCallBack);
|
||||
}
|
||||
}
|
||||
engineStep();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -671,20 +685,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
|
|||
{
|
||||
ResetHwBPX = false;
|
||||
SetHardwareBreakPoint(DebugRegisterX.DrxBreakAddress, DebugRegisterXId, DebugRegisterX.DrxBreakPointType, DebugRegisterX.DrxBreakPointSize, (LPVOID)DebugRegisterX.DrxCallBack);
|
||||
if(engineStepActive)
|
||||
{
|
||||
if(engineStepCount == 0)
|
||||
{
|
||||
myCustomBreakPoint = (fCustomBreakPoint)(engineStepCallBack);
|
||||
engineStepActive = false;
|
||||
engineStepCallBack = NULL;
|
||||
myCustomBreakPoint();
|
||||
}
|
||||
else
|
||||
{
|
||||
SingleStep(engineStepCount, engineStepCallBack);
|
||||
}
|
||||
}
|
||||
engineStep();
|
||||
}
|
||||
if(ResetMemBPX) //restore memory breakpoint
|
||||
{
|
||||
|
|
@ -719,20 +720,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
|
|||
VirtualProtectEx(dbgProcessInformation.hProcess, (LPVOID)ResetMemBPXAddress, ResetMemBPXSize, NewProtect, &OldProtect);
|
||||
}
|
||||
|
||||
if(engineStepActive)
|
||||
{
|
||||
if(engineStepCount == 0)
|
||||
{
|
||||
myCustomBreakPoint = (fCustomBreakPoint)(engineStepCallBack);
|
||||
engineStepActive = false;
|
||||
engineStepCallBack = NULL;
|
||||
myCustomBreakPoint();
|
||||
}
|
||||
else
|
||||
{
|
||||
SingleStep(engineStepCount, engineStepCallBack);
|
||||
}
|
||||
}
|
||||
engineStep();
|
||||
}
|
||||
}
|
||||
else //no resetting needed (debugger reached hardware breakpoint or the user stepped)
|
||||
|
|
@ -867,21 +855,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
|
|||
if(strstr(DisassembledString, "PUSHF"))
|
||||
PushfBPX = true;
|
||||
}
|
||||
if(engineStepActive)
|
||||
{
|
||||
DBGCode = DBG_CONTINUE;
|
||||
if(engineStepCount == 0)
|
||||
{
|
||||
myCustomBreakPoint = (fCustomBreakPoint)(engineStepCallBack);
|
||||
engineStepActive = false;
|
||||
engineStepCallBack = NULL;
|
||||
myCustomBreakPoint();
|
||||
}
|
||||
else
|
||||
{
|
||||
SingleStep(engineStepCount, engineStepCallBack);
|
||||
}
|
||||
}
|
||||
engineStep();
|
||||
}
|
||||
if(DBGCode == DBG_EXCEPTION_NOT_HANDLED) //NOTE: only call the chSingleStep callback when the debuggee generated the exception
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "Global.Injector.h"
|
||||
#include "Global.Engine.Extension.h"
|
||||
#include "Global.Engine.Threading.h"
|
||||
#include "Global.Debugger.h"
|
||||
|
||||
// Global.Engine.Entry:
|
||||
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
||||
|
|
@ -13,6 +14,7 @@ BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
|||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
engineHandle = hinstDLL;
|
||||
InitializeCriticalSection(&engineStepActiveCr);
|
||||
EngineInit();
|
||||
EmptyGarbage();
|
||||
for(int i = 0; i < UE_MAX_RESERVED_MEMORY_LEFT; i++)
|
||||
|
|
|
|||
Loading…
Reference in New Issue