ebpf-challenge/GetRuntimeAddresses/main.go
Özgür Kesim d800683dce RunEvery() and better Error-handling added
1. symbolyze.Scanner now implements the RunEvery(time.Duration) method
   that will call scanner.Run() periodically.  It should be called to
   run in its own goroutine.  The loop can be stopped by calling
   scanner.Stop().

2. The scanner now collects all errors from all observers in a private
   error type `errors []error`. It's Error() returns a cumulated list of
   errors, seperated by a newline.
2020-01-18 20:27:23 +01:00

57 lines
1.2 KiB
Go

package main
import (
"flag"
"fmt"
"os"
"time"
"github.com/optimyze-interviews/OezguerKesim/GetRuntimeAddresses/ebpf"
"github.com/optimyze-interviews/OezguerKesim/GetRuntimeAddresses/symbolyze"
)
var (
symbol = flag.String("symbol", "_PyRuntime", "Symbol to search for")
glob = flag.String("glob", "*python3*", "pattern an ELF-file must match (see filepath.Match)")
debug = flag.Bool("debug", false, "run in debug mode")
)
func main() {
flag.Parse()
mapFD, err := ebpf.CreateMap()
if err != nil {
fmt.Printf("Failed to create eBPF map: %s\n", err)
os.Exit(1)
}
fmt.Printf("Created eBPF map (FD: %d)\n", mapFD)
scanner := symbolyze.NewScanner(*symbol, *glob)
scanner.OnFound(mapFD.Set)
scanner.Debug(*debug)
go scanner.RunEvery(time.Second)
time.Sleep(10 * time.Second)
scanner.Stop()
err = scanner.Run()
if err != nil {
fmt.Printf("Failed to run the symbolyze scanner: %s", err)
os.Exit(1)
}
mapContents, err := mapFD.GetMap()
if err != nil {
fmt.Printf("Failed to get the map contents: %s", err)
os.Exit(1)
}
fmt.Printf("Printing contents of map %d\n", mapFD)
for k, v := range mapContents {
fmt.Printf("\t%d -> 0x%x\n", k, v)
}
os.Exit(0)
}