diff --git a/README.md b/README.md index 5293a01..1484ec5 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,10 @@ If you already have Go, Qemu, Vagrant and Docker installed, there's cross-platfo $ rm -rf {Debian,CentOS,Ubuntu/{14.04,18.04}} # speed up :) $ ./bootstrap.sh $ # wait several hours... + $ export OUT_OF_TREE_KERNELS_CONFIG=$GOPATH/src/github.com/jollheef/out-of-tree/tools/kernel-factory/output/kernels.toml $ cd ../../examples/kernel-exploit $ # test kernel exploit - $ out-of-tree + $ out-of-tree pew $ cd ../kernel-module $ # test kernel module - $ out-of-tree + $ out-of-tree pew diff --git a/main.go b/main.go index 562a693..ab67d41 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,7 @@ import ( "github.com/naoina/toml" "github.com/otiai10/copy" "github.com/remeh/sizedwaitgroup" + kingpin "gopkg.in/alecthomas/kingpin.v2" qemu "github.com/jollheef/out-of-tree/qemu" ) @@ -404,16 +405,7 @@ func exists(path string) bool { return true } -func main() { - ka, err := readArtifactConfig(".out-of-tree.toml") - if err != nil { - log.Fatalln(err) - } - - if ka.SourcePath == "" { - ka.SourcePath = "." - } - +func oldmain() { kcfgEnv := "OUT_OF_TREE_KERNELS_CONFIG" kcfgPath := os.Getenv(kcfgEnv) if !exists(kcfgPath) { @@ -424,6 +416,18 @@ func main() { log.Fatalln("Please specify kernels config path in " + kcfgEnv) } +} + +func pewHandler(workPath, kcfgPath string) (err error) { + ka, err := readArtifactConfig(workPath + "/.out-of-tree.toml") + if err != nil { + log.Fatalln(err) + } + + if ka.SourcePath == "" { + ka.SourcePath = workPath + } + kcfg, err := readKernelConfig(kcfgPath) if err != nil { log.Fatalln(err) @@ -433,4 +437,25 @@ func main() { if err != nil { log.Fatalln(err) } + + return +} + +func main() { + pewCommand := kingpin.Command("pew", "Build, run and test module/exploit") + path := pewCommand.Arg( + "path", "Path to work directory").Default(".").ExistingDir() + kernelsConfig := pewCommand.Flag( + "kernels-config", "Path to kernels config").Envar( + "OUT_OF_TREE_KERNELS_CONFIG").Required().ExistingFile() + + var err error + switch kingpin.Parse() { + case "pew": + err = pewHandler(*path, *kernelsConfig) + } + + if err != nil { + log.Println(err) + } }