From 8bd19008f250bace386ab8b423d4f01323309e3d Mon Sep 17 00:00:00 2001 From: evilsocket Date: Wed, 20 Feb 2019 18:16:30 +0100 Subject: [PATCH] added HID support for Amazon devices --- modules/hid/build_amazon.go | 36 +++++++++++++++++++++++++++++++++++ modules/hid/build_logitech.go | 6 +++--- modules/hid/builders.go | 1 + 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 modules/hid/build_amazon.go diff --git a/modules/hid/build_amazon.go b/modules/hid/build_amazon.go new file mode 100644 index 00000000..be9fdbfe --- /dev/null +++ b/modules/hid/build_amazon.go @@ -0,0 +1,36 @@ +package hid + +const ( + amzFrameDelay = 5 +) + +type AmazonBuilder struct { +} + +func (b AmazonBuilder) frameFor(cmd *Command) []byte { + return []byte{0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, + 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, + 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, + 0x0f, 0, cmd.Mode, 0, cmd.HID, 0} +} + +func (b AmazonBuilder) BuildFrames(commands []*Command) error { + for i, cmd := range commands { + if i == 0 { + for j := 0; j < 5; j++ { + cmd.AddFrame(b.frameFor(&Command{}), amzFrameDelay) + } + } + + if cmd.IsHID() { + cmd.AddFrame(b.frameFor(cmd), amzFrameDelay) + cmd.AddFrame(b.frameFor(&Command{}), amzFrameDelay) + } else if cmd.IsSleep() { + for i, num := 0, cmd.Sleep/10; i < num; i++ { + cmd.AddFrame(b.frameFor(&Command{}), 10) + } + } + } + + return nil +} diff --git a/modules/hid/build_logitech.go b/modules/hid/build_logitech.go index c66d7adf..4d17ea7f 100644 --- a/modules/hid/build_logitech.go +++ b/modules/hid/build_logitech.go @@ -1,7 +1,7 @@ package hid const ( - frameDelay = 12 + ltFrameDelay = 12 ) var ( @@ -31,7 +31,7 @@ func (b LogitechBuilder) BuildFrames(commands []*Command) error { numCommands := len(commands) for i, cmd := range commands { if i == 0 { - cmd.AddFrame(helloData, frameDelay) + cmd.AddFrame(helloData, ltFrameDelay) } next := (*Command)(nil) @@ -40,7 +40,7 @@ func (b LogitechBuilder) BuildFrames(commands []*Command) error { } if cmd.IsHID() { - cmd.AddFrame(b.frameFor(cmd), frameDelay) + cmd.AddFrame(b.frameFor(cmd), ltFrameDelay) cmd.AddFrame(keepAliveData, 0) if next == nil || cmd.HID == next.HID || next.IsSleep() { cmd.AddFrame(b.frameFor(&Command{}), 0) diff --git a/modules/hid/builders.go b/modules/hid/builders.go index 750588d0..cd1dbb8f 100644 --- a/modules/hid/builders.go +++ b/modules/hid/builders.go @@ -10,4 +10,5 @@ type FrameBuilder interface { var FrameBuilders = map[network.HIDType]FrameBuilder{ network.HIDTypeLogitech: LogitechBuilder{}, + network.HIDTypeAmazon: AmazonBuilder{}, }