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: Simplify Process_Closer constructor Created March 31, 2014, 8:31 a.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);
+ MODULEENTRY32W* me = ms.first();
+ while (me != NULL)
+ {
+ if (moduleNames.find(me->szModule) != moduleNames.end())
+ {
+ return true;
+ }
+ me = ms.next();
+ }
+ }
+ return false;
}
//-------------------------------------------------------
@@ -145,19 +163,39 @@
process.dwSize = sizeof( PROCESSENTRY32W ) ;
}
-PROCESSENTRY32W * Snapshot::begin()
+PROCESSENTRY32W * Snapshot::first()
{
- return ::Process32FirstW( handle, & process ) ? ( & process ) : 0 ;
+ return ::Process32FirstW(handle, &process) ? (&process) : 0;
}
PROCESSENTRY32W * Snapshot::next()
{
- return ::Process32NextW( handle, & process ) ? ( & process ) : 0 ;
+ return ::Process32NextW(handle, &process) ? (&process) : 0;
}
void Snapshot::refresh()
{
- handle = ::CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ) ;
+ handle = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
+}
+
+
+//-------------------------------------------------------
+// ModulesSnapshot
+//-------------------------------------------------------
+ModulesSnapshot::ModulesSnapshot(DWORD processId)
+ : handle(::CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, processId))
+{
+ module.dwSize = sizeof(MODULEENTRY32);
+}
+
+MODULEENTRY32W * ModulesSnapshot::first()
+{
+ return ::Module32FirstW(handle, &module) ? (&module) : 0;
+}
+
+MODULEENTRY32W * ModulesSnapshot::next()
+{
+ return ::Module32NextW(handle, &module) ? (&module) : 0;
}
« 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