Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: installer/src/installer-lib/process.cpp

Issue 6003395731128320: Only take into account processes that have our plugin loaded (Closed)
Patch Set: Addressing comments Created March 28, 2014, 12:45 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « installer/src/installer-lib/process.h ('k') | installer/src/installer-lib/test/process_test.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: installer/src/installer-lib/process.cpp
===================================================================
--- a/installer/src/installer-lib/process.cpp
+++ b/installer/src/installer-lib/process.cpp
@@ -31,7 +31,11 @@
{
if ( handle == INVALID_HANDLE_VALUE )
{
- throw std::runtime_error( "Invalid handle" ) ;
+ // TODO: This code really deserves use of a proper exception class that packages
+ // Windows API errors consistently.
+ char tmp[256];
+ sprintf_s(tmp, "Invalid handle. Last error: %d", GetLastError());
+ throw std::runtime_error( tmp ) ;
}
}
@@ -47,12 +51,26 @@
return 0 == wcsncmpi( process.szExeFile, name, length ) ;
}
-//-------------------------------------------------------
-// process_by_any_exe_name_CI
-//-------------------------------------------------------
-bool process_by_any_exe_name_CI::operator()( const PROCESSENTRY32W & process )
+
+bool process_by_any_exe_with_any_module::operator()( const PROCESSENTRY32W & process )
{
- return names.find( process.szExeFile ) != names.end() ;
+ if (processNames.find(process.szExeFile) != processNames.end())
+ {
+ if (moduleNames.empty())
+ return true;
+
+ ModulesSnapshot ms(process.th32ProcessID);
+ ModulesSnapshot::Pointer me = ms.begin();
+ while (me != ms.end())
+ {
+ if (moduleNames.find(me->szModule) != moduleNames.end())
+ {
+ return true;
+ }
+ me = ms.next();
+ }
+ }
+ return false;
}
//-------------------------------------------------------
@@ -162,6 +180,26 @@
//-------------------------------------------------------
+// ModulesSnapshot
+//-------------------------------------------------------
+ModulesSnapshot::ModulesSnapshot(DWORD processId)
+ : handle(::CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, processId))
+{
+ module.dwSize = sizeof(MODULEENTRY32);
+}
+
+MODULEENTRY32W * ModulesSnapshot::begin()
+{
+ return ::Module32FirstW(handle, &module) ? (&module) : 0;
+}
+
+MODULEENTRY32W * ModulesSnapshot::next()
+{
+ return ::Module32NextW(handle, &module) ? (&module) : 0;
+}
+
+
+//-------------------------------------------------------
// send_message, send_endsession_messages
//-------------------------------------------------------
/**
« no previous file with comments | « installer/src/installer-lib/process.h ('k') | installer/src/installer-lib/test/process_test.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld