1
0

Rewrited for kingpin command line arguments parser

This commit is contained in:
dump_stack() 2018-10-26 18:26:43 +00:00
parent 2e9a8018da
commit c86a80d702
2 changed files with 38 additions and 12 deletions

View File

@ -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

45
main.go
View File

@ -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)
}
}