begin implementing an interactive command line interface

This commit is contained in:
kayos 2021-06-14 18:15:50 -07:00
parent 6a95824ae2
commit 9909426150
6 changed files with 56 additions and 21 deletions

1
go.mod

@ -4,6 +4,7 @@ go 1.16
require (
git.tcp.direct/kayos/prototooth v0.3.1-0.20210513000132-e440008138af
git.tcp.direct/kayos/sh3lly v0.0.0-20210614235113-d19f8c64b302
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/godbus/dbus/v5 v5.0.4 // indirect
github.com/muka/go-bluetooth v0.0.0-20201211051136-07f31c601d33 // indirect

19
go.sum

@ -13,11 +13,15 @@ cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiy
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
git.tcp.direct/kayos/prototooth v0.3.1-0.20210513000132-e440008138af h1:+J2MfTQvW1DmX1HYIQUsrCd5l0Il9JMYTOowIs8ju1Y=
git.tcp.direct/kayos/prototooth v0.3.1-0.20210513000132-e440008138af/go.mod h1:kk4oyPgWq6Rijn30Js4ITQC5DFwmpyzWL3+8V6q9wdM=
git.tcp.direct/kayos/sh3lly v0.0.0-20210614235113-d19f8c64b302 h1:ZZPHkn3LszFqSYo6eV1gSHUX0ToVDWbipid+iDRIGnQ=
git.tcp.direct/kayos/sh3lly v0.0.0-20210614235113-d19f8c64b302/go.mod h1:VTiCCb2FCmHdDmLIa4cSqAVW6WISZUwekgTzybxbGx8=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/JuulLabs-OSS/cbgo v0.0.2 h1:gCDyT0+EPuI8GOFyvAksFcVD2vF4CXBAVwT6uVnD9oo=
github.com/JuulLabs-OSS/cbgo v0.0.2/go.mod h1:L4YtGP+gnyD84w7+jN66ncspFRfOYB5aj9QSXaFHmBA=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/Zaba505/sand v1.3.0 h1:FiEhK2r5Pu7F/p+YGKj7+Ig2n12tVOdGJY+5MY3a5Fw=
github.com/Zaba505/sand v1.3.0/go.mod h1:dSKum/Od9vOx061yXMm03HGEs4cUc+PakZF3NSTIgrY=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
@ -68,6 +72,7 @@ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfU
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s=
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@ -126,10 +131,18 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
@ -142,6 +155,8 @@ github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:F
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/muesli/termenv v0.8.1 h1:9q230czSP3DHVpkaPDXGp0TOfAwyjyYwXlUCQxQSaBk=
github.com/muesli/termenv v0.8.1/go.mod h1:kzt/D/4a88RoheZmwfqorY3A+tnsSMA9HJC/fQSFKo0=
github.com/muka/go-bluetooth v0.0.0-20200619025933-f6113f7141c5/go.mod h1:yV39+EVOWdnoTe75NyKdo9iuyI3Slyh4t7eQvElUbWE=
github.com/muka/go-bluetooth v0.0.0-20201211051136-07f31c601d33 h1:p3srutpE8TpQmOUQ5Qw94jYFUdoG2jBbILeYLroQNoI=
github.com/muka/go-bluetooth v0.0.0-20201211051136-07f31c601d33/go.mod h1:dMCjicU6vRBk34dqOmIZm0aod6gUwZXOXzBROqGous0=
@ -172,6 +187,8 @@ github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
@ -195,6 +212,7 @@ github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v0.0.7/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
@ -302,6 +320,7 @@ golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

24
main.go

@ -11,6 +11,7 @@ import (
"syscall"
"time"
"git.tcp.direct/kayos/sh3lly"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
@ -72,9 +73,13 @@ func sigHandler() {
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
log.Warn().Msg("Interrupt detected, shutting down gracefully...")
eros.Slumber()
os.Exit(0)
log.Warn().Msg("Interrupt detected, stopping scan...")
for _, scan := range protogen.ScanMgr.Scans {
scan.Stop()
}
//eros.Slumber()
//os.Exit(0)
}()
}
@ -126,10 +131,9 @@ func earToTheWire() {
}
}
for {
select {
case postcard := <- protogen.ScanMgr.Mailbox:
case postcard := <-protogen.ScanMgr.Mailbox:
sublog = log.With().Int("scan_id", postcard.From).Logger()
interpret(postcard)
}
@ -137,8 +141,7 @@ func earToTheWire() {
}
}
func main() {
defer eros.Slumber()
func bleScan() {
var scan *protogen.Scan
// Note: the tinygo bluetooth (prototooth here) library does already have a channel system for starting and stopping scans
@ -151,5 +154,10 @@ func main() {
//time.Sleep(30 * time.Millisecond)
go dust.Must("Scan", scan.Start())
}
func main() {
defer eros.Slumber()
sh3lly.MainPrompt = "ProtoMolecule > "
sh3lly.StartCLI(ProtoHandler)
}

@ -2,19 +2,15 @@ package blueStuff
import "git.tcp.direct/kayos/prototooth"
//controls connections to found devices to get service characteristics
//TODO: disable the scan adapter, enable the attack adapter (this step pmight not be needed)
// controls connections to found devices to get service characteristics
// TODO: disable the scan adapter, enable the attack adapter (this step pmight not be needed)
// use the result.LocalName passed from scanStuff to start connection
// once connected, for list of service characteristics and check for read / write for each
// loog all of this to eros
func pathways(target bluetooth.ScanResult) {
println("Discovery")
//device, err := projVars.ScanAdapter.Connect(bluetooth.ScanResult.Address, bluetooth.ConnectionParams{})
//srvcs, err := projVars.ScanAdapter.
}

@ -9,7 +9,12 @@ import (
func Must(action string, err error) {
if err != nil {
log.Fatal().Err(err).Str("action", action).Msg("FATAL_ERROR")
switch err.Error() {
case "AdapterExists: Launch helper exited with unknown return code 1":
log.Error().Msg("Is your bluetooth adapter enabled? Linux: is bluetoothd started?")
default:
log.Fatal().Err(err).Str("action", action).Msg("FATAL_ERROR")
}
}
}

@ -3,9 +3,9 @@ package protogen
import (
projVars "protomolecule/src/vars"
"protomolecule/src/eros"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"protomolecule/src/eros"
bluetooth "git.tcp.direct/kayos/prototooth"
@ -50,7 +50,7 @@ func (s *Scan) NewDevice(name string, addr string, manuf string, rssi int16) *er
newid := len(s.Devices)
s.Devices[newid] = &eros.Device{
Name: name,
Addr: addr,
Addr: addr,
Manufacturer: manuf,
RSSIlast: rssi,
}
@ -153,7 +153,7 @@ func (s *Scan) resultHandler(scanAdapter *bluetooth.Adapter, result bluetooth.Sc
Msg("EROS_RECALL")
}
//Services level logging
// Service enumeration and storage
// TODO:
// Fix Logging output here -- Prob shouldnt output this much info
// for each service discovered
@ -198,7 +198,6 @@ func (s *Scan) resultHandler(scanAdapter *bluetooth.Adapter, result bluetooth.Sc
sublog.Info().Str("Adapter", "Attempting Connection").Msg("ADAPTER_STATUS")
// TODO: re-assess the timeout mechanism
// this is largely going to depend on how concurrent we can get (at least with only one ble adapter)
@ -299,6 +298,15 @@ func (s *Scan) resultHandler(scanAdapter *bluetooth.Adapter, result bluetooth.Sc
//TODO: stop scan and call bluestuff func and pass it the local name value
}
func (s *Scan) Stop() error {
// TODO: fix this adapterId situation
err := projVars.ScanAdapter.StopScan()
if err != nil {
return err
}
return nil
}
func (s *Scan) Start() error {
s.Started = time.Now()
@ -314,7 +322,6 @@ func (s *Scan) Start() error {
adapterId := projVars.ScanAdapter.ID
log.Info().
Str("ID", adapterId).
Bool("MODE_TRACK", projVars.TrackingMode).
@ -326,6 +333,5 @@ func (s *Scan) Start() error {
return err
}
return nil
}