-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathxorsum.cpp
More file actions
69 lines (56 loc) · 1.55 KB
/
Copy pathxorsum.cpp
File metadata and controls
69 lines (56 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#define WIN32_LEAN_AND_MEAN
#include <winstrct.h>
#include <wfind.h>
#include "chkfile.h"
#if defined(_DLL) && defined(_M_IX86)
#pragma comment(lib, "minwcrt.lib")
#endif
int main(int, char **argv)
{
char buf[MAX_PATH * 2];
while ((++argv)[0])
{
if (strlen(argv[0]) >= sizeof buf)
{
fprintf(stderr, "Path too long: %s\n", argv[0]);
continue;
}
strcpy(buf, argv[0]);
char *filepart = strchr(buf, '\\');
if (filepart == NULL)
filepart = strchr(buf, '/');
if (filepart == NULL)
filepart = buf;
else
++filepart;
WFilteredFileFinder ff(argv[0], FILE_ATTRIBUTE_DIRECTORY);
if (!ff)
{
win_perror(argv[0]);
continue;
}
do
{
strncpy(filepart, ff.cFileName, sizeof(buf) - (filepart - buf));
buf[sizeof(buf) - 1] = 0;
HANDLE h = CreateFile(buf, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, NULL);
if (h == INVALID_HANDLE_VALUE)
{
win_perror(buf);
continue;
}
ULARGE_INTEGER Checksum;
BOOL Break = FALSE;
if (!GetFileCheckSum(h, 0, &Checksum, &Break))
{
win_perror(buf);
continue;
}
printf("%s - %.4X%.4X\n", buf,
Checksum.HighPart, Checksum.LowPart);
CloseHandle(h);
} while (ff.Next());
}
return 0;
}