diff --git a/TitanEngine/Global.Breakpoints.cpp b/TitanEngine/Global.Breakpoints.cpp index 716a300..f4d78c3 100644 --- a/TitanEngine/Global.Breakpoints.cpp +++ b/TitanEngine/Global.Breakpoints.cpp @@ -113,7 +113,7 @@ void uintdr7(ULONG_PTR dr7, DR7* ret) void BreakPointPostReadFilter(ULONG_PTR lpBaseAddress, unsigned char* lpBuffer, SIZE_T nSize) { - MutexLocker lock("BreakPointBuffer"); + CriticalSectionLocker lock(LockBreakPointBuffer); ULONG_PTR start=lpBaseAddress; ULONG_PTR end=start+nSize; int bpcount=BreakPointBuffer.size(); @@ -124,7 +124,7 @@ void BreakPointPostReadFilter(ULONG_PTR lpBaseAddress, unsigned char* lpBuffer, if(curBp->BreakPointActive != UE_BPXACTIVE || (curBp->BreakPointType != UE_BREAKPOINT && curBp->BreakPointType != UE_SINGLESHOOT)) continue; ULONG_PTR cur_addr=curBp->BreakPointAddress; - for(int j=0; jBreakPointSize; j++) + for(SIZE_T j=0; jBreakPointSize; j++) { if(cur_addr+j==start && cur_addr+jBreakPointActive != UE_BPXACTIVE || (curBp->BreakPointType != UE_BREAKPOINT && curBp->BreakPointType != UE_SINGLESHOOT)) continue; ULONG_PTR cur_addr=curBp->BreakPointAddress; - for(int j=0; jBreakPointSize; j++) + for(SIZE_T j=0; jBreakPointSize; j++) { if(cur_addr+j==start && cur_addr+jBreakPointActive != UE_BPXACTIVE || (curBp->BreakPointType != UE_BREAKPOINT && curBp->BreakPointType != UE_SINGLESHOOT)) continue; ULONG_PTR cur_addr=curBp->BreakPointAddress; - for(int j=0; jBreakPointSize; j++) + for(SIZE_T j=0; jBreakPointSize; j++) { if(cur_addr+j==start && cur_addr+j BreakPointBuffer; void uintdr7(ULONG_PTR dr7, DR7* ret); ULONG_PTR dr7uint(DR7* dr7); void BreakPointPostReadFilter(ULONG_PTR lpBaseAddress, unsigned char* lpBuffer, SIZE_T nSize); -void BreakPointPreWriteFilter(ULONG_PTR lpBaseAddress, SIZE_T nSize, MutexLocker* lock); -void BreakPointPostWriteFilter(ULONG_PTR lpBaseAddress, SIZE_T nSize, MutexLocker* lock); +void BreakPointPreWriteFilter(ULONG_PTR lpBaseAddress, SIZE_T nSize, CriticalSectionLocker* lock); +void BreakPointPostWriteFilter(ULONG_PTR lpBaseAddress, SIZE_T nSize, CriticalSectionLocker* lock); #endif //_GLOBAL_BREAKPOINTS_H diff --git a/TitanEngine/Global.Engine.Threading.cpp b/TitanEngine/Global.Engine.Threading.cpp index 160d094..a03bbe4 100644 --- a/TitanEngine/Global.Engine.Threading.cpp +++ b/TitanEngine/Global.Engine.Threading.cpp @@ -2,35 +2,37 @@ #include "definitions.h" #include "Global.Engine.Threading.h" -MutexLocker::MutexLocker(const char* name) +static CRITICAL_SECTION locks[LockLast]; + +void CriticalSectionInitializeLocks() { - int len=strlen(name); - DynBuf newNameBuf(len+20); - char* newName = (char*)newNameBuf.GetPtr(); - sprintf(newName, "Local\\%s%X", name, GetCurrentProcessId()); - gMutex=CreateMutexA(0, true, newName); - bUnlocked=false; - WaitForSingleObject(gMutex, INFINITE); + for(int i=0; iOptionalHeader.ImageBase; + ULONG_PTR ConvertAddress = AddressToConvert - (ULONG_PTR)PEHeader64->OptionalHeader.ImageBase; PIMAGE_SECTION_HEADER PESections = IMAGE_FIRST_SECTION(PEHeader64); DWORD SectionNumber = PEHeader64->FileHeader.NumberOfSections; DWORD FoundInSection = -1; diff --git a/TitanEngine/TitanEngine.cpp b/TitanEngine/TitanEngine.cpp index df1641e..29dcacd 100644 --- a/TitanEngine/TitanEngine.cpp +++ b/TitanEngine/TitanEngine.cpp @@ -4,6 +4,7 @@ #include "Global.Garbage.h" #include "Global.Injector.h" #include "Global.Engine.Extension.h" +#include "Global.Engine.Threading.h" // Global.Engine.Entry: BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) @@ -11,6 +12,7 @@ BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) switch(fdwReason) { case DLL_PROCESS_ATTACH: + CriticalSectionInitializeLocks(); //initialize critical sections engineHandle=hinstDLL; EngineInit(); EmptyGarbage(); @@ -23,6 +25,7 @@ BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) if(lpvReserved) ExtensionManagerPluginReleaseCallBack(); RemoveDirectoryW(engineSzEngineGarbageFolder); + CriticalSectionDeleteLocks(); //delete critical sections break; } return TRUE;