ebpf-challenge/GetRuntimeAddresses/main.go
Özgür Kesim 7af1728eed Cleanup done and documtation added
symbolyze.go has been simplified and cleaned up.  It now also is documented,
f.e.:

 % go doc Scanner
package symbolyze // import "."

type Scanner struct {
	*log.Logger // Embedded logger

	// Has unexported fields.
}
    Scanner represents an engine for scanning for a specific symbol in all
    ELF-files matching a certain pattern. The pattern is described in
    fileapth.Match().

    Once a Scanner is created with New(), it should be populated with Observer
    functions using OnFound(). Optionally, the scanner can be put into debugging
    mode by a call to DebugOn() prior to a call to Run().

    A call to Scanner.Run() then starts the engine and it will scan all pids in
    /proc. Whenever a match is found, all observers will be called with the
    (pid, offset), concurrently.

func New(symbol, pathglob string) *Scanner
func (S *Scanner) DebugOn()
func (S *Scanner) OnFound(fun Observer)
func (S *Scanner) Run() error
2020-01-15 23:26:30 +01:00

44 lines
881 B
Go

package main
import (
"fmt"
"os"
"github.com/optimyze-interviews/OezguerKesim/GetRuntimeAddresses/ebpf"
"github.com/optimyze-interviews/OezguerKesim/GetRuntimeAddresses/symbolyze"
)
func main() {
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)
//
// Solution to your tasks goes here
//
scanner := symbolyze.New("_PyRuntime", "*python3*")
scanner.OnFound(mapFD.Set)
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)
}