- fixed many bug with memory breakpoints

- added memory breakpoint on execute
- moved binary output directories
- updated codeblocks project
- fixed memory breakpoint reset
This commit is contained in:
mr.exodia 2013-08-26 21:53:40 +02:00
parent 0802cd008b
commit a01ade8de2
15 changed files with 150 additions and 105 deletions

BIN
Release/x64/TitanEngine.lib Normal file

Binary file not shown.

View File

@ -7,7 +7,7 @@
<Option compiler="msvc10" /> <Option compiler="msvc10" />
<Build> <Build>
<Target title="x64"> <Target title="x64">
<Option output="bin/x64/TitanEngine" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" /> <Option output="../Release/x64/TitanEngine" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/x64" /> <Option object_output="obj/x64" />
<Option type="3" /> <Option type="3" />
<Option compiler="microsoft_visual_c_2010_x64" /> <Option compiler="microsoft_visual_c_2010_x64" />
@ -27,7 +27,7 @@
</Linker> </Linker>
</Target> </Target>
<Target title="x32"> <Target title="x32">
<Option output="bin/x32/TitanEngine" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" /> <Option output="../Release/x32/TitanEngine" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/x32" /> <Option object_output="obj/x32" />
<Option type="3" /> <Option type="3" />
<Option compiler="msvc10" /> <Option compiler="msvc10" />

View File

@ -188,8 +188,6 @@ unsigned long Crc32Table[256];
#define UE_MODULEx86 0x2000; #define UE_MODULEx86 0x2000;
#define UE_MODULEx64 0x2000; #define UE_MODULEx64 0x2000;
// Global.Handle.functions: // Global.Handle.functions:
bool EngineCloseHandle(HANDLE myHandle) bool EngineCloseHandle(HANDLE myHandle)
{ {
@ -16470,6 +16468,7 @@ __declspec(dllexport) void DebugLoop()
bool ResetBPX = false; bool ResetBPX = false;
bool BreakDBG = false; bool BreakDBG = false;
bool ResetHwBPX = false; bool ResetHwBPX = false;
bool ResetMemBPX = false;
bool CompareResult = false; bool CompareResult = false;
bool SecondChance = false; bool SecondChance = false;
ULONG_PTR CmpValue1 = NULL; ULONG_PTR CmpValue1 = NULL;
@ -16491,6 +16490,8 @@ __declspec(dllexport) void DebugLoop()
ULONG_PTR MemoryBpxCallBack = 0; ULONG_PTR MemoryBpxCallBack = 0;
DWORD ResetBPXSize = 0; DWORD ResetBPXSize = 0;
ULONG_PTR ResetBPXAddressTo = 0; ULONG_PTR ResetBPXAddressTo = 0;
ULONG_PTR ResetMemBPXAddress = 0;
SIZE_T ResetMemBPXSize = 0;
int MaximumBreakPoints = 0; int MaximumBreakPoints = 0;
ULONG_PTR NumberOfBytesReadWritten = 0; ULONG_PTR NumberOfBytesReadWritten = 0;
MEMORY_BASIC_INFORMATION MemInfo; MEMORY_BASIC_INFORMATION MemInfo;
@ -17037,7 +17038,6 @@ __declspec(dllexport) void DebugLoop()
#endif #endif
SetThreadContext(hActiveThread, &myDBGContext); SetThreadContext(hActiveThread, &myDBGContext);
EngineCloseHandle(hActiveThread); EngineCloseHandle(hActiveThread);
//TODO fixed
VirtualProtectEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, BreakPointBuffer[MaximumBreakPoints].BreakPointSize, OldProtect, &OldProtect); VirtualProtectEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, BreakPointBuffer[MaximumBreakPoints].BreakPointSize, OldProtect, &OldProtect);
myCustomBreakPoint = (fCustomBreakPoint)((LPVOID)BreakPointBuffer[MaximumBreakPoints].ExecuteCallBack); myCustomBreakPoint = (fCustomBreakPoint)((LPVOID)BreakPointBuffer[MaximumBreakPoints].ExecuteCallBack);
if(BreakPointBuffer[MaximumBreakPoints].NumberOfExecutions != -1 && BreakPointBuffer[MaximumBreakPoints].NumberOfExecutions != 0) if(BreakPointBuffer[MaximumBreakPoints].NumberOfExecutions != -1 && BreakPointBuffer[MaximumBreakPoints].NumberOfExecutions != 0)
@ -17185,14 +17185,12 @@ __declspec(dllexport) void DebugLoop()
} }
else else
{ {
//TODO fixed
VirtualProtectEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, BreakPointBuffer[MaximumBreakPoints].BreakPointSize, OldProtect, &OldProtect); VirtualProtectEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, BreakPointBuffer[MaximumBreakPoints].BreakPointSize, OldProtect, &OldProtect);
DBGCode = DBG_CONTINUE; DBGCode = DBG_CONTINUE;
} }
} }
else else
{ {
//TODO fixed
VirtualProtectEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, BreakPointBuffer[MaximumBreakPoints].BreakPointSize, OldProtect, &OldProtect); VirtualProtectEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, BreakPointBuffer[MaximumBreakPoints].BreakPointSize, OldProtect, &OldProtect);
DBGCode = DBG_EXCEPTION_NOT_HANDLED; DBGCode = DBG_EXCEPTION_NOT_HANDLED;
} }
@ -17280,10 +17278,10 @@ __declspec(dllexport) void DebugLoop()
DBGCustomHandler->chSingleStep = NULL; DBGCustomHandler->chSingleStep = NULL;
} }
}*/ }*/
if(ResetBPX == true || ResetHwBPX == true) if(ResetBPX == true || ResetHwBPX == true || ResetMemBPX == true)
{ {
DBGCode = DBG_CONTINUE; DBGCode = DBG_CONTINUE;
if(!ResetHwBPX) if(ResetBPX) //restore 'normal' breakpoint
{ {
if(ResetBPXAddressTo + ResetBPXSize != (ULONG_PTR)DBGEvent.u.Exception.ExceptionRecord.ExceptionAddress) if(ResetBPXAddressTo + ResetBPXSize != (ULONG_PTR)DBGEvent.u.Exception.ExceptionRecord.ExceptionAddress)
{ {
@ -17325,7 +17323,7 @@ __declspec(dllexport) void DebugLoop()
EngineCloseHandle(hActiveThread); EngineCloseHandle(hActiveThread);
} }
} }
else else if(ResetHwBPX) //restore hardware breakpoint
{ {
ResetHwBPX = false; ResetHwBPX = false;
SetHardwareBreakPoint(DebugRegisterX.DrxBreakAddress, DebugRegisterXId, DebugRegisterX.DrxBreakPointType, DebugRegisterX.DrxBreakPointSize, (LPVOID)DebugRegisterX.DrxCallBack); SetHardwareBreakPoint(DebugRegisterX.DrxBreakAddress, DebugRegisterXId, DebugRegisterX.DrxBreakPointType, DebugRegisterX.DrxBreakPointSize, (LPVOID)DebugRegisterX.DrxCallBack);
@ -17351,8 +17349,37 @@ __declspec(dllexport) void DebugLoop()
} }
} }
} }
else if(ResetMemBPX) //restore memory breakpoint
{
ResetMemBPX = false;
VirtualQueryEx(dbgProcessInformation.hProcess, (LPCVOID)ResetMemBPXAddress, &MemInfo, sizeof MEMORY_BASIC_INFORMATION);
OldProtect = MemInfo.AllocationProtect;
NewProtect = OldProtect | PAGE_GUARD;
VirtualProtectEx(dbgProcessInformation.hProcess, (LPVOID)ResetMemBPXAddress, ResetMemBPXSize, NewProtect, &OldProtect);
if(engineStepActive)
{
if(engineStepCount == NULL)
{
myCustomBreakPoint = (fCustomBreakPoint)(engineStepCallBack);
__try
{
engineStepActive = false;
engineStepCallBack = NULL;
myCustomBreakPoint();
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
}
else
{
SingleStep(engineStepCount, engineStepCallBack);
}
}
}
} }
else else //no resetting needed (debugger reached hardware breakpoint or the user stepped)
{ {
if(engineStepActive) if(engineStepActive)
{ {
@ -17376,7 +17403,7 @@ __declspec(dllexport) void DebugLoop()
SingleStep(engineStepCount, engineStepCallBack); SingleStep(engineStepCount, engineStepCallBack);
} }
} }
else else //handle hardware breakpoints
{ {
hActiveThread = OpenThread(THREAD_GET_CONTEXT+THREAD_SET_CONTEXT+THREAD_QUERY_INFORMATION, false, DBGEvent.dwThreadId); hActiveThread = OpenThread(THREAD_GET_CONTEXT+THREAD_SET_CONTEXT+THREAD_QUERY_INFORMATION, false, DBGEvent.dwThreadId);
myDBGContext.ContextFlags = CONTEXT_ALL; myDBGContext.ContextFlags = CONTEXT_ALL;
@ -17394,14 +17421,7 @@ __declspec(dllexport) void DebugLoop()
myCustomHandler = (fCustomHandler)(DebugRegister0.DrxCallBack); myCustomHandler = (fCustomHandler)(DebugRegister0.DrxCallBack);
__try __try
{ {
ULONG_PTR addr=(ULONG_PTR)DBGEvent.u.Exception.ExceptionRecord.ExceptionAddress; myCustomHandler((void*)myDBGContext.Dr0);
if(myDBGContext.Dr6 & 0x1)
#if defined(_WIN64)
addr=(ULONG_PTR)myDBGContext.Rip;
#else
addr=(ULONG_PTR)myDBGContext.Eip;
#endif
myCustomHandler((void*)addr);
} }
__except(EXCEPTION_EXECUTE_HANDLER) __except(EXCEPTION_EXECUTE_HANDLER)
{ {
@ -17431,14 +17451,7 @@ __declspec(dllexport) void DebugLoop()
myCustomHandler = (fCustomHandler)(DebugRegister1.DrxCallBack); myCustomHandler = (fCustomHandler)(DebugRegister1.DrxCallBack);
__try __try
{ {
ULONG_PTR addr=(ULONG_PTR)DBGEvent.u.Exception.ExceptionRecord.ExceptionAddress; myCustomHandler((void*)myDBGContext.Dr1);
if(myDBGContext.Dr6 & 0x2)
#if defined(_WIN64)
addr=(ULONG_PTR)myDBGContext.Rip;
#else
addr=(ULONG_PTR)myDBGContext.Eip;
#endif
myCustomHandler((void*)addr);
} }
__except(EXCEPTION_EXECUTE_HANDLER) __except(EXCEPTION_EXECUTE_HANDLER)
{ {
@ -17468,14 +17481,7 @@ __declspec(dllexport) void DebugLoop()
myCustomHandler = (fCustomHandler)(DebugRegister2.DrxCallBack); myCustomHandler = (fCustomHandler)(DebugRegister2.DrxCallBack);
__try __try
{ {
ULONG_PTR addr=(ULONG_PTR)DBGEvent.u.Exception.ExceptionRecord.ExceptionAddress; myCustomHandler((void*)myDBGContext.Dr2);
if(myDBGContext.Dr6 & 0x4)
#if defined(_WIN64)
addr=(ULONG_PTR)myDBGContext.Rip;
#else
addr=(ULONG_PTR)myDBGContext.Eip;
#endif
myCustomHandler((void*)addr);
} }
__except(EXCEPTION_EXECUTE_HANDLER) __except(EXCEPTION_EXECUTE_HANDLER)
{ {
@ -17505,14 +17511,7 @@ __declspec(dllexport) void DebugLoop()
myCustomHandler = (fCustomHandler)(DebugRegister3.DrxCallBack); myCustomHandler = (fCustomHandler)(DebugRegister3.DrxCallBack);
__try __try
{ {
ULONG_PTR addr=(ULONG_PTR)DBGEvent.u.Exception.ExceptionRecord.ExceptionAddress; myCustomHandler((void*)myDBGContext.Dr3);
if(myDBGContext.Dr6 & 0x8)
#if defined(_WIN64)
addr=(ULONG_PTR)myDBGContext.Rip;
#else
addr=(ULONG_PTR)myDBGContext.Eip;
#endif
myCustomHandler((void*)addr);
} }
__except(EXCEPTION_EXECUTE_HANDLER) __except(EXCEPTION_EXECUTE_HANDLER)
{ {
@ -17554,40 +17553,32 @@ __declspec(dllexport) void DebugLoop()
} }
else if(DBGEvent.u.Exception.ExceptionRecord.ExceptionCode == STATUS_GUARD_PAGE_VIOLATION) else if(DBGEvent.u.Exception.ExceptionRecord.ExceptionCode == STATUS_GUARD_PAGE_VIOLATION)
{ {
/*if(DBGCustomHandler->chPageGuard != NULL)
{
myCustomHandler = (fCustomHandler)((LPVOID)DBGCustomHandler->chPageGuard);
__try
{
myCustomHandler(&DBGEvent.u.Exception.ExceptionRecord);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DBGCustomHandler->chPageGuard = NULL;
}
}*/
char temp[20]="";
sprintf(temp, "%X", (unsigned int)DBGEvent.u.Exception.ExceptionRecord.ExceptionAddress);
MessageBoxA(0,temp,0,0);
MemoryBpxFound = false; MemoryBpxFound = false;
MaximumBreakPoints = 0; MaximumBreakPoints = 0;
ULONG_PTR bpaddr;
for(MaximumBreakPoints = 0; MaximumBreakPoints < BreakPointSetCount; MaximumBreakPoints++) for(MaximumBreakPoints = 0; MaximumBreakPoints < BreakPointSetCount; MaximumBreakPoints++)
{ {
ULONG_PTR addr=BreakPointBuffer[MaximumBreakPoints].BreakPointAddress; ULONG_PTR addr=BreakPointBuffer[MaximumBreakPoints].BreakPointAddress;
ULONG_PTR bpaddr=(ULONG_PTR)DBGEvent.u.Exception.ExceptionRecord.ExceptionAddress; if(DBGEvent.u.Exception.ExceptionRecord.ExceptionInformation[0] == 1)
if(((BreakPointBuffer[MaximumBreakPoints].BreakPointType >= UE_MEMORY) && (BreakPointBuffer[MaximumBreakPoints].BreakPointType <= UE_MEMORY_WRITE)) && bpaddr>=addr && bpaddr<=(addr+BreakPointBuffer[MaximumBreakPoints].BreakPointSize)) bpaddr=(ULONG_PTR)DBGEvent.u.Exception.ExceptionRecord.ExceptionInformation[1]; //page accessed
else
bpaddr=(ULONG_PTR)DBGEvent.u.Exception.ExceptionRecord.ExceptionAddress;
if(((BreakPointBuffer[MaximumBreakPoints].BreakPointType >= UE_MEMORY) && (BreakPointBuffer[MaximumBreakPoints].BreakPointType <= UE_MEMORY_EXECUTE)) && bpaddr>=addr && bpaddr<=(addr+BreakPointBuffer[MaximumBreakPoints].BreakPointSize))
{ {
MemoryBpxFound = true; MemoryBpxFound = true;
break; break;
} }
} }
if(MaximumBreakPoints < MAXIMUM_BREAKPOINTS || MemoryBpxFound == true) if(MaximumBreakPoints < MAXIMUM_BREAKPOINTS || MemoryBpxFound == true) //found memory breakpoint
{ {
if(BreakPointBuffer[MaximumBreakPoints].BreakPointActive == UE_BPXACTIVE) if(BreakPointBuffer[MaximumBreakPoints].BreakPointActive == UE_BPXACTIVE) //memory breakpoint is active
{ {
hActiveThread = OpenThread(THREAD_GET_CONTEXT+THREAD_SET_CONTEXT+THREAD_QUERY_INFORMATION, false, DBGEvent.dwThreadId);
myDBGContext.ContextFlags = CONTEXT_ALL;
GetThreadContext(hActiveThread, &myDBGContext);
DBGCode = DBG_CONTINUE; DBGCode = DBG_CONTINUE;
MemoryBpxCallBack = BreakPointBuffer[MaximumBreakPoints].ExecuteCallBack; MemoryBpxCallBack = BreakPointBuffer[MaximumBreakPoints].ExecuteCallBack;
if(BreakPointBuffer[MaximumBreakPoints].BreakPointType == UE_MEMORY) if(BreakPointBuffer[MaximumBreakPoints].BreakPointType == UE_MEMORY) //READ|WRITE|EXECUTE
{ {
if(BreakPointBuffer[MaximumBreakPoints].MemoryBpxRestoreOnHit != 1) if(BreakPointBuffer[MaximumBreakPoints].MemoryBpxRestoreOnHit != 1)
{ {
@ -17595,22 +17586,26 @@ __declspec(dllexport) void DebugLoop()
} }
else else
{ {
VirtualQueryEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, &MemInfo, sizeof MEMORY_BASIC_INFORMATION); if(!(myDBGContext.EFlags & 0x100))
OldProtect = MemInfo.AllocationProtect; {
NewProtect = OldProtect ^ PAGE_GUARD; myDBGContext.EFlags = myDBGContext.EFlags ^ 0x100;
VirtualProtectEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, BreakPointBuffer[MaximumBreakPoints].BreakPointSize, NewProtect, &OldProtect); }
SetThreadContext(hActiveThread, &myDBGContext);
ResetMemBPXAddress = BreakPointBuffer[MaximumBreakPoints].BreakPointAddress;
ResetMemBPXSize = BreakPointBuffer[MaximumBreakPoints].BreakPointSize;
ResetMemBPX = true;
} }
myCustomBreakPoint = (fCustomBreakPoint)((LPVOID)MemoryBpxCallBack); myCustomHandler = (fCustomHandler)(MemoryBpxCallBack);
__try __try
{ {
myCustomBreakPoint(); myCustomHandler((void*)bpaddr);
} }
__except(EXCEPTION_EXECUTE_HANDLER) __except(EXCEPTION_EXECUTE_HANDLER)
{ {
} }
} }
else if(BreakPointBuffer[MaximumBreakPoints].BreakPointType == UE_MEMORY_READ) else if(BreakPointBuffer[MaximumBreakPoints].BreakPointType == UE_MEMORY_READ) //READ
{ {
if(BreakPointBuffer[MaximumBreakPoints].MemoryBpxRestoreOnHit != 1) if(BreakPointBuffer[MaximumBreakPoints].MemoryBpxRestoreOnHit != 1)
{ {
@ -17618,17 +17613,62 @@ __declspec(dllexport) void DebugLoop()
} }
else else
{ {
VirtualQueryEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, &MemInfo, sizeof MEMORY_BASIC_INFORMATION); if(!(myDBGContext.EFlags & 0x100))
OldProtect = MemInfo.AllocationProtect; {
NewProtect = OldProtect ^ PAGE_GUARD; myDBGContext.EFlags = myDBGContext.EFlags ^ 0x100;
VirtualProtectEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, BreakPointBuffer[MaximumBreakPoints].BreakPointSize, NewProtect, &OldProtect); }
SetThreadContext(hActiveThread, &myDBGContext);
ResetMemBPXAddress = BreakPointBuffer[MaximumBreakPoints].BreakPointAddress;
ResetMemBPXSize = BreakPointBuffer[MaximumBreakPoints].BreakPointSize;
ResetMemBPX = true;
} }
if(DBGEvent.u.Exception.ExceptionRecord.ExceptionInformation[0] == 0) if(DBGEvent.u.Exception.ExceptionRecord.ExceptionInformation[0] == 0) //read operation
{ {
myCustomBreakPoint = (fCustomBreakPoint)((LPVOID)MemoryBpxCallBack); myCustomHandler = (fCustomHandler)(MemoryBpxCallBack);
__try __try
{ {
myCustomBreakPoint(); myCustomHandler((void*)bpaddr);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
}
else //no read operation, restore breakpoint
{
if(!(myDBGContext.EFlags & 0x100))
{
myDBGContext.EFlags = myDBGContext.EFlags ^ 0x100;
}
SetThreadContext(hActiveThread, &myDBGContext);
ResetMemBPXAddress = BreakPointBuffer[MaximumBreakPoints].BreakPointAddress;
ResetMemBPXSize = BreakPointBuffer[MaximumBreakPoints].BreakPointSize;
ResetMemBPX = true;
}
}
else if(BreakPointBuffer[MaximumBreakPoints].BreakPointType == UE_MEMORY_WRITE) //WRITE
{
if(BreakPointBuffer[MaximumBreakPoints].MemoryBpxRestoreOnHit != 1) //remove breakpoint
{
RemoveMemoryBPX(BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, BreakPointBuffer[MaximumBreakPoints].BreakPointSize);
}
else //restore breakpoint after trap flag
{
if(!(myDBGContext.EFlags & 0x100))
{
myDBGContext.EFlags = myDBGContext.EFlags ^ 0x100;
}
SetThreadContext(hActiveThread, &myDBGContext);
ResetMemBPXAddress = BreakPointBuffer[MaximumBreakPoints].BreakPointAddress;
ResetMemBPXSize = BreakPointBuffer[MaximumBreakPoints].BreakPointSize;
ResetMemBPX = true;
}
if(DBGEvent.u.Exception.ExceptionRecord.ExceptionInformation[0] == 1) //write operation
{
myCustomHandler = (fCustomHandler)(MemoryBpxCallBack);
__try
{
myCustomHandler((void*)bpaddr);
} }
__except(EXCEPTION_EXECUTE_HANDLER) __except(EXCEPTION_EXECUTE_HANDLER)
{ {
@ -17637,16 +17677,17 @@ __declspec(dllexport) void DebugLoop()
} }
else else
{ {
if(BreakPointBuffer[MaximumBreakPoints].BreakPointAddress >= (ULONG_PTR)DBGEvent.u.Exception.ExceptionRecord.ExceptionAddress && (ULONG_PTR)DBGEvent.u.Exception.ExceptionRecord.ExceptionAddress <= BreakPointBuffer[MaximumBreakPoints].BreakPointAddress + BreakPointBuffer[MaximumBreakPoints].BreakPointSize) if(!(myDBGContext.EFlags & 0x100))
{ {
VirtualQueryEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, &MemInfo, sizeof MEMORY_BASIC_INFORMATION); myDBGContext.EFlags = myDBGContext.EFlags ^ 0x100;
OldProtect = MemInfo.AllocationProtect;
NewProtect = OldProtect ^ PAGE_GUARD;
VirtualProtectEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, BreakPointBuffer[MaximumBreakPoints].BreakPointSize, NewProtect, &OldProtect);
} }
SetThreadContext(hActiveThread, &myDBGContext);
ResetMemBPXAddress = BreakPointBuffer[MaximumBreakPoints].BreakPointAddress;
ResetMemBPXSize = BreakPointBuffer[MaximumBreakPoints].BreakPointSize;
ResetMemBPX = true;
} }
} }
else if(BreakPointBuffer[MaximumBreakPoints].BreakPointType == UE_MEMORY_WRITE) else if(BreakPointBuffer[MaximumBreakPoints].BreakPointType == UE_MEMORY_EXECUTE) //EXECUTE
{ {
if(BreakPointBuffer[MaximumBreakPoints].MemoryBpxRestoreOnHit != 1) if(BreakPointBuffer[MaximumBreakPoints].MemoryBpxRestoreOnHit != 1)
{ {
@ -17654,41 +17695,47 @@ __declspec(dllexport) void DebugLoop()
} }
else else
{ {
VirtualQueryEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, &MemInfo, sizeof MEMORY_BASIC_INFORMATION); if(!(myDBGContext.EFlags & 0x100))
OldProtect = MemInfo.AllocationProtect; {
NewProtect = OldProtect ^ PAGE_GUARD; myDBGContext.EFlags = myDBGContext.EFlags ^ 0x100;
VirtualProtectEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, BreakPointBuffer[MaximumBreakPoints].BreakPointSize, NewProtect, &OldProtect); }
SetThreadContext(hActiveThread, &myDBGContext);
ResetMemBPXAddress = BreakPointBuffer[MaximumBreakPoints].BreakPointAddress;
ResetMemBPXSize = BreakPointBuffer[MaximumBreakPoints].BreakPointSize;
ResetMemBPX = true;
} }
if(DBGEvent.u.Exception.ExceptionRecord.ExceptionInformation[0] == 1) if(DBGEvent.u.Exception.ExceptionRecord.ExceptionInformation[0] == 0 && (ULONG_PTR)DBGEvent.u.Exception.ExceptionRecord.ExceptionAddress >= BreakPointBuffer[MaximumBreakPoints].BreakPointAddress && (ULONG_PTR)DBGEvent.u.Exception.ExceptionRecord.ExceptionAddress <= BreakPointBuffer[MaximumBreakPoints].BreakPointAddress + BreakPointBuffer[MaximumBreakPoints].BreakPointSize) //read operation
{ {
myCustomBreakPoint = (fCustomBreakPoint)((LPVOID)MemoryBpxCallBack); myCustomHandler = (fCustomHandler)(MemoryBpxCallBack);
__try __try
{ {
myCustomBreakPoint(); myCustomHandler((void*)bpaddr);
} }
__except(EXCEPTION_EXECUTE_HANDLER) __except(EXCEPTION_EXECUTE_HANDLER)
{ {
} }
} }
else else //no execute operation, restore breakpoint
{ {
if(BreakPointBuffer[MaximumBreakPoints].BreakPointAddress >= (ULONG_PTR)DBGEvent.u.Exception.ExceptionRecord.ExceptionAddress && (ULONG_PTR)DBGEvent.u.Exception.ExceptionRecord.ExceptionAddress <= BreakPointBuffer[MaximumBreakPoints].BreakPointAddress + BreakPointBuffer[MaximumBreakPoints].BreakPointSize) if(!(myDBGContext.EFlags & 0x100))
{ {
VirtualQueryEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, &MemInfo, sizeof MEMORY_BASIC_INFORMATION); myDBGContext.EFlags = myDBGContext.EFlags ^ 0x100;
OldProtect = MemInfo.AllocationProtect;
NewProtect = OldProtect ^ PAGE_GUARD;
VirtualProtectEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, BreakPointBuffer[MaximumBreakPoints].BreakPointSize, NewProtect, &OldProtect);
} }
SetThreadContext(hActiveThread, &myDBGContext);
ResetMemBPXAddress = BreakPointBuffer[MaximumBreakPoints].BreakPointAddress;
ResetMemBPXSize = BreakPointBuffer[MaximumBreakPoints].BreakPointSize;
ResetMemBPX = true;
} }
} }
EngineCloseHandle(hActiveThread);
} }
else else
{ {
DBGCode = DBG_EXCEPTION_NOT_HANDLED; DBGCode = DBG_EXCEPTION_NOT_HANDLED;
} }
} }
else else //no memory breakpoint found
{ {
DBGCode = DBG_EXCEPTION_NOT_HANDLED; DBGCode = DBG_EXCEPTION_NOT_HANDLED;
} }
@ -17772,7 +17819,6 @@ __declspec(dllexport) void DebugLoop()
} }
SetThreadContext(hActiveThread, &myDBGContext); SetThreadContext(hActiveThread, &myDBGContext);
EngineCloseHandle(hActiveThread); EngineCloseHandle(hActiveThread);
//TODO fixed
VirtualProtectEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, BreakPointBuffer[MaximumBreakPoints].BreakPointSize, OldProtect, &OldProtect); VirtualProtectEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, BreakPointBuffer[MaximumBreakPoints].BreakPointSize, OldProtect, &OldProtect);
myCustomBreakPoint = (fCustomBreakPoint)((LPVOID)BreakPointBuffer[MaximumBreakPoints].ExecuteCallBack); myCustomBreakPoint = (fCustomBreakPoint)((LPVOID)BreakPointBuffer[MaximumBreakPoints].ExecuteCallBack);
if(BreakPointBuffer[MaximumBreakPoints].NumberOfExecutions != -1 && BreakPointBuffer[MaximumBreakPoints].NumberOfExecutions != 0) if(BreakPointBuffer[MaximumBreakPoints].NumberOfExecutions != -1 && BreakPointBuffer[MaximumBreakPoints].NumberOfExecutions != 0)
@ -17920,14 +17966,12 @@ __declspec(dllexport) void DebugLoop()
} }
else else
{ {
//TODO fixed
VirtualProtectEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, BreakPointBuffer[MaximumBreakPoints].BreakPointSize, OldProtect, &OldProtect); VirtualProtectEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, BreakPointBuffer[MaximumBreakPoints].BreakPointSize, OldProtect, &OldProtect);
DBGCode = DBG_CONTINUE; DBGCode = DBG_CONTINUE;
} }
} }
else else
{ {
//TODO fixed
VirtualProtectEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, BreakPointBuffer[MaximumBreakPoints].BreakPointSize, OldProtect, &OldProtect); VirtualProtectEx(dbgProcessInformation.hProcess, (LPVOID)BreakPointBuffer[MaximumBreakPoints].BreakPointAddress, BreakPointBuffer[MaximumBreakPoints].BreakPointSize, OldProtect, &OldProtect);
DBGCode = DBG_EXCEPTION_NOT_HANDLED; DBGCode = DBG_EXCEPTION_NOT_HANDLED;
} }

View File

@ -66,10 +66,10 @@
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)$(Platform)\$(Configuration)\</OutDir> <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</IntDir> <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Platform)\$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental> <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir> <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)\$(IntDir)x32</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir> <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\x32</IntDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)$(Platform)\$(Configuration)\</OutDir> <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)\$(Configuration)\x64</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Platform)\$(Configuration)\</IntDir> <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Configuration)\x64</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental> <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" /> <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />

View File

@ -415,6 +415,7 @@ typedef struct
#define UE_MEMORY 3 #define UE_MEMORY 3
#define UE_MEMORY_READ 4 #define UE_MEMORY_READ 4
#define UE_MEMORY_WRITE 5 #define UE_MEMORY_WRITE 5
#define UE_MEMORY_EXECUTE 6
#define UE_BREAKPOINT_TYPE_INT3 0x10000000 #define UE_BREAKPOINT_TYPE_INT3 0x10000000
#define UE_BREAKPOINT_TYPE_LONG_INT3 0x20000000 #define UE_BREAKPOINT_TYPE_LONG_INT3 0x20000000
#define UE_BREAKPOINT_TYPE_UD2 0x30000000 #define UE_BREAKPOINT_TYPE_UD2 0x30000000

Binary file not shown.