8000 copy required files for libusb-win32 filter driver installation by xzn · Pull Request #216 · pbatard/libwdi · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

copy required files for libusb-win32 filter driver installation #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 79 additions & 6 deletions libwdi/libwdi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1443,13 +1443,16 @@ static int install_driver_internal(void* arglist)
STARTUPINFOA si;
PROCESS_INFORMATION pi;
SECURITY_ATTRIBUTES sa;
char path[MAX_PATH], exename[MAX_PATH], exeargs[MAX_PATH];
char path[MAX_PATH], exepath[MAX_PATH], exename[MAX_PATH], exeargs[MAX_PATH];
char srcp 10000 ath[MAX_PATH], dstpath[MAX_PATH], syspath[MAX_PATH];
HANDLE stdout_w = INVALID_HANDLE_VALUE;
HANDLE handle[3] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
OVERLAPPED overlapped;
int r;
DWORD err, rd_count, to_read, offset, bufsize = LOGBUF_SIZE;
BOOL is_x64 = FALSE;
UINT ret;
BOOL is_x64 = FALSE, is_WOW64 = FALSE;
BOOL is_uninstall = FALSE;
char *buffer = NULL, *new_buffer;
const char* filter_name = "libusb0";

Expand Down Expand Up @@ -1504,6 +1507,7 @@ static int install_driver_internal(void* arglist)
// This application is not 64 bit, but it might be 32 bit
// running in WOW64
IsWow64Process(GetCurrentProcess(), &is_x64);
is_WOW64 = is_x64;
} else {
is_x64 = TRUE;
}
Expand All @@ -1529,12 +1533,15 @@ static int install_driver_internal(void* arglist)
if (!filter_driver) {
// Why do we need two installers? Glad you asked. If you try to run the x86 installer on an x64
// system, you will get a "System does not work under WOW64 and requires 64-bit version" message.
static_strcpy(exepath, path);
static_sprintf(exename, "\"%s\\installer_x%s.exe\"", path, is_x64?"64":"86");
static_sprintf(exeargs, "\"%s\"", params->inf_name);
} else {
// Use libusb-win32's filter driver installer
static_sprintf(exename, "\"%s\\%s\\\\install-filter.exe\"", path, is_x64?"amd64":"x86");
if (safe_stricmp(current_device->upper_filter, filter_name) == 0) {
static_sprintf(exepath, "%s\\%s", path, is_x64?"amd64":"x86");
static_sprintf(exename, "\"%s\\%s\\install-filter.exe\"", path, is_x64?"amd64":"x86");
is_uninstall = safe_stricmp(current_device->upper_filter, filter_name) == 0;
if (is_uninstall) {
// Device already has the libusb-win32 filter => remove
static_strcpy(exeargs, "uninstall -d=");
} else {
Expand All @@ -1561,15 +1568,15 @@ static int install_driver_internal(void* arglist)
r = WDI_ERROR_NOT_FOUND; goto out;
}

if (IsUserAnAdmin()) {
if (!IsUserAnAdmin()) {
// Take care of UAC with ShellExecuteEx + runas
shExecInfo.cbSize = sizeof(SHELLEXECUTEINFOA);
shExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
shExecInfo.hwnd = NULL;
shExecInfo.lpVerb = "runas";
shExecInfo.lpFile = filter_driver?"install-filter.exe":(is_x64?"installer_x64.exe":"installer_x86.exe");
shExecInfo.lpParameters = exeargs;
shExecInfo.lpDirectory = path;
shExecInfo.lpDirectory = exepath;
shExecInfo.lpClass = NULL;
shExecInfo.nShow = SW_HIDE;
shExecInfo.hInstApp = NULL;
Expand Down Expand Up @@ -1598,6 +1605,72 @@ static int install_driver_internal(void* arglist)

handle[1] = shExecInfo.hProcess;
} else {
// Copy required files for filter driver
if (filter_driver && !is_uninstall) {
ret = GetSystemWindowsDirectoryU(syspath, sizeof(syspath));
if (ret == 0) {
err = GetLastError();

wdi_err("Error getting system path: %s", windows_error_str(err));
r = WDI_ERROR_IO;
goto out;
}

if (is_x64) {
static_sprintf(srcpath, "%s\\amd64\\libusb0.sys", path);
} else {
static_sprintf(srcpath, "%s\\x86\\libusb0.sys", path);
}
if (is_x64 && is_WOW64) {
static_sprintf(dstpath, "%s\\Sysnative\\drivers\\libusb0.sys", syspath);
} else {
static_sprintf(dstpath, "%s\\System32\\drivers\\libusb0.sys", syspath);
}
if (!CopyFileU(srcpath, dstpath, TRUE)) {
err = GetLastError();

if (err != ERROR_SUCCESS && err != ERROR_FILE_EXISTS) {
wdi_err("Error copying \"%s\" to \"%s\": %s", srcpath, dstpath, windows_error_str(err));
r = WDI_ERROR_IO;
goto out;
}
}

if (is_x64) {
static_sprintf(srcpath, "%s\\amd64\\libusb0.dll", path);
if (is_WOW64) {
static_sprintf(dstpath, "%s\\Sysnative\\libusb0.dll", syspath);
} else {
static_sprintf(dstpath, "%s\\System32\\libusb0.dll", syspath);
}
if (!CopyFileU(srcpath, dstpath, TRUE)) {
err = GetLastError();

if (err != ERROR_SUCCESS && err != ERROR_FILE_EXISTS) {
wdi_err("Error copying \"%s\" to \"%s\": %s", srcpath, dstpath, windows_error_str(err));
r = WDI_ERROR_IO;
goto out;
}
}
}

static_sprintf(srcpath, "%s\\x86\\libusb0_x86.dll", path);
if (!is_x64 || is_WOW64) {
static_sprintf(dstpath, "%s\\System32\\libusb0.dll", syspath);
} else {
static_sprintf(dstpath, "%s\\SysWOW64\\libusb0.dll", syspath);
}
if (!CopyFileU(srcpath, dstpath, TRUE)) {
err = GetLastError();

if (err != ERROR_SUCCESS && err != ERROR_FILE_EXISTS) {
wdi_err("Error copying \"%s\" to \"%s\": %s", srcpath, dstpath, windows_error_str(err));
r = WDI_ERROR_IO;
goto out;
}
}
}

// If app is already elevated, simply use CreateProcess()
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
Expand Down
0