From adce077e4829773ca61bd50b3f10eee8f54af323 Mon Sep 17 00:00:00 2001 From: "Mr. eXoDia" Date: Thu, 29 May 2014 02:24:14 +0200 Subject: [PATCH] fixed dll breakpoints --- .../TitanEngine.Debugger.DebugLoop.cpp | 6 ++--- TitanEngine/TitanEngine.Debugger.cpp | 25 ++++++++++++------- TitanEngine/TitanEngine.Librarian.cpp | 2 +- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp b/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp index 4e79e9c..0d78a69 100644 --- a/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp +++ b/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp @@ -338,7 +338,7 @@ __declspec(dllexport) void TITCALL DebugLoop() } if(engineFakeDLLHandle == NULL) { - if(lstrcmpiW(&DLLDebugFileName[i+1], L"kernel32.dll") == NULL) + if(_wcsicmp(&DLLDebugFileName[i+1], L"kernel32.dll") == NULL) { engineFakeDLLHandle = (ULONG_PTR)DBGEvent.u.LoadDll.lpBaseOfDll; } @@ -354,7 +354,7 @@ __declspec(dllexport) void TITCALL DebugLoop() for(int i = LibrarianData.size() - 1; i >= 0; i--) { ptrLibrarianData=&LibrarianData.at(i); - if(!lstrcmpiA(ptrLibrarianData->szLibraryName, szAnsiLibraryName)) + if(!_stricmp(ptrLibrarianData->szLibraryName, szAnsiLibraryName)) { if(ptrLibrarianData->bpxType == UE_ON_LIB_LOAD || ptrLibrarianData->bpxType == UE_ON_LIB_ALL) { @@ -423,7 +423,7 @@ __declspec(dllexport) void TITCALL DebugLoop() for(int i= LibrarianData.size() - 1; i >= 0; i--) { ptrLibrarianData = &LibrarianData.at(i); - if(!lstrcmpiA(ptrLibrarianData->szLibraryName, szAnsiLibraryName)) + if(!_stricmp(ptrLibrarianData->szLibraryName, szAnsiLibraryName)) { if(ptrLibrarianData->bpxType == UE_ON_LIB_UNLOAD || ptrLibrarianData->bpxType == UE_ON_LIB_ALL) { diff --git a/TitanEngine/TitanEngine.Debugger.cpp b/TitanEngine/TitanEngine.Debugger.cpp index d728a7d..3f12a1b 100644 --- a/TitanEngine/TitanEngine.Debugger.cpp +++ b/TitanEngine/TitanEngine.Debugger.cpp @@ -44,7 +44,6 @@ __declspec(dllexport) void* TITCALL InitDebug(char* szFileName, char* szCommandL } __declspec(dllexport) void* TITCALL InitDebugW(wchar_t* szFileName, wchar_t* szCommandLine, wchar_t* szCurrentFolder) { - wchar_t szCreateWithCmdLine[1024]; int DebugConsoleFlag = NULL; @@ -59,7 +58,7 @@ __declspec(dllexport) void* TITCALL InitDebugW(wchar_t* szFileName, wchar_t* szC EngineSetDebugPrivilege(GetCurrentProcess(), true); DebugRemoveDebugPrivilege = true; } - if(szCommandLine == NULL) + if(szCommandLine == NULL || !lstrlenW(szCommandLine)) { if(CreateProcessW(szFileName, NULL, NULL, NULL, false, DEBUG_PROCESS|DEBUG_ONLY_THIS_PROCESS|DebugConsoleFlag|CREATE_NEW_CONSOLE, NULL, szCurrentFolder, &dbgStartupInfo, &dbgProcessInformation)) { @@ -68,17 +67,19 @@ __declspec(dllexport) void* TITCALL InitDebugW(wchar_t* szFileName, wchar_t* szC DebugAttachedToProcess = false; DebugAttachedProcessCallBack = NULL; std::vector().swap(BreakPointBuffer); - return(&dbgProcessInformation); + return &dbgProcessInformation; } else { + DWORD lastError = GetLastError(); if(engineEnableDebugPrivilege) { EngineSetDebugPrivilege(GetCurrentProcess(), false); DebugRemoveDebugPrivilege = false; } - RtlZeroMemory(&dbgProcessInformation,sizeof PROCESS_INFORMATION); - return(0); + memset(&dbgProcessInformation, 0, sizeof(PROCESS_INFORMATION)); + SetLastError(lastError); + return 0; } } else @@ -91,30 +92,35 @@ __declspec(dllexport) void* TITCALL InitDebugW(wchar_t* szFileName, wchar_t* szC DebugAttachedToProcess = false; DebugAttachedProcessCallBack = NULL; std::vector().swap(BreakPointBuffer); - return(&dbgProcessInformation); + return &dbgProcessInformation; } else { + DWORD lastError = GetLastError(); if(engineEnableDebugPrivilege) { EngineSetDebugPrivilege(GetCurrentProcess(), false); DebugRemoveDebugPrivilege = false; } - RtlZeroMemory(&dbgProcessInformation,sizeof PROCESS_INFORMATION); - return(0); + memset(&dbgProcessInformation, 0, sizeof(PROCESS_INFORMATION)); + SetLastError(lastError); + return 0; } } } + __declspec(dllexport) void* TITCALL InitDebugEx(char* szFileName, char* szCommandLine, char* szCurrentFolder, LPVOID EntryCallBack) { DebugExeFileEntryPointCallBack = EntryCallBack; return(InitDebug(szFileName, szCommandLine, szCurrentFolder)); } + __declspec(dllexport) void* TITCALL InitDebugExW(wchar_t* szFileName, wchar_t* szCommandLine, wchar_t* szCurrentFolder, LPVOID EntryCallBack) { DebugExeFileEntryPointCallBack = EntryCallBack; return(InitDebugW(szFileName, szCommandLine, szCurrentFolder)); } + __declspec(dllexport) void* TITCALL InitDLLDebug(char* szFileName, bool ReserveModuleBase, char* szCommandLine, char* szCurrentFolder, LPVOID EntryCallBack) { @@ -149,6 +155,7 @@ __declspec(dllexport) void* TITCALL InitDLLDebug(char* szFileName, bool ReserveM return NULL; } } + __declspec(dllexport) void* TITCALL InitDLLDebugW(wchar_t* szFileName, bool ReserveModuleBase, wchar_t* szCommandLine, wchar_t* szCurrentFolder, LPVOID EntryCallBack) { @@ -202,7 +209,7 @@ __declspec(dllexport) void* TITCALL InitDLLDebugW(wchar_t* szFileName, bool Rese DebugReserveModuleBase = DebugModuleImageBase; DebugModuleEntryPoint = (ULONG_PTR)GetPE32DataW(szFileName, NULL, UE_OEP); DebugModuleEntryPointCallBack = EntryCallBack; - return(InitDebugW(szDebuggerName, szCommandLine, szCurrentFolder)); + return InitDebugW(szDebuggerName, szCommandLine, szCurrentFolder); } return 0; } diff --git a/TitanEngine/TitanEngine.Librarian.cpp b/TitanEngine/TitanEngine.Librarian.cpp index 4b81e48..5e794fb 100644 --- a/TitanEngine/TitanEngine.Librarian.cpp +++ b/TitanEngine/TitanEngine.Librarian.cpp @@ -22,7 +22,7 @@ __declspec(dllexport) bool TITCALL LibrarianRemoveBreakPoint(char* szLibraryName { for(int i = LibrarianData.size() - 1; i >= 0; i--) { - if(!lstrcmpiA(szLibraryName, LibrarianData.at(i).szLibraryName) && (LibrarianData.at(i).bpxType == bpxType || bpxType == UE_ON_LIB_ALL)) + if(!_stricmp(szLibraryName, LibrarianData.at(i).szLibraryName) && (LibrarianData.at(i).bpxType == bpxType || bpxType == UE_ON_LIB_ALL)) { LibrarianData.erase(LibrarianData.begin() + i); }