diff options
| author | Andrey Konovalov <andreyknvl@gmail.com> | 2025-08-20 12:13:46 +0000 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2025-08-21 12:29:58 +0000 |
| commit | c908ebc6718922bde328972729832db68dd6bfa7 (patch) | |
| tree | a8fab65e78bb94234220cdb803c7e485ac39d941 /sys | |
| parent | 5ec502e031c3ca7cad5ac0aa468469b7b9b85d1d (diff) | |
sys/linux: reorganize generateUsbDeviceDescriptor
Introduce a helper function to make the following changes cleaner.
No functional changes.
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/linux/init_vusb.go | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/sys/linux/init_vusb.go b/sys/linux/init_vusb.go index 0c1906819..29ec51e7e 100644 --- a/sys/linux/init_vusb.go +++ b/sys/linux/init_vusb.go @@ -62,10 +62,16 @@ func (arch *arch) generateUsbDeviceDescriptor(g *prog.Gen, typ0 prog.Type, dir p return } - id := randUsbDeviceID(g) + patchUsbDeviceID(g, &arg, calls, usbIdsAll) + + return +} + +func patchUsbDeviceID(g *prog.Gen, arg *prog.Arg, calls []*prog.Call, ids string) { + id := randUsbDeviceID(g, ids) bcdDevice := id.BcdDeviceLo + uint16(g.Rand().Intn(int(id.BcdDeviceHi-id.BcdDeviceLo)+1)) - devArg := arg.(*prog.GroupArg).Inner[0] + devArg := (*arg).(*prog.GroupArg).Inner[0] patchGroupArg(devArg, 7, "idVendor", uint64(id.IDVendor)) patchGroupArg(devArg, 8, "idProduct", uint64(id.IDProduct)) patchGroupArg(devArg, 9, "bcdDevice", uint64(bcdDevice)) @@ -80,21 +86,19 @@ func (arch *arch) generateUsbDeviceDescriptor(g *prog.Gen, typ0 prog.Type, dir p interfaceArg = interfaceArg.(*prog.GroupArg).Inner[0] if i > 0 { // Generate new IDs for every interface after the first one. - id = randUsbDeviceID(g) + id = randUsbDeviceID(g, ids) } patchGroupArg(interfaceArg, 5, "bInterfaceClass", uint64(id.BInterfaceClass)) patchGroupArg(interfaceArg, 6, "bInterfaceSubClass", uint64(id.BInterfaceSubClass)) patchGroupArg(interfaceArg, 7, "bInterfaceProtocol", uint64(id.BInterfaceProtocol)) patchGroupArg(interfaceArg, 2, "bInterfaceNumber", uint64(id.BInterfaceNumber)) } - - return } -func randUsbDeviceID(g *prog.Gen) UsbDeviceID { - totalIds := len(usbIdsAll) / BytesPerUsbID +func randUsbDeviceID(g *prog.Gen, ids string) UsbDeviceID { + totalIds := len(ids) / BytesPerUsbID idNum := g.Rand().Intn(totalIds) - base := usbIdsAll[idNum*BytesPerUsbID : (idNum+1)*BytesPerUsbID] + base := ids[idNum*BytesPerUsbID : (idNum+1)*BytesPerUsbID] p := strings.NewReader(base) var id UsbDeviceID |
