From 1d3c16cd7b08e0f5e40a259493af966d4df50e77 Mon Sep 17 00:00:00 2001 From: Christopher Talib Date: Thu, 19 Dec 2019 16:02:30 +0100 Subject: [PATCH] First stream reader and answers is working --- ai/main.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ go.sum | 1 + main.go | 30 +++++++----------------------- 3 files changed, 61 insertions(+), 23 deletions(-) diff --git a/ai/main.go b/ai/main.go index 3831891..1d7ae5a 100644 --- a/ai/main.go +++ b/ai/main.go @@ -1 +1,54 @@ package ai + +import ( + "fmt" + "regexp" + "strings" + + "git.postblue.info/keygoller/utils" +) + +// ReadFromStream is the main AI function, it reads from the stream of the keys +// and then answers if some conditions are met. +func ReadFromStream(inputChan chan utils.InputEvent) { + var b strings.Builder + for { + data := <-inputChan + b.WriteString(data.KeyString()) + + switch b.String() { + case b.String(): + if findPassword(b.String()) { + fmt.Println("I LIKE YOUR PASSWORD") + b.Reset() + } + if findLove(b.String()) { + fmt.Println("I love you too...") + b.Reset() + } + default: + continue + + } + } +} + +func findPassword(input string) bool { + r, _ := regexp.Compile("PASSWORD") + + if ok := r.MatchString(input); ok { + return true + } + + return false +} + +func findLove(input string) bool { + r, _ := regexp.Compile("ILOVEYOU") + + if ok := r.MatchString(input); ok { + return true + } + + return false +} diff --git a/go.sum b/go.sum index db53863..706fe8d 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= diff --git a/main.go b/main.go index 7623999..1577da9 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "strings" "syscall" + "git.postblue.info/keygoller/ai" "git.postblue.info/keygoller/utils" "github.com/sirupsen/logrus" ) @@ -111,31 +112,13 @@ func (k *KeyLogger) Close() error { return k.fd.Close() } -func output(input InputStream) { - var res string - for { - if input.event.KeyString() != "" { - res += input.event.KeyString() - } - fmt.Println(res) - - } -} - -func join(strs ...string) string { - var sb strings.Builder - for _, str := range strs { - sb.WriteString(str) - } - return sb.String() -} - func main() { fmt.Println("Your keyboard input will be here: ", getKeyboard()) // TODO // !) get streaming data from keyboard // 2 unpackage the data to be human readable // 3 stream the data through an api + StreamChannel := make(chan utils.InputEvent) keyboard := getKeyboard() klog, err := New(keyboard) if err != nil { @@ -144,19 +127,20 @@ func main() { } defer klog.Close() events := klog.Read() - // stream := InputStream{} - var b strings.Builder + + go ai.ReadFromStream(StreamChannel) + for e := range events { switch e.Type { case utils.EvKey: if e.KeyPress() { - b.WriteString(e.KeyString()) + StreamChannel <- e } break default: - fmt.Println(b.String()) + continue } }