8000 Add wdi_sign_driver_inf() by spiro-trikaliotis · Pull Request #234 · pbatard/libwdi · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add wdi_sign_driver_inf() #234

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
Closed
Show file tree
Hide file tree
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
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,23 @@ Main features
* Automated driver files extraction, for both 32 and 64 bit platforms
* Automated driver installation, including UAC elevation where necessary
* Single library embedding all the required files
* Supports Windows platform from Windows 7 to Windows 10
* Supports Windows platform from Windows 7 to Windows 10 (but **NOT** Windows 11)

## IMPORTANT NOTICE REGARDING WINDOWS 11

Libwdi is **NOT COMPATIBLE WITH WINDOWS 11 OR LATER**.

This is due to Microsoft having removed Windows users' ability to indicate whether
they want to trust a driver package in Windows 11, which
[libwdi needs in order to install a driver](https://community.osr.com/discussion/293115/windows-11-and-alternative-driver-installation-method-in-libwdi).

Currently, there is no known way to work around this, which means that libwdi is
unlikely to ever be compatible with Windows 11.

If you are unhappy about this, feel free to tell Microsoft that keeping a user's
ability to declare whether they want to trust a driver package, by adding its
signing certificate into the *Trusted Publishers* store, is an important feature
of earlier versions of Windows that should be retained in Windows 11.

Additional features
-------------------
Expand Down
8 changes: 4 additions & 4 deletions examples/wdi-simple.rc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#endif

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,4,757,0
PRODUCTVERSION 1,4,757,0
FILEVERSION 1,4,758,0
PRODUCTVERSION 1,4,758,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -25,13 +25,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "akeo.ie"
VALUE "FileDescription", "WDI-Simple"
VALUE "FileVersion", "1.3.757"
VALUE "FileVersion", "1.3.758"
VALUE "InternalName", "WDI-Simple"
VALUE "LegalCopyright", "� 2010-2018 Pete Batard (LGPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/lesser.html"
VALUE "OriginalFilename", "wdi-simple.exe"
VALUE "ProductName", "WDI-Simple"
VALUE "ProductVersion", "1.3.757"
VALUE "ProductVersion", "1.3.758"
VALUE "Comments", "http://libwdi.akeo.ie"
END
END
Expand Down
7 changes: 7 additions & 0 deletions examples/zadig.c
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,13 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
return 0;
}

if (nWindowsVersion >= WINDOWS_11) {
MessageBoxA(NULL, "Zadig/libwdi is not compatible with Windows 11 or later",
"Incompatible version", MB_ICONSTOP);
CloseHandle(mutex);
return 0;
}

// Save instance of the application for further reference
main_instance = hInstance;

Expand Down
2 changes: 1 addition & 1 deletion examples/zadig.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#define FIELD_ORANGE RGB(255,240,200)
#define ARROW_GREEN RGB(92,228,65)
#define ARROW_ORANGE RGB(253,143,56)
#define APP_VERSION "Zadig 2.6.757"
#define APP_VERSION "Zadig 2.6.758"

// These are used to flag end users about the driver they are going to replace
enum driver_type {
Expand Down
8 changes: 4 additions & 4 deletions examples/zadig.rc
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 2,6,757,0
PRODUCTVERSION 2,6,757,0
FILEVERSION 2,6,758,0
PRODUCTVERSION 2,6,758,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -264,13 +264,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "akeo.ie"
VALUE "FileDescription", "Zadig"
VALUE "FileVersion", "2.6.757"
VALUE "FileVersion", "2.6.758"
VALUE "InternalName", "Zadig"
VALUE "LegalCopyright", "� 2010-2018 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "zadig.exe"
VALUE "ProductName", "Zadig"
VALUE "ProductVersion", "2.6.757"
VALUE "ProductVersion", "2.6.758"
VALUE "Comments", "http://libwdi.akeo.ie"
END
END
Expand Down
121 changes: 115 additions & 6 deletions libwdi/libwdi.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,13 @@ void GetWindowsVersion(void)
case 0x64: w = (ws ? "10 (Preview 1)" : "Server 10 (Preview 1)");
break;
// Starting with Windows 10 Preview 2, the major is the same as the public-facing version
case 0xA0: w = (ws ? ((vi.dwBuildNumber < 20000) ? "10" : "11") : ((vi.dwBuildNumber < 17763) ? "Server 2016" : "Server 2019"));
break;
case 0xA0:
if (vi.dwBuildNumber < 20000) {
w = (ws ? "10" : ((vi.dwBuildNumber < 17763) ? "Server 2016" : "Server 2019"));
break;
}
nWindowsVersion = 0xB0;
// Fall through
case 0xB0: w = (ws ? "11" : "Server 2022");
break;
default:
Expand Down Expand Up @@ -802,6 +807,11 @@ int LIBWDI_API wdi_create_list(struct wdi_device_info** list,
r = WDI_ERROR_NOT_SUPPORTED;
goto out;
}
if (nWindowsVersion >= WINDOWS_11) {
wdi_err("This version of Windows is not supported");
r = WDI_ERROR_NOT_SUPPORTED;
goto out;
}

*list = NULL;

Expand Down Expand Up @@ -1117,10 +1127,50 @@ static long tokenize_internal(const char* resource_name, char** dst, const token
return -ERROR_RESOURCE_DATA_NOT_FOUND;
}

// tokenizes a resource stored in resource.h
static long tokenize_file_internal(const char* file_name, char** dst, const token_entity_t* token_entities,
const char* tok_prefix, const char* tok_suffix, int recursive)
{
long ret = -ERROR_RESOURCE_DATA_NOT_FOUND;

FILE* f = NULL;
char* buffer = NULL;

f = fopen(file_name, "r");
if (f) {
fseek(f, 0L, SEEK_END);
long size = ftell(f);
fseek(f, 0L, SEEK_SET);

buffer = (char*)malloc(size);
if (buffer == NULL) {
wdi_err("Unable to allocate buffer: aborting");
ret = WDI_ERROR_RESOURCE;
goto out;
}
if (fread(buffer, 1, size, f) < 0) {
wdi_err("Error reading template file");
ret = -ERROR_RESOURCE_DATA_NOT_FOUND;
goto out;
}
ret = tokenize_string(buffer, size,
dst, token_entities, tok_prefix, tok_suffix, recursive);
}

out:
if (buffer) {
free(buffer);
}
if (f) {
fclose(f);
}
return ret;
}

#define CAT_LIST_MAX_ENTRIES 16
// Create an inf and extract coinstallers in the directory pointed by path
int LIBWDI_API wdi_prepare_driver(struct wdi_device_info* device_info, const char* path,
const char* inf_name, struct wdi_options_prepare_driver* options)
static int LIBWDI_API wdi_prepare_or_sign_driver(struct wdi_device_info* device_info, const char* path,
const char* inf_name, const char* inf_input_name, struct wdi_options_prepare_driver* options)
{
const wchar_t bom = 0xFEFF;
#if defined(ENABLE_DEBUG_LOGGING) || defined(INCLUDE_DEBUG_LOGGING)
Expand Down Expand Up @@ -1150,6 +1200,34 @@ int LIBWDI_API wdi_prepare_driver(struct wdi_device_info* device_info, const cha
r = WDI_ERROR_NOT_SUPPORTED;
goto out;
}
if (nWindowsVersion >= WINDOWS_11) {
wdi_err("This version of Windows is not supported");
r = WDI_ERROR_NOT_SUPPORTED;
goto out;
}

if (inf_name == NULL && inf_input_name != NULL) {
static char inf_name_generated[256];
char fext[128] = "";

if (_splitpath_s(inf_input_name,
NULL, 0, // drive: not needed
NULL, 0, // dir: not needed
inf_name_generated, sizeof(inf_name_generated),
fext, sizeof(fext)) != 0) {
wdi_err("Error in _splitpath_s");
r = WDI_ERROR_INVALID_PARAM;
goto out;
}

if (strcat_s(inf_name_generated, sizeof(inf_name_generated), fext) != 0) {
wdi_err("Could not generated inf name");
r = WDI_ERROR_RESOURCE;
goto out;
}

inf_name = inf_name_generated;
}

if ((device_info == NULL) || (inf_name == NULL)) {
wdi_err("One of the required parameter is NULL");
Expand Down Expand Up @@ -1347,8 +1425,15 @@ int LIBWDI_API wdi_prepare_driver(struct wdi_device_info* device_info, const cha
(int)driver_version[driver_type].dwFileVersionLS>>16, (int)driver_version[driver_type].dwFileVersionLS&0xFFFF);

// Tokenize the file
if ((inf_file_size = tokenize_internal(inf_template[driver_type],
&dst, inf_entities, "#", "#", 0)) > 0) {
if (inf_input_name != NULL) {
inf_file_size = tokenize_file_internal(inf_input_name,
&dst, inf_entities, "#", "#", 0);
}
else {
inf_file_size = tokenize_internal(inf_template[driver_type],
&dst, inf_entities, "#", "#", 0);
}
if (inf_file_size > 0) {
fd = fopen_as_userU(inf_path, "w");
if (fd == NULL) {
wdi_err("Failed to create file: %s", inf_path);
Expand Down Expand Up @@ -1452,6 +1537,20 @@ int LIBWDI_API wdi_prepare_driver(struct wdi_device_info* device_info, const cha
return r;
}

// Create an inf and extract coinstallers in the directory pointed by path
int LIBWDI_API wdi_prepare_driver(struct wdi_device_info* device_info, const char* path,
const char* inf_name, struct wdi_options_prepare_driver* options)
{
return wdi_prepare_or_sign_driver(device_info, path, inf_name, NULL, options);
}

// Create an inf and extract coinstallers in the directory pointed by path
int LIBWDI_API wdi_sign_driver_inf(struct wdi_device_info* device_info, const char* path,
const char* inf_input_name, struct wdi_options_prepare_driver* options)
{
return wdi_prepare_or_sign_driver(device_info, path, NULL, inf_input_name, options);
}

// Handle messages received from the elevated installer through the pipe
static int process_message(char* buffer, DWORD size)
{
Expand Down Expand Up @@ -1573,6 +1672,11 @@ static int install_driver_internal(void* arglist)
r = WDI_ERROR_NOT_SUPPORTED;
goto out;
}
if (nWindowsVersion >= WINDOWS_11) {
wdi_err("This version of Windows is not supported");
r = WDI_ERROR_NOT_SUPPORTED;
goto out;
}

PF_LOAD_LIBRARY(SetupAPI);
r = WDI_ERROR_RESOURCE;
Expand Down Expand Up @@ -1869,6 +1973,11 @@ int LIBWDI_API wdi_install_trusted_certificate(const char* cert_name,
r = WDI_ERROR_NOT_SUPPORTED;
goto out;
}
if (nWindowsVersion >= WINDOWS_11) {
wdi_err("This version of Windows is not supported");
r = WDI_ERROR_NOT_SUPPORTED;
goto out;
}

if (safe_strlen(cert_name) == 0) {
r = WDI_ERROR_INVALID_PARAM;
Expand Down
6 changes: 6 additions & 0 deletions libwdi/libwdi.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ LIBWDI_EXP int LIBWDI_API wdi_destroy_list(struct wdi_device_info* list);
LIBWDI_EXP int LIBWDI_API wdi_prepare_driver(struct wdi_device_info* device_info, const char* path,
const char* inf_name, struct wdi_options_prepare_driver* options);

/*
* Sign a specific inf file
*/
LIBWDI_EXP int LIBWDI_API wdi_sign_driver_inf(struct wdi_device_info* device_info, const char* path,
const char* inf_input_name, struct wdi_options_prepare_driver* options);

/*
* Install a driver for a specific device
*/
Expand Down
8 changes: 4 additions & 4 deletions libwdi/libwdi.rc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,4,757,0
PRODUCTVERSION 1,4,757,0
FILEVERSION 1,4,758,0
PRODUCTVERSION 1,4,758,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -68,13 +68,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "akeo.ie"
VALUE "FileDescription", "libwdi: Windows Driver Installer Library"
VALUE "FileVersion", "1.3.757"
VALUE "FileVersion", "1.3.758"
VALUE "InternalName", "libwdi"
VALUE "LegalCopyright", "� 2010-2017 Pete Batard (LGPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/lesser.html"
VALUE "OriginalFilename", "libwdi"
VALUE "ProductName", "libwdi"
VALUE "ProductVersion", "1.3.757"
VALUE "ProductVersion", "1.3.758"
VALUE "Comments", "http://libwdi.akeo.ie"
END
END
Expand Down
1 change: 1 addition & 0 deletions libwdi/stdfn.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ enum WindowsVersion {
WINDOWS_8_1 = 0x63,
WINDOWS_10_PREVIEW1 = 0x64,
WINDOWS_10 = 0xA0,
WINDOWS_11 = 0xB0,
WINDOWS_MAX
};

Expand Down
0