Last active
November 2, 2023 19:41
-
-
Save PyroAVR/bdc20e75ac3051f810cb239f96ccdca3 to your computer and use it in GitHub Desktop.
libwdi parent_id patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/libwdi/libwdi.c b/libwdi/libwdi.c | |
index 0bd1296..2c2b072 100644 | |
--- a/libwdi/libwdi.c | |
+++ b/libwdi/libwdi.c | |
@@ -25,6 +25,7 @@ | |
#include <crtdbg.h> | |
#endif | |
+#include <initguid.h> | |
#include <windows.h> | |
#include <setupapi.h> | |
#include <io.h> | |
@@ -40,6 +41,8 @@ | |
#include <wincrypt.h> | |
#include <winternl.h> | |
#include <assert.h> | |
+#include <devpropdef.h> | |
+#include <devpkey.h> | |
#include "installer.h" | |
#include "libwdi.h" | |
@@ -1065,6 +1068,13 @@ int LIBWDI_API wdi_create_list(struct wdi_device_info** list, | |
} | |
token = strtok (NULL, "\\#&"); | |
} | |
+ // point to parent device for composite children | |
+ if(device_info->is_composite && SetupDiGetDevicePropertyW(dev_info, | |
+ &dev_info_data, &DEVPKEY_Device_Parent, &devprop_type, | |
+ (BYTE*)desc, 2*MAX_DESC_LENGTH, &size, 0)) { | |
+ // guaranteed to be safe length from API description | |
+ device_info->parent_id = wchar_to_utf8(desc); | |
+ } | |
// Eliminate root hubs (no VID/PID => 0 from calloc) | |
if ( (is_hub) && (!has_vid) ) { | |
diff --git a/libwdi/libwdi.h b/libwdi/libwdi.h | |
index 9e043cc..b98a51c 100644 | |
--- a/libwdi/libwdi.h | |
+++ b/libwdi/libwdi.h | |
@@ -166,6 +166,8 @@ struct wdi_device_info { | |
char* compatible_id; | |
/** (Optional) Upper filter. NULL if unused */ | |
char* upper_filter; | |
+ /** (Optional) Parent device. NULL if unused */ | |
+ char* parent_id; | |
/** (Optional) Driver version (four WORDS). 0 if unused */ | |
UINT64 driver_version; | |
}; | |
diff --git a/libwdi/libwdi_i.h b/libwdi/libwdi_i.h | |
index d86785a..6679e43 100644 | |
--- a/libwdi/libwdi_i.h | |
+++ b/libwdi/libwdi_i.h | |
@@ -252,18 +252,6 @@ static const struct {uint16_t vid; uint16_t pid;} android_device[] = { | |
{0x22B8, 0x70A9}, | |
}; | |
- | |
-// For the retrieval of the device description on Windows 7 | |
-#ifndef DEVPROPKEY_DEFINED | |
-typedef struct { | |
- GUID fmtid; | |
- ULONG pid; | |
-} DEVPROPKEY; | |
-#endif | |
- | |
-static const DEVPROPKEY DEVPKEY_Device_BusReportedDeviceDesc = { | |
- { 0x540b947e, 0x8b40, 0x45bc, {0xa8, 0xa2, 0x6a, 0x0b, 0x89, 0x4c, 0xbd, 0xa2} }, 4 }; | |
- | |
// Check the status of the installer process | |
static int __inline check_completion(HANDLE process_handle) { | |
DWORD exit_code; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/libwdi.pxd b/src/libwdi.pxd | |
index 56177cf..e146594 100644 | |
--- a/src/libwdi.pxd | |
+++ b/src/libwdi.pxd | |
@@ -16,7 +16,7 @@ cdef extern from "libwdi.h": | |
char *hardware_id | |
char *compatible_id | |
char *upper_filter | |
- #char *parent_id | |
+ char *parent_id | |
long unsigned int driver_version | |
cdef struct wdi_options_prepare_driver: | |
diff --git a/src/pylibwdi.pyx b/src/pylibwdi.pyx | |
index 0086634..5bd0f1b 100644 | |
--- a/src/pylibwdi.pyx | |
+++ b/src/pylibwdi.pyx | |
@@ -150,9 +150,9 @@ class WDIDeviceInfo: | |
def hardware_id(self): | |
return self._self.hardware_id | |
-# @property | |
-# def parent_id(self): | |
-# return safe_decode(self._self.parent_id, 'utf-8') | |
+ @property | |
+ def parent_id(self): | |
+ return safe_decode(self._self.parent_id, 'utf-8') | |
# TODO: does this actually need to be a cclass? We don't need to pass this to C or call its methods from C. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Both patches must be applied in order for the python bindings to work correctly.