- MemoryReadSafe now actually filters breakpoints out of the buffer

This commit is contained in:
Mr. eXoDia 2014-03-10 00:42:30 +01:00
parent 93a8582044
commit 92eb890c7f
3 changed files with 30 additions and 0 deletions

View File

@ -110,3 +110,26 @@ void uintdr7(ULONG_PTR dr7, DR7* ret)
if(BITGET(dr7,31))
BITSET(ret->HWBP_SIZE[3],1);
}
void FilterBreakPoints(ULONG_PTR lpBaseAddress, unsigned char* lpBuffer, SIZE_T nSize)
{
ULONG_PTR start=lpBaseAddress;
ULONG_PTR end=start+nSize;
int bpcount=BreakPointBuffer.size();
for(int i=0; i<bpcount; i++)
{
BreakPointDetail* curBp=&BreakPointBuffer.at(i);
//check if the breakpoint is one we should be concerned about
if(!curBp->BreakPointActive || (curBp->BreakPointType != UE_BREAKPOINT && curBp->BreakPointType != UE_SINGLESHOOT))
continue;
ULONG_PTR cur_addr=curBp->BreakPointAddress;
if(cur_addr>=start && cur_addr<end) //breakpoint is in range
{
ULONG_PTR index=cur_addr-start; //calculate where to write in the buffer
int n=curBp->BreakPointSize;
if((cur_addr+n)>end)
n=end-cur_addr; //do not overflow the buffer
memcpy(lpBuffer+index, curBp->OriginalByte, n);
}
}
}

View File

@ -7,5 +7,6 @@ extern std::vector<BreakPointDetail> BreakPointBuffer;
void uintdr7(ULONG_PTR dr7, DR7* ret);
ULONG_PTR dr7uint(DR7* dr7);
void FilterBreakPoints(ULONG_PTR lpBaseAddress, unsigned char* lpBuffer, SIZE_T nSize);
#endif //_GLOBAL_BREAKPOINTS_H

View File

@ -1,6 +1,7 @@
#include "stdafx.h"
#include "definitions.h"
#include "Global.Debugger.h"
#include "Global.Breakpoints.h"
#include <stdlib.h>
__declspec(dllexport) bool TITCALL MatchPatternEx(HANDLE hProcess, void* MemoryToCheck, int SizeOfMemoryToCheck, void* PatternToMatch, int SizeOfPatternToMatch, PBYTE WildCard)
@ -368,6 +369,7 @@ __declspec(dllexport) bool TITCALL MemoryReadSafe(HANDLE hProcess, LPVOID lpBase
DWORD dwProtect = 0;
bool retValue = false;
//read memory
if ( (hProcess == 0) || (lpBaseAddress == 0) || (lpBuffer == 0) || (nSize == 0))
{
return false;
@ -398,6 +400,10 @@ __declspec(dllexport) bool TITCALL MemoryReadSafe(HANDLE hProcess, LPVOID lpBase
retValue = true;
}
//filter breakpoints
if(retValue)
FilterBreakPoints((ULONG_PTR)lpBaseAddress, (unsigned char*)lpBuffer, nSize);
return retValue;
}