mirror of
https://github.com/pbatard/rufus.git
synced 2024-08-14 23:57:05 +00:00
[process] check for volumes open with executable access rights
* This allows us to properly identify an open command prompt as a blocking process * Also, since FSCTL_LOCK_VOLUME is slow, switch to using an actual timeout
This commit is contained in:
parent
f53b22a077
commit
7ec8db5602
3 changed files with 17 additions and 13 deletions
|
@ -121,7 +121,7 @@ static HANDLE GetHandle(char* Path, BOOL bLockDrive, BOOL bWriteAccess, BOOL bWr
|
|||
{
|
||||
int i;
|
||||
BOOL bSearchProcess = FALSE;
|
||||
DWORD size;
|
||||
DWORD size, EndTime;
|
||||
HANDLE hDrive = INVALID_HANDLE_VALUE;
|
||||
char DevPath[MAX_PATH];
|
||||
|
||||
|
@ -172,13 +172,14 @@ static HANDLE GetHandle(char* Path, BOOL bLockDrive, BOOL bWriteAccess, BOOL bWr
|
|||
}
|
||||
|
||||
uprintf("Requesting lock...");
|
||||
for (i = 0; i < DRIVE_ACCESS_RETRIES; i++) {
|
||||
EndTime = GetTickCount() + DRIVE_ACCESS_TIMEOUT;
|
||||
do {
|
||||
if (DeviceIoControl(hDrive, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &size, NULL))
|
||||
goto out;
|
||||
if (IS_ERROR(FormatStatus)) // User cancel
|
||||
break;
|
||||
Sleep(DRIVE_ACCESS_TIMEOUT/DRIVE_ACCESS_RETRIES);
|
||||
}
|
||||
Sleep(DRIVE_ACCESS_TIMEOUT / DRIVE_ACCESS_RETRIES);
|
||||
} while (GetTickCount() < EndTime);
|
||||
// If we reached this section, either we didn't manage to get a lock or the user cancelled
|
||||
uprintf("Could not lock access to %s: %s", Path, WindowsErrorString());
|
||||
// See if we can tell the user what processes are accessing the drive
|
||||
|
|
|
@ -398,7 +398,7 @@ NTSTATUS PhQueryProcessesUsingVolumeOrFile(HANDLE VolumeOrFileHandle,
|
|||
*/
|
||||
BOOL SearchProcess(char* HandleName, BOOL bPartialMatch, BOOL bIgnoreSelf)
|
||||
{
|
||||
const char *access_rights_str[4] = { "n", "r", "w", "rw" };
|
||||
const char *access_rights_str[8] = { "n", "r", "w", "rw", "x", "rx", "wx", "rwx" };
|
||||
NTSTATUS status = STATUS_SUCCESS;
|
||||
PSYSTEM_HANDLE_INFORMATION_EX handles = NULL;
|
||||
POBJECT_NAME_INFORMATION buffer = NULL;
|
||||
|
@ -481,7 +481,7 @@ BOOL SearchProcess(char* HandleName, BOOL bPartialMatch, BOOL bIgnoreSelf)
|
|||
|
||||
// If we're switching process and found a match, print it
|
||||
if (bFound) {
|
||||
uprintf("o '%s' (pid: %ld, access: %s)", exe_path, pid[cur_pid], access_rights_str[access_rights & 0x3]);
|
||||
uprintf("o '%s' (pid: %ld, access: %s)", exe_path, pid[cur_pid], access_rights_str[access_rights & 0x7]);
|
||||
bFound = FALSE;
|
||||
access_rights = 0;
|
||||
}
|
||||
|
@ -504,8 +504,8 @@ BOOL SearchProcess(char* HandleName, BOOL bPartialMatch, BOOL bIgnoreSelf)
|
|||
if (handleInfo->UniqueProcessId == last_access_denied_pid)
|
||||
continue;
|
||||
|
||||
// Filter out handles that aren't opened with Read (bit 0) or Write (bit 1) access
|
||||
if ((handleInfo->GrantedAccess & 0x3) == 0)
|
||||
// Filter out handles that aren't opened with Read (bit 0), Write (bit 1) or Execute (bit 5) access
|
||||
if ((handleInfo->GrantedAccess & 0x23) == 0)
|
||||
continue;
|
||||
|
||||
// Open the process to which the handle we are after belongs, if not already opened
|
||||
|
@ -578,6 +578,9 @@ BOOL SearchProcess(char* HandleName, BOOL bPartialMatch, BOOL bIgnoreSelf)
|
|||
|
||||
// Keep a mask of all the access rights being used
|
||||
access_rights |= handleInfo->GrantedAccess;
|
||||
// The Executable bit is in a place we don't like => reposition it
|
||||
if (access_rights & 0x20)
|
||||
access_rights = (access_rights & 0x3) | 0x4;
|
||||
|
||||
// If this is the very first process we find, print a header
|
||||
if (exe_path[0] == 0)
|
||||
|
|
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.1109"
|
||||
CAPTION "Rufus 2.15.1110"
|
||||
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,1109,0
|
||||
PRODUCTVERSION 2,15,1109,0
|
||||
FILEVERSION 2,15,1110,0
|
||||
PRODUCTVERSION 2,15,1110,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.1109"
|
||||
VALUE "FileVersion", "2.15.1110"
|
||||
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.1109"
|
||||
VALUE "ProductVersion", "2.15.1110"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
|
Loading…
Reference in a new issue