Added ability to query lib locations to windows builds

This commit is contained in:
Adam Potolsky 2015-06-10 13:18:39 -07:00
parent 8366bb6247
commit fa0dfa0ded
4 changed files with 66 additions and 1 deletions

View File

@ -56,4 +56,11 @@ public:
*/ */
virtual void setting(const std::string& valueName, const std::string& valueString) const = 0; 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;
//@}
}; };

View File

@ -23,6 +23,9 @@
#include "tchar.h" #include "tchar.h"
#include <string> #include <string>
#include <windows.h>
#include <psapi.h>
static const char* s_settingsKeyNames[] = { static const char* s_settingsKeyNames[] = {
_T("SOFTWARE"), _T("SOFTWARE"),
_T("Synergy"), _T("Synergy"),
@ -152,3 +155,39 @@ ArchSystemWindows::isWOW64() const
#endif #endif
return false; 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;
}

View File

@ -33,6 +33,7 @@ public:
virtual std::string getPlatformName() const; virtual std::string getPlatformName() const;
virtual std::string setting(const std::string& valueName) const; virtual std::string setting(const std::string& valueName) const;
virtual void setting(const std::string& valueName, const std::string& valueString) const; virtual void setting(const std::string& valueName, const std::string& valueString) const;
virtual std::string getLibsUsed(void) const;
bool isWOW64() const; bool isWOW64() const;
}; };

View File

@ -23,6 +23,9 @@
#include "base/Log.h" #include "base/Log.h"
#include <iostream> #include <iostream>
#include <sstream>
#include <vector>
#include <iterator>
const char * kSynergyVers = VERSION; const char * kSynergyVers = VERSION;
SecureSocket* g_secureSocket = NULL; SecureSocket* g_secureSocket = NULL;
@ -30,8 +33,21 @@ SecureListenSocket* g_secureListenSocket = NULL;
Arch* g_arch = NULL; Arch* g_arch = NULL;
Log* g_log = 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 void
init(void* log, void* arch) init(void* log, void* arch)
{ {
@ -42,6 +58,8 @@ init(void* log, void* arch)
if (g_arch == NULL) { if (g_arch == NULL) {
Arch::setInstance(reinterpret_cast<Arch*>(arch)); Arch::setInstance(reinterpret_cast<Arch*>(arch));
} }
LOG(( CLOG_DEBUG "%s",helperGetLibsUsed().c_str()));
} }
int int