From a815753c524780b79d6ba126ea4550cb56a51b7f Mon Sep 17 00:00:00 2001 From: "Mr. eXoDia" Date: Wed, 20 Aug 2014 23:33:42 +0200 Subject: [PATCH] fixed detection when stepping over 'pop ss, pushfd/q' (thanks to firelegend for reporting) --- TitanEngine/TitanEngine.Debugger.Control.cpp | 23 ++++++++++++------- .../TitanEngine.Debugger.DebugLoop.cpp | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/TitanEngine/TitanEngine.Debugger.Control.cpp b/TitanEngine/TitanEngine.Debugger.Control.cpp index 1a35bf2..cc34bd3 100644 --- a/TitanEngine/TitanEngine.Debugger.Control.cpp +++ b/TitanEngine/TitanEngine.Debugger.Control.cpp @@ -50,20 +50,27 @@ __declspec(dllexport) void TITCALL ForceClose() __declspec(dllexport) void TITCALL StepInto(LPVOID StepCallBack) { ULONG_PTR ueCurrentPosition = GetContextData(UE_CIP); - unsigned char instr[16]; + unsigned char instr[32]; //two instructions MemoryReadSafe(dbgProcessInformation.hProcess, (void*)ueCurrentPosition, instr, sizeof(instr), 0); char* DisassembledString = (char*)StaticDisassembleEx(ueCurrentPosition, (LPVOID)instr); if(strstr(DisassembledString, "PUSHF")) StepOver(StepCallBack); else { - ULONG_PTR ueContext = NULL; - ueContext = (ULONG_PTR)GetContextData(UE_EFLAGS); - ueContext |= UE_TRAP_FLAG; - SetContextData(UE_EFLAGS, ueContext); - engineStepActive = true; - engineStepCallBack = StepCallBack; - engineStepCount = NULL; + int len = StaticLengthDisassemble((LPVOID)instr); + DisassembledString = (char*)StaticDisassembleEx(ueCurrentPosition + len, (LPVOID)(instr + len)); + if(strstr(DisassembledString, "PUSHF")) //we wanna land on PUSHF safely (to prevent 'PUSH SS, POP SS' problems + SetBPX(ueCurrentPosition + len, UE_BREAKPOINT_TYPE_INT3 + UE_SINGLESHOOT, StepCallBack); + else + { + ULONG_PTR ueContext = NULL; + ueContext = (ULONG_PTR)GetContextData(UE_EFLAGS); + ueContext |= UE_TRAP_FLAG; + SetContextData(UE_EFLAGS, ueContext); + engineStepActive = true; + engineStepCallBack = StepCallBack; + engineStepCount = NULL; + } } } diff --git a/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp b/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp index 8565fcf..0363f46 100644 --- a/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp +++ b/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp @@ -1191,7 +1191,7 @@ __declspec(dllexport) void TITCALL DebugLoop() ResetBPXAddressTo = NULL; ResetBPX = false; } - + //execute callback myCustomBreakPoint = (fCustomBreakPoint)((LPVOID)FoundBreakPoint.ExecuteCallBack); __try