1 |
|
---|
2 | #include <stdio.h>
|
---|
3 | #include <Windows.h>
|
---|
4 |
|
---|
5 | typedef enum _FILE_INFORMATION_CLASS {
|
---|
6 | FileDirectoryInformation = 1,
|
---|
7 | FileFullDirectoryInformation, // 2
|
---|
8 | FileBothDirectoryInformation, // 3
|
---|
9 | FileBasicInformation, // 4 wdm
|
---|
10 | FileStandardInformation, // 5 wdm
|
---|
11 | FileInternalInformation, // 6
|
---|
12 | FileEaInformation, // 7
|
---|
13 | FileAccessInformation, // 8
|
---|
14 | FileNameInformation, // 9
|
---|
15 | FileRenameInformation, // 10
|
---|
16 | FileLinkInformation, // 11
|
---|
17 | FileNamesInformation, // 12
|
---|
18 | FileDispositionInformation, // 13
|
---|
19 | FilePositionInformation, // 14 wdm
|
---|
20 | FileFullEaInformation, // 15
|
---|
21 | FileModeInformation, // 16
|
---|
22 | FileAlignmentInformation, // 17
|
---|
23 | FileAllInformation, // 18
|
---|
24 | FileAllocationInformation, // 19
|
---|
25 | FileEndOfFileInformation, // 20 wdm
|
---|
26 | FileAlternateNameInformation, // 21
|
---|
27 | FileStreamInformation, // 22
|
---|
28 | FilePipeInformation, // 23
|
---|
29 | FilePipeLocalInformation, // 24
|
---|
30 | FilePipeRemoteInformation, // 25
|
---|
31 | FileMailslotQueryInformation, // 26
|
---|
32 | FileMailslotSetInformation, // 27
|
---|
33 | FileCompressionInformation, // 28
|
---|
34 | FileObjectIdInformation, // 29
|
---|
35 | FileCompletionInformation, // 30
|
---|
36 | FileMoveClusterInformation, // 31
|
---|
37 | FileQuotaInformation, // 32
|
---|
38 | FileReparsePointInformation, // 33
|
---|
39 | FileNetworkOpenInformation, // 34
|
---|
40 | FileAttributeTagInformation, // 35
|
---|
41 | FileTrackingInformation, // 36
|
---|
42 | FileIdBothDirectoryInformation, // 37
|
---|
43 | FileIdFullDirectoryInformation, // 38
|
---|
44 | FileMaximumInformation
|
---|
45 | } FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
|
---|
46 |
|
---|
47 | typedef struct _FILE_NAME_INFORMATION
|
---|
48 | {
|
---|
49 | ULONG FileNameLength;
|
---|
50 | WCHAR FileName[1];
|
---|
51 | } FILE_NAME_INFORMATION, *PFILE_NAME_INFORMATION;
|
---|
52 |
|
---|
53 | typedef LONG NTSTATUS;
|
---|
54 |
|
---|
55 | typedef struct _IO_STATUS_BLOCK
|
---|
56 | {
|
---|
57 | union
|
---|
58 | {
|
---|
59 | NTSTATUS Status;
|
---|
60 | PVOID Pointer;
|
---|
61 | };
|
---|
62 | ULONG_PTR Information;
|
---|
63 | } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
|
---|
64 |
|
---|
65 | NTSYSAPI
|
---|
66 | NTSTATUS
|
---|
67 | NTAPI
|
---|
68 | NtQueryInformationFile(HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FileInformation,
|
---|
69 | ULONG Length, FILE_INFORMATION_CLASS FileInformationClass);
|
---|
70 |
|
---|
71 |
|
---|
72 |
|
---|
73 | int main(int argc, char **argv)
|
---|
74 | {
|
---|
75 | int rc = 0;
|
---|
76 | int i;
|
---|
77 |
|
---|
78 | NTSTATUS (NTAPI *pfnNtQueryInformationFile)(HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FileInformation,
|
---|
79 | ULONG Length, FILE_INFORMATION_CLASS FileInformationClass);
|
---|
80 |
|
---|
81 | pfnNtQueryInformationFile = GetProcAddress(LoadLibrary("ntdll.dll"), "NtQueryInformationFile");
|
---|
82 |
|
---|
83 | for (i = 1; i < argc; i++)
|
---|
84 | {
|
---|
85 | HANDLE hFile = CreateFile(argv[i],
|
---|
86 | GENERIC_READ,
|
---|
87 | FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
---|
88 | NULL,
|
---|
89 | OPEN_EXISTING,
|
---|
90 | FILE_FLAG_BACKUP_SEMANTICS,
|
---|
91 | NULL);
|
---|
92 | if (hFile)
|
---|
93 | {
|
---|
94 | long rcNt;
|
---|
95 | char abBuf[4096];
|
---|
96 | IO_STATUS_BLOCK Ios;
|
---|
97 |
|
---|
98 | memset(abBuf, 0, sizeof(abBuf));
|
---|
99 | memset(&Ios, 0, sizeof(Ios));
|
---|
100 | rcNt = pfnNtQueryInformationFile(hFile, &Ios, abBuf, sizeof(abBuf), FileNameInformation);
|
---|
101 | if (rcNt >= 0)
|
---|
102 | {
|
---|
103 | PFILE_NAME_INFORMATION pFileNameInfo = (PFILE_NAME_INFORMATION)abBuf;
|
---|
104 | printf("#%d: %s - rcNt=%#x - FileNameInformation:\n"
|
---|
105 | " FileName: %ls\n"
|
---|
106 | " FileNameLength: %lu\n",
|
---|
107 | i, argv[i], rcNt,
|
---|
108 | pFileNameInfo->FileName,
|
---|
109 | pFileNameInfo->FileNameLength
|
---|
110 | );
|
---|
111 | }
|
---|
112 | else
|
---|
113 | printf("#%d: %s - rcNt=%#x - FileNameInformation!\n", i, argv[i], rcNt);
|
---|
114 |
|
---|
115 | CloseHandle(hFile);
|
---|
116 | }
|
---|
117 | else
|
---|
118 | {
|
---|
119 | printf("#%d: %s - open failed, last error %d\n", i, argv[i], GetLastError());
|
---|
120 | rc = 1;
|
---|
121 | }
|
---|
122 | }
|
---|
123 | return rc;
|
---|
124 | }
|
---|