-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcerrlook.c
40 lines (33 loc) · 1.1 KB
/
cerrlook.c
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
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main(int argc, char *argv[]) {
if (argc < 2) {
puts("usage: winerrlook [MODULE]... CODE");
return EXIT_SUCCESS;
}
unsigned int code = strtoul(argv[argc - 1], NULL, 0);
char *module_name = "<system>";
int modules = argc - 2;
char msg[65535] = {0};
DWORD res = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, HRESULT_CODE(code), 0,
msg, sizeof(msg), NULL);
for (int i = 0; i < modules && res == 0; i++) {
HMODULE hm = LoadLibraryA(argv[i + 1]);
module_name = argv[i + 1];
res =
FormatMessageA(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_FROM_SYSTEM,
hm, HRESULT_CODE(code), 0, msg, sizeof(msg), NULL);
FreeLibrary(hm);
}
if (!res) {
printf("Can't get message for code '%s': 0x%08X\n", argv[argc - 1],
GetLastError());
return EXIT_FAILURE;
}
printf("Dec:\t%d\n", code);
printf("Hex:\t0x%08X\n", code);
printf("Module:\t%s\n", module_name);
printf("Text:\t%s\n", msg);
return EXIT_SUCCESS;
}