MCPcopy
hub / github.com/bettercap/bettercap / prepInjection

Method prepInjection

modules/hid/hid_inject.go:45–91  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

43}
44
45func (mod *HIDRecon) prepInjection() (error, *network.HIDDevice, []*Command) {
46 var err error
47
48 if err, mod.sniffType = mod.StringParam("hid.force.type"); err != nil {
49 return err, nil, nil
50 }
51
52 dev, found := mod.Session.HID.Get(mod.sniffAddr)
53 if found == false {
54 mod.Warning("device %s is not visible, will use HID type %s", mod.sniffAddr, tui.Yellow(mod.sniffType))
55 } else if dev.Type == network.HIDTypeUnknown {
56 mod.Warning("device %s type has not been detected yet, falling back to '%s'", mod.sniffAddr, tui.Yellow(mod.sniffType))
57 }
58
59 var builder FrameBuilder
60 if found && dev.Type != network.HIDTypeUnknown {
61 // get the device specific protocol handler
62 builder, found = FrameBuilders[dev.Type]
63 if found == false {
64 return errNotSupported(dev), nil, nil
65 }
66 } else {
67 // get the device protocol handler from the hid.force.type parameter
68 builder = builderFromName(mod.sniffType)
69 }
70
71 // get the keymap from the selected layout
72 keyMap := KeyMapFor(mod.keyLayout)
73 if keyMap == nil {
74 return errNoKeyMap(mod.keyLayout), nil, nil
75 }
76
77 // parse the script into a list of Command objects
78 cmds, err := mod.parser.Parse(keyMap, mod.scriptPath)
79 if err != nil {
80 return err, nil, nil
81 }
82
83 mod.Info("%s loaded ...", mod.scriptPath)
84
85 // build the protocol specific frames to send
86 if err := builder.BuildFrames(dev, cmds); err != nil {
87 return err, nil, nil
88 }
89
90 return nil, dev, cmds
91}
92
93func (mod *HIDRecon) doInjection() {
94 mod.writeLock.Lock()

Callers 1

doInjectionMethod · 0.95

Calls 10

BuildFramesMethod · 0.95
errNotSupportedFunction · 0.85
builderFromNameFunction · 0.85
KeyMapForFunction · 0.85
errNoKeyMapFunction · 0.85
StringParamMethod · 0.80
GetMethod · 0.45
WarningMethod · 0.45
ParseMethod · 0.45
InfoMethod · 0.45

Tested by

no test coverage detected