diff --git a/CMakeLists.txt b/CMakeLists.txt index 4231957f..7a30c9c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -441,6 +441,7 @@ target_link_libraries(dbg PRIVATE Shlwapi Ws2_32 Wininet + Iphlpapi ) if(CMAKE_SIZEOF_VOID_P EQUAL 4) # x86 diff --git a/cmake.toml b/cmake.toml index 69372d2e..1d0742de 100644 --- a/cmake.toml +++ b/cmake.toml @@ -105,6 +105,7 @@ private-link-libraries = [ "Shlwapi", "Ws2_32", "Wininet", + "Iphlpapi", ] x86.private-link-libraries = [ "src/dbg/dbghelp/dbghelp_x86.lib", diff --git a/src/dbg/_global.cpp b/src/dbg/_global.cpp index b4535674..34c6d8b5 100644 --- a/src/dbg/_global.cpp +++ b/src/dbg/_global.cpp @@ -403,7 +403,6 @@ void WaitForMultipleThreadsTermination(const HANDLE* hThread, int count, DWORD t duint GetThreadCount() { duint threadCount = std::thread::hardware_concurrency(); -#if (_WIN32_WINNT >= 0x0601) // GetLogicalProcessorInformationEx is supported on Windows 7 DWORD length = 0; if(GetLogicalProcessorInformationEx(RelationAll, nullptr, &length) || GetLastError() != ERROR_INSUFFICIENT_BUFFER) { @@ -432,6 +431,5 @@ duint GetThreadCount() } offset += info->Size; } -#endif // _WIN32_WINNT >= 0x0600 return threadCount; } \ No newline at end of file diff --git a/src/dbg/commands/cmd-searching.cpp b/src/dbg/commands/cmd-searching.cpp index e6edbca6..29bcd6ed 100644 --- a/src/dbg/commands/cmd-searching.cpp +++ b/src/dbg/commands/cmd-searching.cpp @@ -76,19 +76,11 @@ class SearchTimer public: SearchTimer() { -#if (_WIN32_WINNT >= 0x0600) // GetTickCount64 is not supported on Windows XP ticks = GetTickCount64(); -#else - ticks = GetTickCount(); -#endif // _WIN32_WINNT >= 0x0600 } void StopTimer() { -#if (_WIN32_WINNT >= 0x0600) // GetTickCount64 is not supported on Windows XP ticks = GetTickCount64() - ticks; -#else - ticks = GetTickCount() - ticks; -#endif // _WIN32_WINNT >= 0x0600 } DWORD GetTicks() { diff --git a/src/dbg/exprfunc.cpp b/src/dbg/exprfunc.cpp index ddc3daf7..6ae05a63 100644 --- a/src/dbg/exprfunc.cpp +++ b/src/dbg/exprfunc.cpp @@ -468,11 +468,7 @@ namespace Exprfunc duint gettickcount() { -#if (_WIN32_WINNT >= 0x0600) - return GetTickCount64(); -#else - return GetTickCount(); -#endif _WIN32_WINNT >= 0x0600 + return (duint)GetTickCount64(); } duint rdtsc() diff --git a/src/dbg/handles.cpp b/src/dbg/handles.cpp index 6de80bbd..048b11ec 100644 --- a/src/dbg/handles.cpp +++ b/src/dbg/handles.cpp @@ -163,45 +163,15 @@ bool HandlesGetName(HANDLE remoteHandle, String & name, String & typeName) } else if(strcmp(typeName.c_str(), "Thread") == 0) { - DWORD TID, PID; -#if (_WIN32_WINNT >= 0x0600) - TID = GetThreadId(hLocalHandle); - PID = GetProcessIdOfThread(hLocalHandle); -#else - auto getTidPid = [](HANDLE hThread, DWORD & TID, DWORD & PID) - { - static auto pGetThreadId = (DWORD(__stdcall*)(HANDLE))GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "GetThreadId"); - static auto pGetProcessIdOfThread = (DWORD(__stdcall*)(HANDLE))GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "GetProcessIdOfThread"); - if(pGetThreadId != NULL && pGetProcessIdOfThread != NULL) //Vista or Server 2003 only - { - TID = pGetThreadId(hThread); - PID = pGetProcessIdOfThread(hThread); - } - else //Windows XP - { - THREAD_BASIC_INFORMATION threadInfo; - ULONG threadInfoSize = 0; - NTSTATUS isok = NtQueryInformationThread(hThread, ThreadBasicInformation, &threadInfo, sizeof(threadInfo), &threadInfoSize); - if(NT_SUCCESS(isok)) - { - TID = (DWORD)(duint)threadInfo.ClientId.UniqueThread; - PID = (DWORD)(duint)threadInfo.ClientId.UniqueProcess; - } - } - }; - getTidPid(hLocalHandle, TID, PID); -#endif // _WIN32_WINNT < 0x0600 + auto TID = GetThreadId(hLocalHandle); + auto PID = GetProcessIdOfThread(hLocalHandle); if(TID == 0 || PID == 0) //The first time could fail because the process didn't specify query permissions. { HANDLE hLocalQueryHandle; if(DuplicateHandle(hProcess, remoteHandle, GetCurrentProcess(), &hLocalQueryHandle, THREAD_QUERY_INFORMATION, FALSE, 0)) { -#if (_WIN32_WINNT >= 0x0600) TID = GetThreadId(hLocalQueryHandle); PID = GetProcessIdOfThread(hLocalQueryHandle); -#else - getTidPid(hLocalHandle, TID, PID); -#endif // _WIN32_WINNT < 0x0600 CloseHandle(hLocalQueryHandle); } } diff --git a/src/dbg/tcpconnections.cpp b/src/dbg/tcpconnections.cpp index 909773e3..b7c0b3ca 100644 --- a/src/dbg/tcpconnections.cpp +++ b/src/dbg/tcpconnections.cpp @@ -1,9 +1,6 @@ #include "tcpconnections.h" #include - -#if (_WIN32_WINNT >= 0x0600) #include -#pragma comment(lib, "iphlpapi.lib") static const char* TcpStateToString(unsigned int State) { @@ -37,12 +34,9 @@ static const char* TcpStateToString(unsigned int State) return "UNKNOWN"; } } -#endif // _WIN32_WINNT >= 0x0600 - bool TcpEnumConnections(duint pid, std::vector & connections) { -#if (_WIN32_WINNT >= 0x0600) TCPCONNECTIONINFO info; wchar_t AddrBuffer[TCP_ADDR_SIZE] = L""; ULONG ulSize = 0; @@ -106,8 +100,5 @@ bool TcpEnumConnections(duint pid, std::vector & connections) } } } -#else - // This feature requires Windows Vista or greater, so don't compile on Windows XP. -#endif // _WIN32_WINNT >= 0x0600 return true; } diff --git a/src/dbg/thread.cpp b/src/dbg/thread.cpp index 15111c4a..c0c05366 100644 --- a/src/dbg/thread.cpp +++ b/src/dbg/thread.cpp @@ -318,11 +318,7 @@ DWORD ThreadGetId(HANDLE Thread) } // Wasn't found, check with Windows -#if (_WIN32_WINNT >= 0x0600) // GetThreadId is not supported on Windows XP return GetThreadId(Thread); -#else - return 0; -#endif // _WIN32_WINNT >= 0x0600 } int ThreadSuspendAll() @@ -385,14 +381,10 @@ ULONG64 ThreadQueryCycleTime(HANDLE hThread) { ULONG64 CycleTime; -#if (_WIN32_WINNT >= 0x0600) // QueryThreadCycleTime is not supported on Windows XP if(!QueryThreadCycleTime(hThread, &CycleTime)) CycleTime = 0; return CycleTime; -#else - return 0; -#endif // _WIN32_WINNT >= 0x0600 } void ThreadUpdateWaitReasons() diff --git a/src/dbg/threading.cpp b/src/dbg/threading.cpp index 72005409..159f7e46 100644 --- a/src/dbg/threading.cpp +++ b/src/dbg/threading.cpp @@ -65,20 +65,13 @@ void SectionLockerGlobal::Initialize() // This gets called on the same thread as the GUI m_guiMainThreadId = GetCurrentThreadId(); -#if (_WIN32_WINNT >= 0x0600) + // Destroy previous data if any existed memset(m_srwLocks, 0, sizeof(m_srwLocks)); for(int i = 0; i < ARRAYSIZE(m_srwLocks); i++) InitializeSRWLock(&m_srwLocks[i]); -#else - // Fall back to critical sections otherwise - // Destroy previous data if any existed - memset(m_crLocks, 0, sizeof(m_crLocks)); - for(int i = 0; i < ARRAYSIZE(m_crLocks); i++) - InitializeCriticalSection(&m_crLocks[i]); -#endif // _WIN32_WINNT >= 0x0600 m_Initialized = true; } @@ -87,7 +80,6 @@ void SectionLockerGlobal::Deinitialize() if(!m_Initialized) return; -#if (_WIN32_WINNT >= 0x0600) for(int i = 0; i < ARRAYSIZE(m_srwLocks); i++) { // Wait for the lock's ownership to be released @@ -97,18 +89,6 @@ void SectionLockerGlobal::Deinitialize() // Invalidate data memset(&m_srwLocks[i], 0, sizeof(SRWLOCK)); } -#else - for(int i = 0; i < ARRAYSIZE(m_crLocks); i++) - { - // Wait for the lock's ownership to be released - EnterCriticalSection(&m_crLocks[i]); - LeaveCriticalSection(&m_crLocks[i]); - - // Delete critical section - DeleteCriticalSection(&m_crLocks[i]); - memset(&m_crLocks[i], 0, sizeof(CRITICAL_SECTION)); - } -#endif // _WIN32_WINNT >= 0x0600 m_Initialized = false; } diff --git a/src/dbg/threading.h b/src/dbg/threading.h index e11b1ecd..ceac5def 100644 --- a/src/dbg/threading.h +++ b/src/dbg/threading.h @@ -105,7 +105,6 @@ private: { auto threadId = GetCurrentThreadId(); -#if (_WIN32_WINNT >= 0x0600) auto srwLock = &m_srwLocks[LockIndex]; if(Shared) @@ -146,24 +145,11 @@ private: assert(m_exclusiveOwner[LockIndex].count == 0); m_exclusiveOwner[LockIndex].threadId = threadId; m_exclusiveOwner[LockIndex].count = 1; -#else - auto cr = &m_crLocks[LockIndex]; - if(ProcessGuiEvents && threadId == m_guiMainThreadId) - { - while(!TryEnterCriticalSection(cr)) - GuiProcessEvents(); - } - else - { - EnterCriticalSection(cr); - } -#endif // _WIN32_WINNT >= 0x0600 } template static void ReleaseLock() { -#if (_WIN32_WINNT >= 0x0600) if(Shared) { if(m_exclusiveOwner[LockIndex].threadId == GetCurrentThreadId()) @@ -181,9 +167,6 @@ private: m_exclusiveOwner[LockIndex].threadId = 0; ReleaseSRWLockExclusive(&m_srwLocks[LockIndex]); } -#else - LeaveCriticalSection(&m_crLocks[LockIndex]); -#endif // _WIN32_WINNT >= 0x0600 } static bool m_Initialized; diff --git a/src/gui/Src/Bridge/Bridge.cpp b/src/gui/Src/Bridge/Bridge.cpp index adc2c3d3..78225456 100644 --- a/src/gui/Src/Bridge/Bridge.cpp +++ b/src/gui/Src/Bridge/Bridge.cpp @@ -1132,24 +1132,8 @@ __declspec(dllexport) void* _gui_sendmessage(GUIMSG type, void* param1, void* pa __declspec(dllexport) const char* _gui_translate_text(const char* source) { -#if (_WIN32_WINNT >= 0x0600) // Starting from Windows Vista this is supported QByteArray translatedUtf8 = QCoreApplication::translate("DBG", source).toUtf8(); TLS_TranslatedString.Data[translatedUtf8.size()] = 0; // Set the string terminator first. memcpy(TLS_TranslatedString.Data, translatedUtf8.constData(), std::min((size_t)translatedUtf8.size(), sizeof(TLS_TranslatedString.Data) - 1)); // Then copy the string safely. return TLS_TranslatedString.Data; // Don't need to free this memory. But this pointer should be used immediately to reduce race condition. -#else - if(TLS_TranslatedStringMap) - { - QByteArray translatedUtf8 = QCoreApplication::translate("DBG", source).toUtf8(); - // Boom... VS does not support "thread_local"... and cannot use "__declspec(thread)" in a DLL... https://blogs.msdn.microsoft.com/oldnewthing/20101122-00/?p=12233 - // Simulating Thread Local Storage with a map... - DWORD ThreadId = GetCurrentThreadId(); - TranslatedStringStorage & TranslatedString = (*TLS_TranslatedStringMap)[ThreadId]; - TranslatedString.Data[translatedUtf8.size()] = 0; // Set the string terminator first. - memcpy(TranslatedString.Data, translatedUtf8.constData(), std::min((size_t)translatedUtf8.size(), sizeof(TranslatedString.Data) - 1)); // Then copy the string safely. - return TranslatedString.Data; // Don't need to free this memory. But this pointer should be used immediately to reduce race condition. - } - else // Translators are not initialized yet. - return source; -#endif // _WIN32_WINNT >= 0x0600 } diff --git a/src/gui/Src/Gui/HandlesView.cpp b/src/gui/Src/Gui/HandlesView.cpp index 71f2cdf3..e6d2bf9d 100644 --- a/src/gui/Src/Gui/HandlesView.cpp +++ b/src/gui/Src/Gui/HandlesView.cpp @@ -137,12 +137,6 @@ HandlesView::HandlesView(QWidget* parent) : QWidget(parent) connect(Config(), SIGNAL(shortcutsUpdated()), this, SLOT(refreshShortcuts())); connect(Bridge::getBridge(), SIGNAL(dbgStateChanged(DBGSTATE)), this, SLOT(dbgStateChanged(DBGSTATE))); -#if (_WIN32_WINNT < 0x0600) // This is only supported on Windows Vista or greater - mTcpConnectionsTable->setRowCount(1); - mTcpConnectionsTable->setCellContent(0, 0, tr("TCP Connection enumeration is only available on Windows Vista or greater.")); - mTcpConnectionsTable->reloadData(); -#endif (_WIN32_WINNT < 0x0600) - mWindowsTable->setAccessibleName(tr("Windows")); mHandlesTable->setAccessibleName(tr("Handles")); mTcpConnectionsTable->setAccessibleName(tr("TCP Connections")); @@ -530,7 +524,6 @@ void HandlesView::enumPrivileges() //Enumerate TCP connections and update TCP connections table void HandlesView::enumTcpConnections() { -#if (_WIN32_WINNT >= 0x0600) BridgeList connections; if(DbgFunctions()->EnumTcpConnections(&connections)) { @@ -551,7 +544,6 @@ void HandlesView::enumTcpConnections() mTcpConnectionsTable->reloadData(); // refresh values also when in mSearchList mTcpConnectionsTable->refreshSearchList(); -#endif // _WIN32_WINNT < 0x0600 } /* diff --git a/src/gui/Src/main.cpp b/src/gui/Src/main.cpp index 9eb8baa8..635565ba 100644 --- a/src/gui/Src/main.cpp +++ b/src/gui/Src/main.cpp @@ -63,13 +63,7 @@ bool MyApplication::notify(QObject* receiver, QEvent* event) static Configuration* mConfiguration; char gCurrentLocale[MAX_SETTING_SIZE] = ""; -#if (_WIN32_WINNT < 0x0600) -// Boom... VS does not support "thread_local"... and cannot use "__declspec(thread)" in a DLL... https://blogs.msdn.microsoft.com/oldnewthing/20101122-00/?p=12233 (dead link) -// Simulating Thread Local Storage with a map... -std::map* TLS_TranslatedStringMap; //key = Thread Id, value = Translate Buffer -#else thread_local TranslatedStringStorage TLS_TranslatedString; -#endif static bool isValidLocale(const QString & locale) { @@ -173,10 +167,6 @@ int main(int argc, char* argv[]) if(x64dbgTranslator.load(QString("x64dbg_%1").arg(gCurrentLocale), path)) application.installTranslator(&x64dbgTranslator); -#if (_WIN32_WINNT < 0x0600) - TLS_TranslatedStringMap = new std::map(); -#endif // _WIN32_WINNT < 0x0600 - // load config file + set config font mConfiguration = new Configuration; application.setFont(ConfigFont("Application")); @@ -237,12 +227,6 @@ int main(int argc, char* argv[]) #endif delete mainWindow; mConfiguration->save(); //save config on exit -#if (_WIN32_WINNT < 0x0600) - //delete tls - auto temp = TLS_TranslatedStringMap; - TLS_TranslatedStringMap = nullptr; - delete temp; -#endif // _WIN32_WINNT < 0x0600 //TODO free Zydis/config/bridge and prevent use after free. diff --git a/src/gui/Src/main.h b/src/gui/Src/main.h index b3a10838..ebdd3eeb 100644 --- a/src/gui/Src/main.h +++ b/src/gui/Src/main.h @@ -27,11 +27,8 @@ struct TranslatedStringStorage { char Data[4096]; }; -#if (_WIN32_WINNT >= 0x0600) + extern thread_local TranslatedStringStorage TLS_TranslatedString; -#else -extern std::map* TLS_TranslatedStringMap; -#endif // _WIN32_WINNT >= 0x0600 #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) class MyEventFilter : public QAbstractNativeEventFilter