Skip to content

Commit

Permalink
check the konamicode in userspace
Browse files Browse the repository at this point in the history
  • Loading branch information
spikat committed Nov 17, 2022
1 parent 75b9500 commit c1eade1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*~
*.o
bin/

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ clean:
rm -fr ebpf/bin/
rm -f $(NAME)

run:
sudo $(NAME)
run: $(NAME)
sudo ./$(NAME)
45 changes: 37 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"os/signal"
"time"

manager "github.com/DataDog/ebpf-manager"
"github.com/sirupsen/logrus"
Expand All @@ -23,9 +24,39 @@ var m = &manager.Manager{
},
},
},
Maps: []*manager.Map{{
Name: "konamicode_activation_counter",
}},
}

func checkKonamicode() (uint32, error) {
m, _, err := m.GetMap("konamicode_activation_counter")
if err != nil {
logrus.Printf("checkKonamicode error: %v\n", err)
return 0, err
}
var key, val uint32
err = m.Lookup(&key, &val)
if err != nil {
logrus.Printf("checkKonamicode error: %v\n", err)
return 0, err
}
return val, nil
}

func start_konamicode_watcher() {
go func() {
konamicode_check := time.NewTicker(time.Second)

for {
select {
case _ = <-konamicode_check.C:
val, err := checkKonamicode()
if err != nil {
continue
} else if val != 0 {
logrus.Printf("KONAMI CODE ACTIVATED \\o/ !\n")
}
}
}
}()
}

func main() {
Expand All @@ -38,15 +69,13 @@ func main() {
if err := m.Start(); err != nil {
panic(fmt.Errorf("failed to start manager: %w", err))
}

defer m.Stop(manager.CleanAll)
logrus.Println("manager successfully started")

start_konamicode_watcher()

logrus.Println("=> Cmd+C to stop")
wait()

if err := m.Stop(manager.CleanAll); err != nil {
logrus.Fatal(err)
}
}

// wait - Waits until an interrupt or kill signal is sent
Expand Down

0 comments on commit c1eade1

Please sign in to comment.