From 7953590d007da90049710e0da27407ff329f9cef Mon Sep 17 00:00:00 2001 From: mrexodia Date: Mon, 15 Feb 2016 18:57:08 +0100 Subject: [PATCH] different way to break GleeBug for JIT debugging --- GleeBug/Debugger.cpp | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/GleeBug/Debugger.cpp b/GleeBug/Debugger.cpp index cb78e8b..1defc66 100644 --- a/GleeBug/Debugger.cpp +++ b/GleeBug/Debugger.cpp @@ -71,25 +71,8 @@ namespace GleeBug if (!mProcess || !mThread || !mRegisters) //fail when there is no process or thread currently specified return false; - //write the code that breaks the process - auto codePtr = ptr(VirtualAllocEx(mProcess->hProcess, nullptr, 0x1000, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE)); - if (!codePtr) - { - cbInternalError("Debugger::UnsafeDetachAndBreak, VirtualAllocEx failed!"); - return false; - } - uint8 code[] = { 0xCC, 0xC3 }; - mProcess->MemWriteUnsafe(codePtr, code, sizeof(code)); - - //push the return address (current GIP) on the stack - mRegisters->Gsp -= sizeof(ptr); - auto gip = mRegisters->Gip(); - mProcess->MemWriteUnsafe(mRegisters->Gsp(), &gip, sizeof(gip)); - - //change the GIP to the code - mRegisters->Gip = codePtr; - - //flush the register cache (needed here explicitly because control will be out of the debugger after this). + //set the trap flag to trigger an exception + mRegisters->TrapFlag = true; mThread->RegWriteContext(); //detach from the process @@ -102,7 +85,7 @@ namespace GleeBug mDetach = false; //unset the trap flag when set by GleeBug - if (mThread->isInternalStepping) + if (mThread->isInternalStepping || mThread->isSingleStepping) mRegisters->TrapFlag = false; } }; \ No newline at end of file