HardwareDevices: Add PhGetProcessDeviceMap
#include "devices.h"
#include <ntdddisk.h>
-ULONG DiskDriveQueryDeviceMap(
- VOID
- )
-{
-#ifndef _WIN64
- PROCESS_DEVICEMAP_INFORMATION deviceMapInfo;
-#else
- PROCESS_DEVICEMAP_INFORMATION_EX deviceMapInfo;
-#endif
-
- memset(&deviceMapInfo, 0, sizeof(deviceMapInfo));
-
- NtQueryInformationProcess(
- NtCurrentProcess(),
- ProcessDeviceMap,
- &deviceMapInfo,
- sizeof(deviceMapInfo),
- NULL
- );
-
- return deviceMapInfo.Query.DriveMap;
-}
-
PPH_STRING DiskDriveQueryDosMountPoints(
_In_ ULONG DeviceNumber
)
{
- ULONG driveMask;
+ ULONG deviceMap = 0;
WCHAR deviceNameBuffer[7] = L"\\??\\?:";
PH_STRING_BUILDER stringBuilder;
PhInitializeStringBuilder(&stringBuilder, DOS_MAX_PATH_LENGTH);
- driveMask = DiskDriveQueryDeviceMap();
+ PhGetProcessDeviceMap(NtCurrentProcess(), &deviceMap);
- // NOTE: This isn't the best way of doing this but it works.
+ // This isn't the best way of doing this but it works. (dmex)
for (INT i = 0; i < 0x1A; i++)
- {
- if (driveMask & (0x1 << i))
{
HANDLE deviceHandle;
+ if (deviceMap)
+ {
+ if (!(deviceMap & (0x1 << i)))
+ continue;
+ }
+
deviceNameBuffer[4] = (WCHAR)('A' + i);
if (NT_SUCCESS(PhCreateFile(
@@ -99,7 +80,6 @@ PPH_STRING DiskDriveQueryDosMountPoints(
NtClose(deviceHandle);
}
}
- }
if (stringBuilder.String->Length != 0)
PhRemoveEndStringBuilder(&stringBuilder, 1);
@@ -111,19 +91,24 @@ PPH_LIST DiskDriveQueryMountPointHandles(
_In_ ULONG DeviceNumber
)
{
- ULONG driveMask;
+ ULONG deviceMap = 0;
PPH_LIST deviceList;
WCHAR deviceNameBuffer[7] = L"\\??\\?:";
- driveMask = DiskDriveQueryDeviceMap();
+ PhGetProcessDeviceMap(NtCurrentProcess(), &deviceMap);
+
deviceList = PhCreateList(2);
for (INT i = 0; i < 26; i++)
- {
- if (driveMask & (1 << i))
{
HANDLE deviceHandle;
+ if (deviceMap)
+ {
+ if (!(deviceMap & (0x1 << i)))
+ continue;
+ }
+
deviceNameBuffer[4] = (WCHAR)('A' + i);
if (NT_SUCCESS(PhCreateFile(
@@ -139,6 +124,9 @@ PPH_LIST DiskDriveQueryMountPointHandles(
ULONG deviceNumber = ULONG_MAX; // Note: Do not initialize to zero.
DEVICE_TYPE deviceType = 0;
+ DiskDriveQueryDeviceInformation(
+ deviceHandle, NULL, NULL, NULL, NULL);
+
if (NT_SUCCESS(DiskDriveQueryDeviceTypeAndNumber(
deviceHandle,
&deviceNumber,
@@ -162,7 +150,6 @@ PPH_LIST DiskDriveQueryMountPointHandles(
}
}
}
- }
return deviceList;
}
