How to use MatchSyscall method of mgrconfig Package

Best Syzkaller code snippet using mgrconfig.MatchSyscall

load.go

Source:load.go Github

copy

Full Screen

1// Copyright 2015 syzkaller project authors. All rights reserved.2// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.3package mgrconfig4import (5 "fmt"6 "io/ioutil"7 "os"8 "path/filepath"9 "strings"10 "github.com/google/syzkaller/pkg/config"11 "github.com/google/syzkaller/pkg/osutil"12 "github.com/google/syzkaller/prog"13 _ "github.com/google/syzkaller/sys" // most mgrconfig users want targets too14 "github.com/google/syzkaller/sys/targets"15)16func LoadData(data []byte) (*Config, error) {17 cfg, err := LoadPartialData(data)18 if err != nil {19 return nil, err20 }21 if err := Complete(cfg); err != nil {22 return nil, err23 }24 return cfg, nil25}26func LoadFile(filename string) (*Config, error) {27 cfg, err := LoadPartialFile(filename)28 if err != nil {29 return nil, err30 }31 if err := Complete(cfg); err != nil {32 return nil, err33 }34 return cfg, nil35}36func LoadPartialData(data []byte) (*Config, error) {37 cfg := defaultValues()38 if err := config.LoadData(data, cfg); err != nil {39 return nil, err40 }41 return loadPartial(cfg)42}43func LoadPartialFile(filename string) (*Config, error) {44 cfg := defaultValues()45 if err := config.LoadFile(filename, cfg); err != nil {46 return nil, err47 }48 return loadPartial(cfg)49}50func defaultValues() *Config {51 return &Config{52 SSHUser: "root",53 Cover: true,54 Reproduce: true,55 Sandbox: "none",56 RPC: ":0",57 Procs: 1,58 }59}60func loadPartial(cfg *Config) (*Config, error) {61 var err error62 cfg.TargetOS, cfg.TargetVMArch, cfg.TargetArch, err = splitTarget(cfg.Target)63 if err != nil {64 return nil, err65 }66 return cfg, nil67}68func Complete(cfg *Config) error {69 if err := checkNonEmpty(70 cfg.TargetOS, "target",71 cfg.TargetVMArch, "target",72 cfg.TargetArch, "target",73 cfg.Workdir, "workdir",74 cfg.Syzkaller, "syzkaller",75 cfg.HTTP, "http",76 cfg.Type, "type",77 cfg.SSHUser, "ssh_user",78 ); err != nil {79 return err80 }81 cfg.Workdir = osutil.Abs(cfg.Workdir)82 if cfg.WorkdirTemplate != "" {83 cfg.WorkdirTemplate = osutil.Abs(cfg.WorkdirTemplate)84 if _, err := ioutil.ReadDir(cfg.WorkdirTemplate); err != nil {85 return fmt.Errorf("failed to read workdir_template: %v", err)86 }87 }88 if cfg.Image != "" {89 if !osutil.IsExist(cfg.Image) {90 return fmt.Errorf("bad config param image: can't find %v", cfg.Image)91 }92 cfg.Image = osutil.Abs(cfg.Image)93 }94 if err := completeBinaries(cfg); err != nil {95 return err96 }97 if cfg.Procs < 1 || cfg.Procs > 32 {98 return fmt.Errorf("bad config param procs: '%v', want [1, 32]", cfg.Procs)99 }100 switch cfg.Sandbox {101 case "none", "setuid", "namespace", "android":102 default:103 return fmt.Errorf("config param sandbox must contain one of none/setuid/namespace/android")104 }105 if err := checkSSHParams(cfg); err != nil {106 return err107 }108 cfg.CompleteKernelDirs()109 if cfg.HubClient != "" {110 if err := checkNonEmpty(111 cfg.Name, "name",112 cfg.HubAddr, "hub_addr",113 cfg.HubKey, "hub_key",114 ); err != nil {115 return err116 }117 }118 if cfg.DashboardClient != "" {119 if err := checkNonEmpty(120 cfg.Name, "name",121 cfg.DashboardAddr, "dashboard_addr",122 cfg.DashboardKey, "dashboard_key",123 ); err != nil {124 return err125 }126 }127 return nil128}129func checkNonEmpty(fields ...string) error {130 for i := 0; i < len(fields); i += 2 {131 if fields[i] == "" {132 return fmt.Errorf("config param %v is empty", fields[i+1])133 }134 }135 return nil136}137func (cfg *Config) CompleteKernelDirs() {138 cfg.KernelObj = osutil.Abs(cfg.KernelObj)139 if cfg.KernelSrc == "" {140 cfg.KernelSrc = cfg.KernelObj // assume in-tree build by default141 }142 cfg.KernelSrc = osutil.Abs(cfg.KernelSrc)143 if cfg.KernelBuildSrc == "" {144 cfg.KernelBuildSrc = cfg.KernelSrc145 }146 cfg.KernelBuildSrc = osutil.Abs(cfg.KernelBuildSrc)147}148func checkSSHParams(cfg *Config) error {149 if cfg.SSHKey == "" {150 return nil151 }152 info, err := os.Stat(cfg.SSHKey)153 if err != nil {154 return err155 }156 if info.Mode()&0077 != 0 {157 return fmt.Errorf("sshkey %v is unprotected, ssh will reject it, do chmod 0600", cfg.SSHKey)158 }159 cfg.SSHKey = osutil.Abs(cfg.SSHKey)160 return nil161}162func completeBinaries(cfg *Config) error {163 sysTarget := targets.Get(cfg.TargetOS, cfg.TargetArch)164 if sysTarget == nil {165 return fmt.Errorf("unsupported OS/arch: %v/%v", cfg.TargetOS, cfg.TargetArch)166 }167 cfg.Syzkaller = osutil.Abs(cfg.Syzkaller)168 exe := sysTarget.ExeExtension169 targetBin := func(name, arch string) string {170 return filepath.Join(cfg.Syzkaller, "bin", cfg.TargetOS+"_"+arch, name+exe)171 }172 cfg.SyzFuzzerBin = targetBin("syz-fuzzer", cfg.TargetVMArch)173 cfg.SyzExecprogBin = targetBin("syz-execprog", cfg.TargetVMArch)174 cfg.SyzExecutorBin = targetBin("syz-executor", cfg.TargetArch)175 if !osutil.IsExist(cfg.SyzFuzzerBin) {176 return fmt.Errorf("bad config syzkaller param: can't find %v", cfg.SyzFuzzerBin)177 }178 if !osutil.IsExist(cfg.SyzExecprogBin) {179 return fmt.Errorf("bad config syzkaller param: can't find %v", cfg.SyzExecprogBin)180 }181 if !osutil.IsExist(cfg.SyzExecutorBin) {182 return fmt.Errorf("bad config syzkaller param: can't find %v", cfg.SyzExecutorBin)183 }184 return nil185}186func splitTarget(target string) (string, string, string, error) {187 if target == "" {188 return "", "", "", fmt.Errorf("target is empty")189 }190 targetParts := strings.Split(target, "/")191 if len(targetParts) != 2 && len(targetParts) != 3 {192 return "", "", "", fmt.Errorf("bad config param target")193 }194 os := targetParts[0]195 vmarch := targetParts[1]196 arch := targetParts[1]197 if len(targetParts) == 3 {198 arch = targetParts[2]199 }200 return os, vmarch, arch, nil201}202func ParseEnabledSyscalls(target *prog.Target, enabled, disabled []string) ([]int, error) {203 syscalls := make(map[int]bool)204 if len(enabled) != 0 {205 for _, c := range enabled {206 n := 0207 for _, call := range target.Syscalls {208 if matchSyscall(call.Name, c) {209 syscalls[call.ID] = true210 n++211 }212 }213 if n == 0 {214 return nil, fmt.Errorf("unknown enabled syscall: %v", c)215 }216 }217 } else {218 for _, call := range target.Syscalls {219 syscalls[call.ID] = true220 }221 }222 for call := range syscalls {223 if target.Syscalls[call].Attrs.Disabled {224 delete(syscalls, call)225 }226 }227 for _, c := range disabled {228 n := 0229 for _, call := range target.Syscalls {230 if matchSyscall(call.Name, c) {231 delete(syscalls, call.ID)232 n++233 }234 }235 if n == 0 {236 return nil, fmt.Errorf("unknown disabled syscall: %v", c)237 }238 }239 if len(syscalls) == 0 {240 return nil, fmt.Errorf("all syscalls are disabled by disable_syscalls in config")241 }242 var arr []int243 for id := range syscalls {244 arr = append(arr, id)245 }246 return arr, nil247}248func matchSyscall(name, pattern string) bool {249 if pattern == name || strings.HasPrefix(name, pattern+"$") {250 return true251 }252 if len(pattern) > 1 && pattern[len(pattern)-1] == '*' &&253 strings.HasPrefix(name, pattern[:len(pattern)-1]) {254 return true255 }256 return false257}...

Full Screen

Full Screen

MatchSyscall

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 m = mgrconfig.NewMonitorConfig()4 m.MatchSyscall("socket")5 fmt.Println(m)6}7import (8func main() {9 m = mgrconfig.NewMonitorConfig()10 m.MatchSyscall("socket")11 m.MatchSyscall("bind")12 fmt.Println(m)13}14import (15func main() {16 m = mgrconfig.NewMonitorConfig()17 m.MatchSyscall("socket")18 m.MatchSyscall("bind")19 m.MatchSyscall("connect")20 fmt.Println(m)21}22import (23func main() {24 m = mgrconfig.NewMonitorConfig()25 m.MatchSyscall("socket")26 m.MatchSyscall("bind")27 m.MatchSyscall("connect")28 m.MatchSyscall("listen")29 fmt.Println(m)30}31import (32func main() {33 m = mgrconfig.NewMonitorConfig()34 m.MatchSyscall("socket")35 m.MatchSyscall("bind")36 m.MatchSyscall("connect")37 m.MatchSyscall("listen")38 m.MatchSyscall("accept")39 fmt.Println(m)40}

Full Screen

Full Screen

MatchSyscall

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 matchSyscall = mgrconfig.MatchSyscall{4 }5 fmt.Println(matchSyscall)6}7import (8func main() {9 matchSyscall = mgrconfig.MatchSyscall{10 }11 fmt.Println(matchSyscall)12}13import (14func main() {15 matchSyscall = mgrconfig.MatchSyscall{16 }17 fmt.Println(matchSyscall)18}19import (20func main() {21 matchSyscall = mgrconfig.MatchSyscall{22 }23 fmt.Println(matchSyscall)24}25import (26func main() {27 matchSyscall = mgrconfig.MatchSyscall{28 }29 fmt.Println(matchSyscall)30}31import (

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful