mirror of https://github.com/x64dbg/TitanEngine
Make sure stepping is called back on the same thread
- When issuing a step command, remember its thread ID so that other threads cannot hijack the callback and trigger their breakpoints.
This commit is contained in:
parent
49f59781da
commit
d77456f43e
|
|
@ -31,7 +31,7 @@ std::vector<ULONG_PTR> tlsCallBackList;
|
||||||
std::vector<PROCESS_ITEM_DATA> hListProcess;
|
std::vector<PROCESS_ITEM_DATA> hListProcess;
|
||||||
DWORD engineStepCount = 0;
|
DWORD engineStepCount = 0;
|
||||||
LPVOID engineStepCallBack = NULL;
|
LPVOID engineStepCallBack = NULL;
|
||||||
bool engineStepActive = false;
|
DWORD engineStepTID = 0;
|
||||||
bool engineProcessIsNowDetached = false;
|
bool engineProcessIsNowDetached = false;
|
||||||
DWORD DBGCode = DBG_CONTINUE;
|
DWORD DBGCode = DBG_CONTINUE;
|
||||||
bool engineFileIsBeingDebugged = false;
|
bool engineFileIsBeingDebugged = false;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ extern std::vector<ULONG_PTR> tlsCallBackList;
|
||||||
extern std::vector<PROCESS_ITEM_DATA> hListProcess;
|
extern std::vector<PROCESS_ITEM_DATA> hListProcess;
|
||||||
extern DWORD engineStepCount;
|
extern DWORD engineStepCount;
|
||||||
extern LPVOID engineStepCallBack;
|
extern LPVOID engineStepCallBack;
|
||||||
extern bool engineStepActive;
|
extern DWORD engineStepTID;
|
||||||
extern bool engineProcessIsNowDetached;
|
extern bool engineProcessIsNowDetached;
|
||||||
extern DWORD DBGCode;
|
extern DWORD DBGCode;
|
||||||
extern bool engineFileIsBeingDebugged;
|
extern bool engineFileIsBeingDebugged;
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ __declspec(dllexport) void TITCALL ForceClose()
|
||||||
__declspec(dllexport) void TITCALL StepInto(LPVOID StepCallBack)
|
__declspec(dllexport) void TITCALL StepInto(LPVOID StepCallBack)
|
||||||
{
|
{
|
||||||
EnterCriticalSection(&engineStepActiveCr);
|
EnterCriticalSection(&engineStepActiveCr);
|
||||||
if (!engineStepActive)
|
if (engineStepTID == 0)
|
||||||
{
|
{
|
||||||
ULONG_PTR ueCurrentPosition = GetContextData(UE_CIP);
|
ULONG_PTR ueCurrentPosition = GetContextData(UE_CIP);
|
||||||
unsigned char instr[16];
|
unsigned char instr[16];
|
||||||
|
|
@ -60,7 +60,7 @@ __declspec(dllexport) void TITCALL StepInto(LPVOID StepCallBack)
|
||||||
myDBGContext.EFlags |= UE_TRAP_FLAG;
|
myDBGContext.EFlags |= UE_TRAP_FLAG;
|
||||||
SetThreadContext(hActiveThread, &myDBGContext);
|
SetThreadContext(hActiveThread, &myDBGContext);
|
||||||
EngineCloseHandle(hActiveThread);
|
EngineCloseHandle(hActiveThread);
|
||||||
engineStepActive = true;
|
engineStepTID = DBGEvent.dwThreadId;
|
||||||
engineStepCallBack = StepCallBack;
|
engineStepCallBack = StepCallBack;
|
||||||
engineStepCount = 0;
|
engineStepCount = 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,14 +16,14 @@
|
||||||
static void engineStep()
|
static void engineStep()
|
||||||
{
|
{
|
||||||
EnterCriticalSection(&engineStepActiveCr);
|
EnterCriticalSection(&engineStepActiveCr);
|
||||||
if (engineStepActive)
|
if (engineStepTID == DBGEvent.dwThreadId)
|
||||||
{
|
{
|
||||||
DBGCode = DBG_CONTINUE;
|
DBGCode = DBG_CONTINUE;
|
||||||
if (engineStepCount == 0)
|
if (engineStepCount == 0)
|
||||||
{
|
{
|
||||||
typedef void(TITCALL* fCustomBreakPoint)(void);
|
typedef void(TITCALL* fCustomBreakPoint)(void);
|
||||||
auto cbStep = fCustomBreakPoint(engineStepCallBack);
|
auto cbStep = fCustomBreakPoint(engineStepCallBack);
|
||||||
engineStepActive = false;
|
engineStepTID = 0;
|
||||||
engineStepCallBack = NULL;
|
engineStepCallBack = NULL;
|
||||||
LeaveCriticalSection(&engineStepActiveCr);
|
LeaveCriticalSection(&engineStepActiveCr);
|
||||||
cbStep();
|
cbStep();
|
||||||
|
|
@ -1237,7 +1237,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
|
||||||
//general unhandled exception callback
|
//general unhandled exception callback
|
||||||
if(DBGCode == DBG_EXCEPTION_NOT_HANDLED)
|
if(DBGCode == DBG_EXCEPTION_NOT_HANDLED)
|
||||||
{
|
{
|
||||||
engineStepActive = false;
|
engineStepTID = 0;
|
||||||
|
|
||||||
if(DBGCustomHandler->chUnhandledException != NULL)
|
if(DBGCustomHandler->chUnhandledException != NULL)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue