diff --git a/src/lib/arch/IArchSystem.h b/src/lib/arch/IArchSystem.h index 826f6e5f..8b508ac5 100644 --- a/src/lib/arch/IArchSystem.h +++ b/src/lib/arch/IArchSystem.h @@ -56,4 +56,11 @@ public: */ virtual void setting(const std::string& valueName, const std::string& valueString) const = 0; //@} + + //! Get the pathnames of the libraries used by Synergy + /* + Returns a string containing the full path names of all loaded libraries at the point it is called. + */ + virtual std::string getLibsUsed(void) const = 0; + //@} }; diff --git a/src/lib/arch/win32/ArchSystemWindows.cpp b/src/lib/arch/win32/ArchSystemWindows.cpp index b1853d9b..391726ec 100644 --- a/src/lib/arch/win32/ArchSystemWindows.cpp +++ b/src/lib/arch/win32/ArchSystemWindows.cpp @@ -23,6 +23,9 @@ #include "tchar.h" #include +#include +#include + static const char* s_settingsKeyNames[] = { _T("SOFTWARE"), _T("Synergy"), @@ -152,3 +155,39 @@ ArchSystemWindows::isWOW64() const #endif return false; } +#pragma comment(lib, "psapi") + +std::string +ArchSystemWindows::getLibsUsed(void) const +{ + HMODULE hMods[1024]; + HANDLE hProcess; + DWORD cbNeeded; + unsigned int i; + char hex[16]; + + DWORD pid = GetCurrentProcessId(); + + std::string msg = "pid:" + std::to_string((_ULonglong)pid) + "\n"; + + hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid); + + if (NULL == hProcess) { + return msg; + } + + if (EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded)) { + for (i = 0; i < (cbNeeded / sizeof(HMODULE)); i++) { + TCHAR szModName[MAX_PATH]; + if (GetModuleFileNameEx(hProcess, hMods[i], szModName, sizeof(szModName) / sizeof(TCHAR))) { + sprintf(hex,"(0x%08X)",hMods[i]); + msg += szModName; + msg.append(hex); + msg.append("\n"); + } + } + } + + CloseHandle(hProcess); + return msg; +} diff --git a/src/lib/arch/win32/ArchSystemWindows.h b/src/lib/arch/win32/ArchSystemWindows.h index a7e237a5..c747f28f 100644 --- a/src/lib/arch/win32/ArchSystemWindows.h +++ b/src/lib/arch/win32/ArchSystemWindows.h @@ -33,6 +33,7 @@ public: virtual std::string getPlatformName() const; virtual std::string setting(const std::string& valueName) const; virtual void setting(const std::string& valueName, const std::string& valueString) const; + virtual std::string getLibsUsed(void) const; bool isWOW64() const; }; diff --git a/src/lib/plugin/ns/ns.cpp b/src/lib/plugin/ns/ns.cpp index b2d8823d..114023c5 100644 --- a/src/lib/plugin/ns/ns.cpp +++ b/src/lib/plugin/ns/ns.cpp @@ -23,6 +23,9 @@ #include "base/Log.h" #include +#include +#include +#include const char * kSynergyVers = VERSION; SecureSocket* g_secureSocket = NULL; @@ -30,8 +33,21 @@ SecureListenSocket* g_secureListenSocket = NULL; Arch* g_arch = NULL; Log* g_log = NULL; -extern "C" { +std::string +helperGetLibsUsed(void) +{ + std::stringstream libs(ARCH->getLibsUsed()); + std::string msg; + std::string pid; + std::getline(libs,pid); + while( std::getline(libs,msg) ) { + LOG(( CLOG_DEBUG "libs:%s",msg.c_str())); + } + return pid; +} + +extern "C" { void init(void* log, void* arch) { @@ -42,6 +58,8 @@ init(void* log, void* arch) if (g_arch == NULL) { Arch::setInstance(reinterpret_cast(arch)); } + + LOG(( CLOG_DEBUG "%s",helperGetLibsUsed().c_str())); } int