-
Notifications
You must be signed in to change notification settings - Fork 1
/
glowdrvinst.c
126 lines (106 loc) · 3.4 KB
/
glowdrvinst.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* Copyright (c) 2015 Antumbra
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <direct.h>
#include <stdbool.h>
#include <stdint.h>
#include <libwdi.h>
bool batch = false;
void die(int st)
{
if (!batch) {
printf("Press ENTER to exit.\n");
for (int c; c = getchar(), c != '\n' && c != EOF;);
}
exit(st);
}
void install_driver(uint16_t vid, uint16_t pid)
{
printf("Will install WinUSB driver for VID 0x%04x PID 0x%04x\n",
(unsigned int)vid, (unsigned int)pid);
struct wdi_options_prepare_driver prepopts = {
.driver_type = WDI_WINUSB,
.vendor_name = "Antumbra",
.device_guid = NULL,
.disable_cat = false,
.disable_signing = false,
.cert_subject = NULL,
.use_wcid_driver = false,
};
struct wdi_device_info dev = {
.next = NULL,
.vid = vid,
.pid = pid,
.is_composite = false,
.mi = 0,
.desc = "Glow",
.driver = NULL,
.device_id = NULL,
.hardware_id = NULL,
.compatible_id = NULL,
.upper_filter = NULL,
.driver_version = 0,
};
int err;
const char prefix[] = "glowinftmp";
char tmpdir[sizeof prefix + 8 + 1];
sprintf(tmpdir, "%s%04x%04x", prefix, (unsigned int)vid, (unsigned int)pid);
err = wdi_prepare_driver(&dev, tmpdir, "glow.inf", &prepopts);
if (err) {
fprintf(stderr, "wdi_prepare_driver: %s\n", wdi_strerror(err));
die(1);
}
err = wdi_install_driver(&dev, tmpdir, "glow.inf", NULL);
if (err) {
fprintf(stderr, "wdi_install_driver: %s\n", wdi_strerror(err));
die(1);
}
fputs("Installation successful\n", stdout);
}
int main(int argc, char **argv)
{
bool elevated;
for (int i = 1; i < argc; ++i) {
if (!strcmp(argv[i], "batch"))
batch = true;
if (!strcmp(argv[i], "elevated"))
elevated = true;
}
fputs("Antumbra Glow WinUSB driver installer\n", stdout);
if (!batch && !elevated) {
fputs("Trying to relaunch with elevated privileges\n", stdout);
char buf[MAX_PATH];
GetModuleFileName(NULL, buf, sizeof buf);
printf("Executable is: %s\n", buf);
int ret = ShellExecute(NULL, "runas", buf, "elevated", NULL, 5);
if (ret > 32) {
fputs("Successfully relaunched; exiting unprivileged instance.\n", stdout);
die(0);
}
else {
fputs("Relaunch failed!\n", stdout);
die(1);
}
}
if (!batch) {
fputs("Press ENTER to begin installation...\n", stdout);
for (int c; (c = getchar()) != '\n';) {
if (c == EOF)
exit(0);
}
}
install_driver(0x16d0, 0x0a85);
die(0);
return 0;
}