mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 21:43:18 -07:00
new: new can module for CAN-bus
This commit is contained in:
parent
9937e797ae
commit
5fe3ef3d52
12 changed files with 755 additions and 3 deletions
|
@ -120,6 +120,8 @@ func (mod *EventsStream) Render(output io.Writer, e session.Event) {
|
|||
mod.viewBLEEvent(output, e)
|
||||
} else if strings.HasPrefix(e.Tag, "hid.") {
|
||||
mod.viewHIDEvent(output, e)
|
||||
} else if strings.HasPrefix(e.Tag, "can.") {
|
||||
mod.viewCANEvent(output, e)
|
||||
} else if strings.HasPrefix(e.Tag, "gps.") {
|
||||
mod.viewGPSEvent(output, e)
|
||||
} else if strings.HasPrefix(e.Tag, "mod.") {
|
||||
|
|
51
modules/events_stream/events_view_can.go
Normal file
51
modules/events_stream/events_view_can.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
package events_stream
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/bettercap/bettercap/modules/can"
|
||||
"github.com/bettercap/bettercap/network"
|
||||
"github.com/bettercap/bettercap/session"
|
||||
"github.com/dustin/go-humanize"
|
||||
|
||||
"github.com/evilsocket/islazy/tui"
|
||||
)
|
||||
|
||||
func (mod *EventsStream) viewCANEvent(output io.Writer, e session.Event) {
|
||||
if e.Tag == "can.device.new" {
|
||||
dev := e.Data.(*network.CANDevice)
|
||||
fmt.Fprintf(output, "[%s] [%s] new CAN device %s (%s) detected.\n",
|
||||
e.Time.Format(mod.timeFormat),
|
||||
tui.Green(e.Tag),
|
||||
tui.Bold(dev.Name),
|
||||
tui.Dim(dev.Description))
|
||||
} else if e.Tag == "can.message" {
|
||||
msg := e.Data.(can.Message)
|
||||
|
||||
// unparsed
|
||||
if msg.Name == "" {
|
||||
fmt.Fprintf(output, "[%s] [%s] <id %d> (%s): %s\n",
|
||||
e.Time.Format(mod.timeFormat),
|
||||
tui.Green(e.Tag),
|
||||
msg.Frame.ID,
|
||||
tui.Dim(humanize.Bytes(uint64(msg.Frame.Length))),
|
||||
hex.EncodeToString(msg.Frame.Data[:msg.Frame.Length]))
|
||||
} else {
|
||||
fmt.Fprintf(output, "[%s] [%s] <id %d> %s (%s) from %s:\n",
|
||||
e.Time.Format(mod.timeFormat),
|
||||
tui.Green(e.Tag),
|
||||
msg.Frame.ID,
|
||||
msg.Name,
|
||||
tui.Dim(humanize.Bytes(uint64(msg.Frame.Length))),
|
||||
tui.Bold(msg.Source.Name))
|
||||
|
||||
for name, value := range msg.Signals {
|
||||
fmt.Fprintf(output, " %s : %s\n", name, value)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fmt.Fprintf(output, "[%s] [%s] %v\n", e.Time.Format(mod.timeFormat), tui.Green(e.Tag), e)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue