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: Changes for x64 custom action and addressing comments Created March 27, 2014, 11:22 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
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(tmp, "Invalid handle. Last error: %d", GetLastError());
Wladimir Palant 2014/03/28 07:30:17 sprintf() is deprecated, please use sprintf_s() in
+ throw std::runtime_error( tmp ) ;
}
}
@@ -47,12 +51,29 @@
return 0 == wcsncmpi( process.szExeFile, name, length ) ;
}
+
//-------------------------------------------------------
-// process_by_any_exe_name_CI
+// process_by_any_exe_with_any_module
//-------------------------------------------------------
Wladimir Palant 2014/03/28 07:30:17 I guess I am missing the point of having of this c
-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 );
+ MODULEENTRY32* me = ms.begin();
+ while ( me != ms.end() )
+ {
+ if (moduleNames.find( me->szModule ) != moduleNames.end())
+ {
+ return true;
+ }
+ me = ms.next();
+ }
Wladimir Palant 2014/03/28 07:30:17 Nit: Please use spaces for indentation.
+ }
+ return false;
}
//-------------------------------------------------------
@@ -162,6 +183,26 @@
//-------------------------------------------------------
+// ModulesSnapshot
+//-------------------------------------------------------
+ModulesSnapshot::ModulesSnapshot(DWORD processId)
+ : handle( ::CreateToolhelp32Snapshot( TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, processId ) )
Wladimir Palant 2014/03/28 07:30:17 Style nit: That's rather unusual style in this fil
+{
+ module.dwSize = sizeof( MODULEENTRY32 ) ;
+}
+
+MODULEENTRY32W * ModulesSnapshot::begin()
+{
+ return ::Module32FirstW( handle, & module ) ? ( & module ) : 0 ;
+}
+
+MODULEENTRY32W * ModulesSnapshot::next()
+{
+ return ::Module32NextW( handle, & module ) ? ( & module ) : 0 ;
+}
Wladimir Palant 2014/03/28 07:30:17 This fakes a C++ iterator interface but does so in
Eric 2014/03/28 12:06:00 Yep. It really ought be a proper iterator class, b
Oleksandr 2014/03/28 12:48:35 I actually like the way it is implemented. The ite
Wladimir Palant 2014/03/28 13:55:24 This is simply misleading, one looks at the loop a
Oleksandr 2014/03/28 14:28:16 Fixed in Patchset 4 On 2014/03/28 13:55:24, Wladim
+
+
+//-------------------------------------------------------
// send_message, send_endsession_messages
//-------------------------------------------------------
/**

Powered by Google App Engine
This is Rietveld