aboutsummaryrefslogtreecommitdiffstats
path: root/tun/wintun/setupapi/types_windows.go
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-02-07 23:45:11 +0100
committerSimon Rozman <simon@rozman.si>2019-02-07 23:50:43 +0100
commitc4988999ac073db9e08a4efdb2f82a3d4f32f25d (patch)
treeaca16cf3aae4686efa5e508f84c6cd34c758ad52 /tun/wintun/setupapi/types_windows.go
parentsetupapi: Merge SP_DRVINFO_DATA and DrvInfoData (diff)
downloadwireguard-go-c4988999ac073db9e08a4efdb2f82a3d4f32f25d.tar.xz
wireguard-go-c4988999ac073db9e08a4efdb2f82a3d4f32f25d.zip
setupapi: Merge _SP_DRVINFO_DETAIL_DATA and DrvInfoDetailData
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'tun/wintun/setupapi/types_windows.go')
-rw-r--r--tun/wintun/setupapi/types_windows.go82
1 files changed, 42 insertions, 40 deletions
diff --git a/tun/wintun/setupapi/types_windows.go b/tun/wintun/setupapi/types_windows.go
index ab5c9bb..8acb31b 100644
--- a/tun/wintun/setupapi/types_windows.go
+++ b/tun/wintun/setupapi/types_windows.go
@@ -368,75 +368,77 @@ func (data *DrvInfoData) IsNewer(driverDate windows.Filetime, driverVersion uint
return false
}
-type _SP_DRVINFO_DETAIL_DATA struct {
- Size uint32
+// DrvInfoDetailData is driver information details structure (provides detailed information about a particular driver information structure)
+type DrvInfoDetailData struct {
+ size uint32 // On input, this must be exactly the sizeof(DrvInfoDetailData). On output, we set this member to the actual size of structure data.
InfDate windows.Filetime
- CompatIDsOffset uint32
- CompatIDsLength uint32
+ compatIDsOffset uint32
+ compatIDsLength uint32
_ uintptr
- SectionName [LINE_LEN]uint16
- InfFileName [windows.MAX_PATH]uint16
- DrvDescription [LINE_LEN]uint16
- HardwareID [1]uint16
+ sectionName [LINE_LEN]uint16
+ infFileName [windows.MAX_PATH]uint16
+ drvDescription [LINE_LEN]uint16
+ hardwareID [1]uint16
}
-func (_data *_SP_DRVINFO_DETAIL_DATA) toGo(bufLen uint32) (DriverInfoDetailData *DrvInfoDetailData) {
- DriverInfoDetailData = &DrvInfoDetailData{
- InfDate: _data.InfDate,
- SectionName: windows.UTF16ToString(_data.SectionName[:]),
- InfFileName: windows.UTF16ToString(_data.InfFileName[:]),
- DrvDescription: windows.UTF16ToString(_data.DrvDescription[:]),
- CompatIDs: []string{},
- }
+func (data *DrvInfoDetailData) GetSectionName() string {
+ return windows.UTF16ToString(data.sectionName[:])
+}
- bufW := _data.getBuf(bufLen)
+func (data *DrvInfoDetailData) GetInfFileName() string {
+ return windows.UTF16ToString(data.infFileName[:])
+}
+
+func (data *DrvInfoDetailData) GetDrvDescription() string {
+ return windows.UTF16ToString(data.drvDescription[:])
+}
- if _data.CompatIDsOffset > 1 {
- DriverInfoDetailData.HardwareID = windows.UTF16ToString(bufW[:wcslen(bufW)])
+func (data *DrvInfoDetailData) GetHardwareID() string {
+ if data.compatIDsOffset > 1 {
+ bufW := data.getBuf()
+ return windows.UTF16ToString(bufW[:wcslen(bufW)])
}
- if _data.CompatIDsLength > 0 {
- bufW = bufW[_data.CompatIDsOffset : _data.CompatIDsOffset+_data.CompatIDsLength]
+ return ""
+}
+
+func (data *DrvInfoDetailData) GetCompatIDs() []string {
+ a := make([]string, 0)
+
+ if data.compatIDsLength > 0 {
+ bufW := data.getBuf()
+ bufW = bufW[data.compatIDsOffset : data.compatIDsOffset+data.compatIDsLength]
for i := 0; i < len(bufW); {
j := i + wcslen(bufW[i:])
if i < j {
- DriverInfoDetailData.CompatIDs = append(DriverInfoDetailData.CompatIDs, windows.UTF16ToString(bufW[i:j]))
+ a = append(a, windows.UTF16ToString(bufW[i:j]))
}
i = j + 1
}
}
- return
+ return a
}
-func (_data *_SP_DRVINFO_DETAIL_DATA) getBuf(bufLen uint32) []uint16 {
- len := (bufLen - uint32(unsafe.Offsetof(_data.HardwareID))) / 2
+func (data *DrvInfoDetailData) getBuf() []uint16 {
+ len := (data.size - uint32(unsafe.Offsetof(data.hardwareID))) / 2
sl := struct {
addr *uint16
len int
cap int
- }{&_data.HardwareID[0], int(len), int(len)}
+ }{&data.hardwareID[0], int(len), int(len)}
return *(*[]uint16)(unsafe.Pointer(&sl))
}
-// DrvInfoDetailData is driver information details structure (provides detailed information about a particular driver information structure)
-type DrvInfoDetailData struct {
- InfDate windows.Filetime
- SectionName string
- InfFileName string
- DrvDescription string
- HardwareID string
- CompatIDs []string
-}
-
// IsCompatible method tests if given hardware ID matches the driver or is listed on the compatible ID list.
-func (driverInfoDetailData *DrvInfoDetailData) IsCompatible(hwid string) bool {
+func (data *DrvInfoDetailData) IsCompatible(hwid string) bool {
hwidLC := strings.ToLower(hwid)
- if strings.ToLower(driverInfoDetailData.HardwareID) == hwidLC {
+ if strings.ToLower(data.GetHardwareID()) == hwidLC {
return true
}
- for i := range driverInfoDetailData.CompatIDs {
- if strings.ToLower(driverInfoDetailData.CompatIDs[i]) == hwidLC {
+ a := data.GetCompatIDs()
+ for i := range a {
+ if strings.ToLower(a[i]) == hwidLC {
return true
}
}