2020-01-14 15:32:06 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-01-16 00:02:59 +01:00
|
|
|
"flag"
|
2020-01-14 15:32:06 +01:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2020-01-18 20:27:23 +01:00
|
|
|
"time"
|
2020-01-14 15:32:06 +01:00
|
|
|
|
|
|
|
"github.com/optimyze-interviews/OezguerKesim/GetRuntimeAddresses/ebpf"
|
2020-01-15 20:42:53 +01:00
|
|
|
"github.com/optimyze-interviews/OezguerKesim/GetRuntimeAddresses/symbolyze"
|
2020-01-14 15:32:06 +01:00
|
|
|
)
|
|
|
|
|
2020-01-16 00:02:59 +01:00
|
|
|
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")
|
|
|
|
)
|
|
|
|
|
2020-01-14 15:32:06 +01:00
|
|
|
func main() {
|
2020-01-16 00:02:59 +01:00
|
|
|
flag.Parse()
|
|
|
|
|
2020-01-14 15:32:06 +01:00
|
|
|
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)
|
|
|
|
|
2020-01-16 00:13:03 +01:00
|
|
|
scanner := symbolyze.NewScanner(*symbol, *glob)
|
2020-01-15 23:26:30 +01:00
|
|
|
scanner.OnFound(mapFD.Set)
|
2020-01-18 20:27:23 +01:00
|
|
|
scanner.Debug(*debug)
|
|
|
|
|
|
|
|
go scanner.RunEvery(time.Second)
|
|
|
|
|
|
|
|
time.Sleep(10 * time.Second)
|
|
|
|
scanner.Stop()
|
2020-01-16 00:02:59 +01:00
|
|
|
|
2020-01-15 23:26:30 +01:00
|
|
|
err = scanner.Run()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Failed to run the symbolyze scanner: %s", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2020-01-15 12:48:36 +01:00
|
|
|
|
2020-01-15 19:04:56 +01:00
|
|
|
mapContents, err := mapFD.GetMap()
|
2020-01-14 15:32:06 +01:00
|
|
|
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)
|
|
|
|
}
|