mirror of
				https://github.com/pbatard/rufus.git
				synced 2024-08-14 23:57:05 +00:00 
			
		
		
		
	[process] restrict search to handles that have R or W access
* Also fix loop overflow
This commit is contained in:
		
							parent
							
								
									d1927ac1ef
								
							
						
					
					
						commit
						0c76dbf075
					
				
					 9 changed files with 39 additions and 31 deletions
				
			
		|  | @ -208,9 +208,9 @@ | |||
|     <ClCompile Include="..\net.c" /> | ||||
|     <ClCompile Include="..\parser.c" /> | ||||
|     <ClCompile Include="..\pki.c" /> | ||||
|     <ClCompile Include="..\process.c" /> | ||||
|     <ClCompile Include="..\rufus.c" /> | ||||
|     <ClCompile Include="..\checksum.c" /> | ||||
|     <ClCompile Include="..\search.c" /> | ||||
|     <ClCompile Include="..\smart.c" /> | ||||
|     <ClCompile Include="..\stdfn.c" /> | ||||
|     <ClCompile Include="..\stdio.c" /> | ||||
|  | @ -226,7 +226,7 @@ | |||
|     <ClInclude Include="..\format.h" /> | ||||
|     <ClInclude Include="..\hdd_vs_ufd.h" /> | ||||
|     <ClInclude Include="..\missing.h" /> | ||||
|     <ClInclude Include="..\search.h" /> | ||||
|     <ClInclude Include="..\process.h" /> | ||||
|     <ClInclude Include="..\settings.h" /> | ||||
|     <ClInclude Include="..\libcdio\cdio\cdio.h" /> | ||||
|     <ClInclude Include="..\libcdio\cdio\iso9660.h" /> | ||||
|  |  | |||
|  | @ -75,7 +75,7 @@ | |||
|     <ClCompile Include="..\dev.c"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\search.c"> | ||||
|     <ClCompile Include="..\process.c"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|   </ItemGroup> | ||||
|  | @ -146,7 +146,7 @@ | |||
|     <ClInclude Include="..\db.h"> | ||||
|       <Filter>Header Files</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\search.h"> | ||||
|     <ClInclude Include="..\process.h"> | ||||
|       <Filter>Header Files</Filter> | ||||
|     </ClInclude> | ||||
|   </ItemGroup> | ||||
|  |  | |||
|  | @ -191,9 +191,9 @@ | |||
|     <ClCompile Include="..\net.c" /> | ||||
|     <ClCompile Include="..\parser.c" /> | ||||
|     <ClCompile Include="..\pki.c" /> | ||||
|     <ClCompile Include="..\process.c" /> | ||||
|     <ClCompile Include="..\rufus.c" /> | ||||
|     <ClCompile Include="..\checksum.c" /> | ||||
|     <ClCompile Include="..\search.c" /> | ||||
|     <ClCompile Include="..\smart.c" /> | ||||
|     <ClCompile Include="..\stdfn.c" /> | ||||
|     <ClCompile Include="..\stdio.c" /> | ||||
|  | @ -209,7 +209,7 @@ | |||
|     <ClInclude Include="..\format.h" /> | ||||
|     <ClInclude Include="..\hdd_vs_ufd.h" /> | ||||
|     <ClInclude Include="..\missing.h" /> | ||||
|     <ClInclude Include="..\search.h" /> | ||||
|     <ClInclude Include="..\process.h" /> | ||||
|     <ClInclude Include="..\settings.h" /> | ||||
|     <ClInclude Include="..\libcdio\cdio\cdio.h" /> | ||||
|     <ClInclude Include="..\libcdio\cdio\iso9660.h" /> | ||||
|  |  | |||
|  | @ -75,7 +75,7 @@ | |||
|     <ClCompile Include="..\dev.c"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\search.c"> | ||||
|     <ClCompile Include="..\process.c"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|   </ItemGroup> | ||||
|  | @ -146,7 +146,7 @@ | |||
|     <ClInclude Include="..\db.h"> | ||||
|       <Filter>Header Files</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\search.h"> | ||||
|     <ClInclude Include="..\process.h"> | ||||
|       <Filter>Header Files</Filter> | ||||
|     </ClInclude> | ||||
|   </ItemGroup> | ||||
|  |  | |||
|  | @ -11,7 +11,7 @@ AM_V_WINDRES   = $(AM_V_WINDRES_$(V)) | |||
| 	$(AM_V_WINDRES) $(AM_RCFLAGS) -i $< -o $@ | ||||
| 
 | ||||
| rufus_SOURCES = badblocks.c checksum.c dev.c dos.c dos_locale.c drive.c format.c icon.c iso.c localization.c \ | ||||
| 	net.c parser.c pki.c rufus.c search.c smart.c stdfn.c stdio.c stdlg.c syslinux.c vhd.c | ||||
| 	net.c parser.c pki.c process.c rufus.c smart.c stdfn.c stdio.c stdlg.c syslinux.c vhd.c | ||||
| rufus_CFLAGS = -I./ms-sys/inc -I./syslinux/libfat -I./syslinux/libinstaller -I./syslinux/win -I./libcdio $(AM_CFLAGS) | ||||
| rufus_LDFLAGS = $(AM_LDFLAGS) -mwindows | ||||
| rufus_LDADD = rufus_rc.o bled/libbled.a ms-sys/libmssys.a syslinux/libfat/libfat.a syslinux/libinstaller/libinstaller.a syslinux/win/libwin.a \ | ||||
|  |  | |||
|  | @ -93,7 +93,7 @@ am_rufus_OBJECTS = rufus-badblocks.$(OBJEXT) rufus-checksum.$(OBJEXT) \ | |||
| 	rufus-format.$(OBJEXT) rufus-icon.$(OBJEXT) \
 | ||||
| 	rufus-iso.$(OBJEXT) rufus-localization.$(OBJEXT) \
 | ||||
| 	rufus-net.$(OBJEXT) rufus-parser.$(OBJEXT) rufus-pki.$(OBJEXT) \
 | ||||
| 	rufus-rufus.$(OBJEXT) rufus-search.$(OBJEXT) \
 | ||||
| 	rufus-process.$(OBJEXT) rufus-rufus.$(OBJEXT) \
 | ||||
| 	rufus-smart.$(OBJEXT) rufus-stdfn.$(OBJEXT) \
 | ||||
| 	rufus-stdio.$(OBJEXT) rufus-stdlg.$(OBJEXT) \
 | ||||
| 	rufus-syslinux.$(OBJEXT) rufus-vhd.$(OBJEXT) | ||||
|  | @ -271,7 +271,7 @@ AM_V_WINDRES_1 = $(WINDRES) | |||
| AM_V_WINDRES_ = $(AM_V_WINDRES_$(AM_DEFAULT_VERBOSITY)) | ||||
| AM_V_WINDRES = $(AM_V_WINDRES_$(V)) | ||||
| rufus_SOURCES = badblocks.c checksum.c dev.c dos.c dos_locale.c drive.c format.c icon.c iso.c localization.c \
 | ||||
| 	net.c parser.c pki.c rufus.c search.c smart.c stdfn.c stdio.c stdlg.c syslinux.c vhd.c | ||||
| 	net.c parser.c pki.c process.c rufus.c smart.c stdfn.c stdio.c stdlg.c syslinux.c vhd.c | ||||
| 
 | ||||
| rufus_CFLAGS = -I./ms-sys/inc -I./syslinux/libfat -I./syslinux/libinstaller -I./syslinux/win -I./libcdio $(AM_CFLAGS) | ||||
| rufus_LDFLAGS = $(AM_LDFLAGS) -mwindows | ||||
|  | @ -410,18 +410,18 @@ rufus-pki.o: pki.c | |||
| rufus-pki.obj: pki.c | ||||
| 	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-pki.obj `if test -f 'pki.c'; then $(CYGPATH_W) 'pki.c'; else $(CYGPATH_W) '$(srcdir)/pki.c'; fi` | ||||
| 
 | ||||
| rufus-process.o: process.c | ||||
| 	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-process.o `test -f 'process.c' || echo '$(srcdir)/'`process.c | ||||
| 
 | ||||
| rufus-process.obj: process.c | ||||
| 	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-process.obj `if test -f 'process.c'; then $(CYGPATH_W) 'process.c'; else $(CYGPATH_W) '$(srcdir)/process.c'; fi` | ||||
| 
 | ||||
| rufus-rufus.o: rufus.c | ||||
| 	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-rufus.o `test -f 'rufus.c' || echo '$(srcdir)/'`rufus.c | ||||
| 
 | ||||
| rufus-rufus.obj: rufus.c | ||||
| 	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-rufus.obj `if test -f 'rufus.c'; then $(CYGPATH_W) 'rufus.c'; else $(CYGPATH_W) '$(srcdir)/rufus.c'; fi` | ||||
| 
 | ||||
| rufus-search.o: search.c | ||||
| 	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-search.o `test -f 'search.c' || echo '$(srcdir)/'`search.c | ||||
| 
 | ||||
| rufus-search.obj: search.c | ||||
| 	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-search.obj `if test -f 'search.c'; then $(CYGPATH_W) 'search.c'; else $(CYGPATH_W) '$(srcdir)/search.c'; fi` | ||||
| 
 | ||||
| rufus-smart.o: smart.c | ||||
| 	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(rufus_CFLAGS) $(CFLAGS) -c -o rufus-smart.o `test -f 'smart.c' || echo '$(srcdir)/'`smart.c | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| /*
 | ||||
|  * Rufus: The Reliable USB Formatting Utility | ||||
|  * Search functionality for handles | ||||
|  * Process search functionality | ||||
|  * | ||||
|  * Modified from Process Hacker: | ||||
|  *   https://github.com/processhacker2/processhacker2/
 | ||||
|  | @ -30,7 +30,7 @@ | |||
| #include <windows.h> | ||||
| 
 | ||||
| #include "rufus.h" | ||||
| #include "search.h" | ||||
| #include "process.h" | ||||
| #include "missing.h" | ||||
| #include "msapi_utf8.h" | ||||
| 
 | ||||
|  | @ -405,7 +405,8 @@ BOOL SearchProcess(char* HandleName, BOOL bPartialMatch, BOOL bIgnoreSelf) | |||
| 
 | ||||
| 	for (i = 0; ; i++) { | ||||
| 		ULONG attempts = 8; | ||||
| 		PSYSTEM_HANDLE_TABLE_ENTRY_INFO_EX handleInfo = &handles->Handles[i]; | ||||
| 		PSYSTEM_HANDLE_TABLE_ENTRY_INFO_EX handleInfo = | ||||
| 			(i < handles->NumberOfHandles) ? &handles->Handles[i] : NULL; | ||||
| 
 | ||||
| 		if ((dupHandle != NULL) && (processHandle != NtCurrentProcess())) { | ||||
| 			pfNtClose(dupHandle); | ||||
|  | @ -414,12 +415,14 @@ BOOL SearchProcess(char* HandleName, BOOL bPartialMatch, BOOL bIgnoreSelf) | |||
| 
 | ||||
| #ifdef USE_OBJECT_TYPES | ||||
| 		// Only look for File objects type
 | ||||
| 		if ((fileObjectTypeIndex >= 0 ) && (handleInfo->ObjectTypeIndex != (USHORT)fileObjectTypeIndex)) | ||||
| 		if ((fileObjectTypeIndex >= 0 ) && (handleInfo != NULL) && | ||||
| 			(handleInfo->ObjectTypeIndex != (USHORT)fileObjectTypeIndex)) | ||||
| 			continue; | ||||
| #endif | ||||
| 
 | ||||
| 		// Update the current handle's process PID and compare against last
 | ||||
| 		pid[cur_pid] = handleInfo->UniqueProcessId; | ||||
| 		// Note: Be careful about not trying to overflow our list!
 | ||||
| 		pid[cur_pid] = (handleInfo != NULL) ? handleInfo->UniqueProcessId : -1; | ||||
| 
 | ||||
| 		if (pid[0] != pid[1]) { | ||||
| 			cur_pid = (cur_pid + 1) % 2; | ||||
|  | @ -433,13 +436,17 @@ BOOL SearchProcess(char* HandleName, BOOL bPartialMatch, BOOL bIgnoreSelf) | |||
| 
 | ||||
| 		CHECK_FOR_USER_CANCEL; | ||||
| 
 | ||||
| 		// Exit loop condition
 | ||||
| 		if (i >= handles->NumberOfHandles) | ||||
| 			break; | ||||
| 
 | ||||
| 		// Don't bother with processes we can't access
 | ||||
| 		if (handleInfo->UniqueProcessId == last_access_denied_pid) | ||||
| 			continue; | ||||
| 
 | ||||
| 		// Exit loop condition
 | ||||
| 		if (i >= handles->NumberOfHandles) | ||||
| 			break; | ||||
| 		// Filter out handles that aren't opened with Read (bit 0) or Write (bit 1) access
 | ||||
| 		if ((handleInfo->GrantedAccess & 0x3) == 0) | ||||
| 			continue; | ||||
| 
 | ||||
| 		// Open the process to which the handle we are after belongs, if not already opened
 | ||||
| 		if (pid[0] != pid[1]) { | ||||
|  | @ -476,6 +483,7 @@ BOOL SearchProcess(char* HandleName, BOOL bPartialMatch, BOOL bIgnoreSelf) | |||
| 		// A loop is needed because the I/O subsystem likes to give us the wrong return lengths...
 | ||||
| 		do { | ||||
| 			ULONG returnSize; | ||||
| 			// TODO: We might still need a timeout on ObjectName queries, as PH does...
 | ||||
| 			status = pfNtQueryObject(dupHandle, ObjectNameInformation, buffer, bufferSize, &returnSize); | ||||
| 			if (status == STATUS_BUFFER_OVERFLOW || status == STATUS_INFO_LENGTH_MISMATCH || | ||||
| 				status == STATUS_BUFFER_TOO_SMALL) { | ||||
|  | @ -1,6 +1,6 @@ | |||
| /*
 | ||||
|  * Rufus: The Reliable USB Formatting Utility | ||||
|  * Search functionality for handles | ||||
|  * Process search functionality | ||||
|  * | ||||
|  * Modified from Process Hacker: | ||||
|  *   https://github.com/processhacker2/processhacker2/
 | ||||
							
								
								
									
										10
									
								
								src/rufus.rc
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								src/rufus.rc
									
										
									
									
									
								
							|  | @ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL | |||
| IDD_DIALOG DIALOGEX 12, 12, 242, 376 | ||||
| STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | ||||
| EXSTYLE WS_EX_ACCEPTFILES | ||||
| CAPTION "Rufus 2.15.1097" | ||||
| CAPTION "Rufus 2.15.1098" | ||||
| FONT 8, "Segoe UI Symbol", 400, 0, 0x0 | ||||
| BEGIN | ||||
|     LTEXT           "Device",IDS_DEVICE_TXT,9,6,200,8 | ||||
|  | @ -334,8 +334,8 @@ END | |||
| // | ||||
| 
 | ||||
| VS_VERSION_INFO VERSIONINFO | ||||
|  FILEVERSION 2,15,1097,0 | ||||
|  PRODUCTVERSION 2,15,1097,0 | ||||
|  FILEVERSION 2,15,1098,0 | ||||
|  PRODUCTVERSION 2,15,1098,0 | ||||
|  FILEFLAGSMASK 0x3fL | ||||
| #ifdef _DEBUG | ||||
|  FILEFLAGS 0x1L | ||||
|  | @ -352,13 +352,13 @@ BEGIN | |||
|         BEGIN | ||||
|             VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" | ||||
|             VALUE "FileDescription", "Rufus" | ||||
|             VALUE "FileVersion", "2.15.1097" | ||||
|             VALUE "FileVersion", "2.15.1098" | ||||
|             VALUE "InternalName", "Rufus" | ||||
|             VALUE "LegalCopyright", "© 2011-2017 Pete Batard (GPL v3)" | ||||
|             VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" | ||||
|             VALUE "OriginalFilename", "rufus.exe" | ||||
|             VALUE "ProductName", "Rufus" | ||||
|             VALUE "ProductVersion", "2.15.1097" | ||||
|             VALUE "ProductVersion", "2.15.1098" | ||||
|         END | ||||
|     END | ||||
|     BLOCK "VarFileInfo" | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue