diff --git a/src/Config.h b/src/Config.h index 8bf08d72..e546b750 100644 --- a/src/Config.h +++ b/src/Config.h @@ -30,7 +30,7 @@ #define VER_LAMEXP_MINOR_LO 3 #define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_PATCH 1 -#define VER_LAMEXP_BUILD 580 +#define VER_LAMEXP_BUILD 582 /////////////////////////////////////////////////////////////////////////////// // Tools versions diff --git a/src/Global.cpp b/src/Global.cpp index c44b887a..eec0b43e 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -572,12 +572,28 @@ lamexp_cpu_t lamexp_detect_cpu_features(void) return features; } +/* + * Check for debugger (detect routine) + */ +static bool lamexp_check_for_debugger(void) +{ + __try + { + DebugBreak(); + } + __except(GetExceptionCode() == EXCEPTION_BREAKPOINT ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) + { + return false; + } + return true; +} + /* * Check for debugger (thread proc) */ static void WINAPI lamexp_debug_thread_proc(__in LPVOID lpParameter) { - while(!IsDebuggerPresent()) + while(!(IsDebuggerPresent() || lamexp_check_for_debugger())) { Sleep(333); } @@ -589,11 +605,12 @@ static void WINAPI lamexp_debug_thread_proc(__in LPVOID lpParameter) */ static HANDLE lamexp_debug_thread_init(void) { - if(IsDebuggerPresent()) + if(IsDebuggerPresent() || lamexp_check_for_debugger()) { FatalAppExit(0, L"Not a debug build. Please unload debugger and try again!"); TerminateProcess(GetCurrentProcess(), -1); } + return CreateThread(NULL, NULL, reinterpret_cast(&lamexp_debug_thread_proc), NULL, NULL, NULL); } diff --git a/src/Main.cpp b/src/Main.cpp index f03f82d0..6ad24b84 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -43,7 +43,7 @@ // Main function /////////////////////////////////////////////////////////////////////////////// -int lamexp_main(int argc, char* argv[]) +static int lamexp_main(int argc, char* argv[]) { int iResult = -1; bool bAccepted = true; @@ -181,7 +181,7 @@ int lamexp_main(int argc, char* argv[]) // Applicaton entry point /////////////////////////////////////////////////////////////////////////////// -int main(int argc, char* argv[]) +static int _main(int argc, char* argv[]) { if(LAMEXP_DEBUG) { @@ -194,7 +194,6 @@ int main(int argc, char* argv[]) else { int iResult = -1; - SetUnhandledExceptionFilter(lamexp_exception_handler); try { qInstallMsgHandler(lamexp_message_handler); @@ -229,11 +228,35 @@ int main(int argc, char* argv[]) } } -extern "C" +int main(int argc, char* argv[]) { - void __declspec(dllexport) __stdcall Test(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow) + if(LAMEXP_DEBUG) { - OutputDebugStringA(lpszCmdLine); - MessageBoxA(0, lpszCmdLine, "LameXP is here!", MB_ICONINFORMATION); + return _main(argc, argv); + } + else + { + __try + { + SetUnhandledExceptionFilter(lamexp_exception_handler); + return _main(argc, argv); + } + __except(1) + { + fflush(stdout); + fflush(stderr); + fprintf(stderr, "\nGURU MEDITATION !!!\n"); + FatalAppExit(0, L"Unhandeled exception error, application will exit!"); + TerminateProcess(GetCurrentProcess(), -1); + } } } + +//extern "C" +//{ +// void __declspec(dllexport) __stdcall Test(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow) +// { +// OutputDebugStringA(lpszCmdLine); +// MessageBoxA(0, lpszCmdLine, "LameXP is here!", MB_ICONINFORMATION); +// } +//}