| 1 | package hidscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/ |
| 2 | |
| 3 | import ( |
| 4 | "github.com/bettercap/bettercap/networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/" |
| 5 | ) |
| 6 | |
| 7 | const ( |
| 8 | ltFrameDelayscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/ltFrameDelay. = 12 |
| 9 | ) |
| 10 | |
| 11 | var ( |
| 12 | helloDatascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/helloData. = []byte{0x00, 0x4F, 0x00, 0x04, 0xB0, 0x10, 0x00, 0x00, 0x00, 0xED} |
| 13 | keepAliveDatascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/keepAliveData. = []byte{0x00, 0x40, 0x04, 0xB0, 0x0C} |
| 14 | ) |
| 15 | |
| 16 | type LogitechBuilderscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/LogitechBuilder# struct { |
| 17 | } |
| 18 | |
| 19 | func (b LogitechBuilderscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/LogitechBuilder#) frameForscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/LogitechBuilder#frameFor().(cmd *Commandscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/Command#) []byte { |
| 20 | data := []byte{0, 0xC1, cmd.Modescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/Command#Mode., cmd.HIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/Command#HID., 0, 0, 0, 0, 0, 0} |
| 21 | sz := len(data) |
| 22 | last := sz - 1 |
| 23 | sum := byte(0xff) |
| 24 | |
| 25 | for i := 0; i < last; i++ { |
| 26 | sum = (sum - data[i]) & 0xff |
| 27 | } |
| 28 | sum = (sum + 1) & 0xff |
| 29 | data[last] = sum |
| 30 | |
| 31 | return data |
| 32 | } |
| 33 | |
| 34 | func (b LogitechBuilderscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/LogitechBuilder#) BuildFramesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/LogitechBuilder#BuildFrames().(dev *networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/.HIDDevicescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/HIDDevice#, commands []*Commandscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/Command#) error { |
| 35 | last := len(commands) - 1 |
| 36 | for i, cmd := range commands { |
| 37 | if i == 0 { |
| 38 | cmd.AddFramescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/Command#AddFrame().(helloDatascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/helloData., ltFrameDelayscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/ltFrameDelay.) |
| 39 | } |
| 40 | |
| 41 | next := (*Commandscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/Command#)(nil) |
| 42 | if i < last { |
| 43 | next = commands[i+1] |
| 44 | } |
| 45 | |
| 46 | if cmd.IsHIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/Command#IsHID().() { |
| 47 | cmd.AddFramescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/Command#AddFrame().(b.frameForscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/LogitechBuilder#frameFor().(cmd), ltFrameDelayscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/ltFrameDelay.) |
| 48 | cmd.AddFramescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/Command#AddFrame().(keepAliveDatascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/keepAliveData., 0) |
| 49 | if next == nil || cmd.HIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/Command#HID. == next.HIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/Command#HID. || next.IsSleepscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/Command#IsSleep().() { |
| 50 | cmd.AddFramescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/Command#AddFrame().(b.frameForscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/LogitechBuilder#frameFor().(&Commandscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/Command#{}), 0) |
| 51 | } |
| 52 | } else if cmd.IsSleepscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/Command#IsSleep().() { |
| 53 | for i, num := 0, cmd.Sleepscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/Command#Sleep./10; i < num; i++ { |
| 54 | cmd.AddFramescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/Command#AddFrame().(keepAliveDatascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/hid`/keepAliveData., 10) |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return nil |
| 60 | } |