1
0

{artifact,distro}Type unmarshalling

This commit is contained in:
dump_stack() 2018-10-07 08:28:31 +00:00
parent dfcd11c549
commit 46122397b5

28
main.go
View File

@ -13,6 +13,7 @@ import (
"os/exec" "os/exec"
"regexp" "regexp"
"runtime" "runtime"
"strings"
"time" "time"
"github.com/logrusorgru/aurora" "github.com/logrusorgru/aurora"
@ -39,6 +40,19 @@ func (at artifactType) String() string {
return [...]string{"module", "exploit"}[at] return [...]string{"module", "exploit"}[at]
} }
func (at *artifactType) UnmarshalTOML(data []byte) (err error) {
stype := strings.Trim(string(data), `"`)
stypelower := strings.ToLower(stype)
if strings.Contains(stypelower, "module") {
*at = KernelModule
} else if strings.Contains(stypelower, "exploit") {
*at = KernelExploit
} else {
err = errors.New(fmt.Sprintf("Type %s is unsupported", stype))
}
return
}
type artifact struct { type artifact struct {
Name string Name string
Type artifactType Type artifactType
@ -77,6 +91,20 @@ func (dt distroType) String() string {
return [...]string{"Ubuntu", "CentOS", "Debian"}[dt] return [...]string{"Ubuntu", "CentOS", "Debian"}[dt]
} }
func (dt *distroType) UnmarshalTOML(data []byte) (err error) {
sDistro := strings.Trim(string(data), `"`)
if strings.EqualFold(sDistro, "Ubuntu") {
*dt = Ubuntu
} else if strings.EqualFold(sDistro, "CentOS") {
*dt = CentOS
} else if strings.EqualFold(sDistro, "Debian") {
*dt = Debian
} else {
err = errors.New(fmt.Sprintf("Distro %s is unsupported", sDistro))
}
return
}
type kernelInfo struct { type kernelInfo struct {
DistroType distroType DistroType distroType
DistroRelease string // 18.04/7.4.1708/9.1 DistroRelease string // 18.04/7.4.1708/9.1