mirror of https://github.com/x64dbg/TitanEngine
- resolved issue #42 (fixed the pre/post filters)
- resolved issue #34 (critical sections lock tested & working) - dynamic DLLLoader name (avoids detection + you can debug two DLL files in the same directory)
This commit is contained in:
parent
51bf507216
commit
d777ee3590
|
|
@ -126,15 +126,10 @@ void BreakPointPostReadFilter(ULONG_PTR lpBaseAddress, unsigned char* lpBuffer,
|
||||||
ULONG_PTR cur_addr=curBp->BreakPointAddress;
|
ULONG_PTR cur_addr=curBp->BreakPointAddress;
|
||||||
for(SIZE_T j=0; j<curBp->BreakPointSize; j++)
|
for(SIZE_T j=0; j<curBp->BreakPointSize; j++)
|
||||||
{
|
{
|
||||||
if(cur_addr+j==start && cur_addr+j<end) //breakpoint is in range
|
if(cur_addr+j>=start && cur_addr+j<end) //breakpoint is in range
|
||||||
{
|
{
|
||||||
ULONG_PTR index=cur_addr+j-start; //calculate where to write in the buffer
|
ULONG_PTR index=cur_addr+j-start; //calculate where to write in the buffer
|
||||||
int n=curBp->BreakPointSize-j;
|
memcpy(lpBuffer+index, &curBp->OriginalByte[j], sizeof(char));
|
||||||
if((cur_addr+n)>end)
|
|
||||||
n=end-cur_addr; //do not overflow the buffer
|
|
||||||
memcpy(lpBuffer+index, &curBp->OriginalByte[j], n);
|
|
||||||
if(n==curBp->BreakPointSize)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -154,7 +149,7 @@ void BreakPointPreWriteFilter(ULONG_PTR lpBaseAddress, SIZE_T nSize, CriticalSec
|
||||||
ULONG_PTR cur_addr=curBp->BreakPointAddress;
|
ULONG_PTR cur_addr=curBp->BreakPointAddress;
|
||||||
for(SIZE_T j=0; j<curBp->BreakPointSize; j++)
|
for(SIZE_T j=0; j<curBp->BreakPointSize; j++)
|
||||||
{
|
{
|
||||||
if(cur_addr+j==start && cur_addr+j<end) //breakpoint byte is in range
|
if(cur_addr+j>=start && cur_addr+j<end) //breakpoint byte is in range
|
||||||
{
|
{
|
||||||
lock->unlock();
|
lock->unlock();
|
||||||
DisableBPX(cur_addr);
|
DisableBPX(cur_addr);
|
||||||
|
|
@ -180,7 +175,7 @@ void BreakPointPostWriteFilter(ULONG_PTR lpBaseAddress, SIZE_T nSize, CriticalSe
|
||||||
ULONG_PTR cur_addr=curBp->BreakPointAddress;
|
ULONG_PTR cur_addr=curBp->BreakPointAddress;
|
||||||
for(SIZE_T j=0; j<curBp->BreakPointSize; j++)
|
for(SIZE_T j=0; j<curBp->BreakPointSize; j++)
|
||||||
{
|
{
|
||||||
if(cur_addr+j==start && cur_addr+j<end) //breakpoint byte is in range
|
if(cur_addr+j>=start && cur_addr+j<end) //breakpoint byte is in range
|
||||||
{
|
{
|
||||||
curBp->BreakPointActive = UE_BPXINACTIVE; //little hack
|
curBp->BreakPointActive = UE_BPXINACTIVE; //little hack
|
||||||
lock->unlock();
|
lock->unlock();
|
||||||
|
|
|
||||||
|
|
@ -2,37 +2,45 @@
|
||||||
#include "definitions.h"
|
#include "definitions.h"
|
||||||
#include "Global.Engine.Threading.h"
|
#include "Global.Engine.Threading.h"
|
||||||
|
|
||||||
static CRITICAL_SECTION locks[LockLast];
|
static CRITICAL_SECTION locks[LockLast] = {};
|
||||||
|
static bool bInitDone = false;
|
||||||
|
|
||||||
void CriticalSectionInitializeLocks()
|
static void CriticalSectionInitializeLocks()
|
||||||
{
|
{
|
||||||
|
if(bInitDone)
|
||||||
|
return;
|
||||||
for(int i=0; i<LockLast; i++)
|
for(int i=0; i<LockLast; i++)
|
||||||
InitializeCriticalSection(&locks[i]);
|
InitializeCriticalSection(&locks[i]);
|
||||||
|
bInitDone=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CriticalSectionDeleteLocks()
|
void CriticalSectionDeleteLocks()
|
||||||
{
|
{
|
||||||
|
if(!bInitDone)
|
||||||
|
return;
|
||||||
for(int i=0; i<LockLast; i++)
|
for(int i=0; i<LockLast; i++)
|
||||||
DeleteCriticalSection(&locks[i]);
|
DeleteCriticalSection(&locks[i]);
|
||||||
|
bInitDone=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CriticalSectionLocker::CriticalSectionLocker(CriticalSectionLock lock)
|
CriticalSectionLocker::CriticalSectionLocker(CriticalSectionLock lock)
|
||||||
{
|
{
|
||||||
gCriticalSection=&locks[lock];
|
CriticalSectionInitializeLocks(); //initialize critical sections
|
||||||
EnterCriticalSection(gCriticalSection);
|
gLock=lock;
|
||||||
|
EnterCriticalSection(&locks[gLock]);
|
||||||
}
|
}
|
||||||
|
|
||||||
CriticalSectionLocker::~CriticalSectionLocker()
|
CriticalSectionLocker::~CriticalSectionLocker()
|
||||||
{
|
{
|
||||||
LeaveCriticalSection(gCriticalSection);
|
LeaveCriticalSection(&locks[gLock]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CriticalSectionLocker::unlock()
|
void CriticalSectionLocker::unlock()
|
||||||
{
|
{
|
||||||
LeaveCriticalSection(gCriticalSection);
|
LeaveCriticalSection(&locks[gLock]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CriticalSectionLocker::relock()
|
void CriticalSectionLocker::relock()
|
||||||
{
|
{
|
||||||
EnterCriticalSection(gCriticalSection);
|
EnterCriticalSection(&locks[gLock]);
|
||||||
}
|
}
|
||||||
|
|
@ -7,7 +7,6 @@ enum CriticalSectionLock
|
||||||
LockLast
|
LockLast
|
||||||
};
|
};
|
||||||
|
|
||||||
void CriticalSectionInitializeLocks();
|
|
||||||
void CriticalSectionDeleteLocks();
|
void CriticalSectionDeleteLocks();
|
||||||
|
|
||||||
class CriticalSectionLocker
|
class CriticalSectionLocker
|
||||||
|
|
@ -19,7 +18,7 @@ public:
|
||||||
void relock();
|
void relock();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LPCRITICAL_SECTION gCriticalSection;
|
CriticalSectionLock gLock;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //_GLOBAL_ENGINE_THREADING_H
|
#endif //_GLOBAL_ENGINE_THREADING_H
|
||||||
|
|
@ -170,22 +170,17 @@ __declspec(dllexport) void* TITCALL InitDLLDebugW(wchar_t* szFileName, bool Rese
|
||||||
{
|
{
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
|
wchar_t DLLLoaderName[64]=L"";
|
||||||
|
#ifdef _WIN64
|
||||||
|
wsprintfW(DLLLoaderName, L"DLLLoader64_%.4X.exe", GetTickCount()&0xFFFF);
|
||||||
|
#else
|
||||||
|
wsprintfW(DLLLoaderName, L"DLLLoader32_%.4X.exe", GetTickCount()&0xFFFF);
|
||||||
|
#endif
|
||||||
if(i)
|
if(i)
|
||||||
{
|
lstrcpyW(szDebuggerName+i+1, DLLLoaderName);
|
||||||
#ifdef _WIN64
|
|
||||||
lstrcpyW(szDebuggerName+i+1, L"DLLLoader64.exe");
|
|
||||||
#else
|
|
||||||
lstrcpyW(szDebuggerName+i+1, L"DLLLoader32.exe");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
lstrcpyW(szDebuggerName, DLLLoaderName);
|
||||||
#ifdef _WIN64
|
|
||||||
lstrcpyW(szDebuggerName, L"DLLLoader64.exe");
|
|
||||||
#else
|
|
||||||
lstrcpyW(szDebuggerName, L"DLLLoader32.exe");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#if defined(_WIN64)
|
#if defined(_WIN64)
|
||||||
ReturnData = EngineExtractResource("LOADERX64", szDebuggerName);
|
ReturnData = EngineExtractResource("LOADERX64", szDebuggerName);
|
||||||
#else
|
#else
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
||||||
switch(fdwReason)
|
switch(fdwReason)
|
||||||
{
|
{
|
||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_ATTACH:
|
||||||
CriticalSectionInitializeLocks(); //initialize critical sections
|
|
||||||
engineHandle=hinstDLL;
|
engineHandle=hinstDLL;
|
||||||
EngineInit();
|
EngineInit();
|
||||||
EmptyGarbage();
|
EmptyGarbage();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue