#include <Windows.h>
|
#include <winternl.h>
|
#include <cstdio>
|
|
typedef enum {
|
FileFsVolumeInformation = 1,
|
FileFsLabelInformation = 2,
|
FileFsSizeInformation = 3,
|
FileFsDeviceInformation = 4,
|
FileFsAttributeInformation = 5,
|
FileFsControlInformation = 6,
|
FileFsFullSizeInformation = 7,
|
FileFsObjectIdInformation = 8,
|
FileFsDriverPathInformation = 9,
|
FileFsVolumeFlagsInformation = 10,
|
FileFsSectorSizeInformation = 11
|
} FS_INFORMATION_CLASS;
|
|
extern "C"
|
NTSTATUS WINAPI NtQueryVolumeInformationFile(
|
_In_ HANDLE FileHandle,
|
_Out_ PIO_STATUS_BLOCK IoStatusBlock,
|
_Out_ PVOID FsInformation,
|
_In_ ULONG Length,
|
_In_ FS_INFORMATION_CLASS FsInformationClass
|
);
|
|
VOID PrintHex(PBYTE Data, ULONG dwBytes) {
|
for (ULONG i = 0; i < dwBytes; i += 16) {
|
printf("%.8x: ", i);
|
|
for (ULONG j = 0; j < 16; j++) {
|
if (i + j < dwBytes) {
|
printf("%.2x ", Data[i + j]);
|
}
|
else {
|
printf("?? ");
|
}
|
}
|
|
for (ULONG j = 0; j < 16; j++) {
|
if (i + j < dwBytes && Data[i + j] >= 0x20 && Data[i + j] <= 0x7e) {
|
printf("%c", Data[i + j]);
|
}
|
else {
|
printf(".");
|
}
|
}
|
|
printf("\n");
|
}
|
}
|
|
int main() {
|
// Open the disk device.
|
HANDLE hDisk = CreateFile(L"C:\\", 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
if (hDisk == INVALID_HANDLE_VALUE) {
|
printf("CreateFile failed, %d\n", GetLastError());
|
return 1;
|
}
|
|
// Obtain the output data, assuming that it will fit into 256 bytes.
|
BYTE output[256];
|
IO_STATUS_BLOCK iosb;
|
NTSTATUS st = NtQueryVolumeInformationFile(hDisk, &iosb, output, sizeof(output), FileFsVolumeInformation);
|
if (!NT_SUCCESS(st)) {
|
printf("NtQueryVolumeInformationFile failed, %x\n", st);
|
CloseHandle(hDisk);
|
return 1;
|
}
|
|
// Dump the output data on screen and free resources.
|
PrintHex(output, iosb.Information);
|
CloseHandle(hDisk);
|
|
return 0;
|
}
|