-
Notifications
You must be signed in to change notification settings - Fork 31
/
DRV.c
97 lines (84 loc) · 1.99 KB
/
DRV.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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "VSTriage.h"
PWSTR pwszDrvBuf = NULL;
size_t stDrvBufSize;
BOOL DRVMain(void)
{
LPVOID* pDriversTable;
DWORD dwDriversTableSize;
DWORD dwDriverCount;
DWORD dwLastError;
BOOL bRes;
BOOL bSuccess = TRUE;
pDriversTable = NULL;
dwDriversTableSize = sizeof(LPVOID); //init 1, 0 changes the result.
while (TRUE)
{
DWORD dwRequiredTableSize;
if (pDriversTable)
{
LocalFree(pDriversTable);
}
pDriversTable = LocalAlloc(LPTR, dwDriversTableSize);
CRASHIFNULLALLOC(pDriversTable);
bRes = EnumDeviceDrivers(pDriversTable, dwDriversTableSize, &dwRequiredTableSize);
if (bRes)
{
if (dwDriversTableSize == dwRequiredTableSize)
{
break; //done
}
else
{
dwDriversTableSize = dwRequiredTableSize;
continue;
}
}
else
{
dwLastError = GetLastError();
REPORTERROR(L"EnumDeviceDrivers() failed ", dwLastError);
bSuccess = FALSE;
break;
}
}
if (0 == dwDriversTableSize)
{
return FALSE;
}
dwDriverCount = dwDriversTableSize / sizeof(LPVOID);
for (DWORD i = 0; i < dwDriverCount; i++)
{
TCHAR szDriver[MAX_PATH];
LPVOID pCurrentDriver = pDriversTable[i];
if (GetDeviceDriverFileNameW(pCurrentDriver, szDriver, ARRAYSIZE(szDriver)))
{
WCHAR wszDrivers[MAX_PATH] = {0};
StringCchPrintfW(wszDrivers, ARRAYSIZE(wszDrivers), L"%s\r\n", szDriver);
StringCchCatW(pwszDrvBuf, stDrvBufSize / sizeof(WCHAR), wszDrivers);
}
else
{
bSuccess = FALSE;
}
}
LocalFree(pDriversTable);
if (!bSuccess)
{
StringCchCatW(
pwszDrvBuf,
stDrvBufSize / sizeof(WCHAR),
L"(Results may be incomplete due to failed API calls.)\r\n");
}
return TRUE;
}
PWSTR DRV_Output(void)
{
wprintf(L"Listing Drivers\r\n");
stDrvBufSize = SIZE_16MB;
pwszDrvBuf = LocalAlloc(LPTR, stDrvBufSize);
CRASHIFNULLALLOC(pwszDrvBuf);
AddCheckHeader(pwszDrvBuf, stDrvBufSize, L"Drivers", TRUE);
DRVMain();
ShrinkWcharBuffer(&pwszDrvBuf);
return pwszDrvBuf;
}