How to use CallSet method of prog Package

Best Syzkaller code snippet using prog.CallSet

call_selector.go

Source:call_selector.go Github

copy

Full Screen

1// Copyright 2018 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 proggen4import (5 "bytes"6 "github.com/google/syzkaller/prog"7 "github.com/google/syzkaller/tools/syz-trace2syz/parser"8 "strconv"9 "unicode"10)11var discriminatorArgs = map[string][]int{12 "bpf": {0},13 "fcntl": {1},14 "ioprio_get": {0},15 "socket": {0, 1, 2},16 "socketpair": {0, 1, 2},17 "ioctl": {0, 1},18 "getsockopt": {1, 2},19 "setsockopt": {1, 2},20 "accept": {0},21 "accept4": {0},22 "bind": {0},23 "connect": {0},24 "recvfrom": {0},25 "sendto": {0},26 "sendmsg": {0},27 "getsockname": {0},28 "openat": {1},29}30var openDiscriminatorArgs = map[string]int{31 "open": 0,32 "openat": 1,33 "syz_open_dev": 0,34}35type callSelector interface {36 Select(call *parser.Syscall) *prog.Syscall37}38func newSelectors(target *prog.Target, returnCache returnCache) []callSelector {39 sc := newSelectorCommon(target, returnCache)40 return []callSelector{41 &defaultCallSelector{sc},42 &openCallSelector{sc},43 }44}45type selectorCommon struct {46 target *prog.Target47 returnCache returnCache48 callCache map[string][]*prog.Syscall49}50func newSelectorCommon(target *prog.Target, returnCache returnCache) *selectorCommon {51 return &selectorCommon{52 target: target,53 returnCache: returnCache,54 callCache: make(map[string][]*prog.Syscall),55 }56}57// matches strace file string with a constant string in openat or syz_open_dev58// if the string in openat or syz_open_dev has a # then this method will59// return the corresponding id from the strace string60func (cs *selectorCommon) matchFilename(syzFile, straceFile []byte) (bool, int) {61 syzFile = bytes.Trim(syzFile, "\x00")62 straceFile = bytes.Trim(straceFile, "\x00")63 if len(syzFile) != len(straceFile) {64 return false, -165 }66 var id []byte67 dev := -168 for i, c := range syzFile {69 x := straceFile[i]70 if c == x {71 continue72 }73 if c != '#' || !unicode.IsDigit(rune(x)) {74 return false, -175 }76 id = append(id, x)77 }78 if len(id) > 0 {79 dev, _ = strconv.Atoi(string(id))80 }81 return true, dev82}83// callSet returns all syscalls with the given name.84func (cs *selectorCommon) callSet(callName string) []*prog.Syscall {85 calls, ok := cs.callCache[callName]86 if ok {87 return calls88 }89 for _, call := range cs.target.Syscalls {90 if call.CallName == callName {91 calls = append(calls, call)92 }93 }94 cs.callCache[callName] = calls95 return calls96}97type openCallSelector struct {98 *selectorCommon99}100// Select returns the best matching descrimination for this syscall.101func (cs *openCallSelector) Select(call *parser.Syscall) *prog.Syscall {102 if _, ok := openDiscriminatorArgs[call.CallName]; !ok {103 return nil104 }105 for callName := range openDiscriminatorArgs {106 for _, variant := range cs.callSet(callName) {107 match, devID := cs.matchOpen(variant, call)108 if !match {109 continue110 }111 if call.CallName == "open" && callName == "openat" {112 cwd := parser.Constant(cs.target.ConstMap["AT_FDCWD"])113 call.Args = append([]parser.IrType{cwd}, call.Args...)114 return variant115 }116 if match && call.CallName == "open" && callName == "syz_open_dev" {117 if devID < 0 {118 return variant119 }120 args := []parser.IrType{call.Args[0], parser.Constant(uint64(devID))}121 call.Args = append(args, call.Args[1:]...)122 return variant123 }124 }125 }126 return nil127}128func (cs *openCallSelector) matchOpen(meta *prog.Syscall, call *parser.Syscall) (bool, int) {129 straceFileArg := call.Args[openDiscriminatorArgs[call.CallName]]130 straceBuf := straceFileArg.(*parser.BufferType).Val131 syzFileArg := meta.Args[openDiscriminatorArgs[meta.CallName]].Type132 if _, ok := syzFileArg.(*prog.PtrType); !ok {133 return false, -1134 }135 syzBuf := syzFileArg.(*prog.PtrType).Elem.(*prog.BufferType)136 if syzBuf.Kind != prog.BufferString {137 return false, -1138 }139 for _, val := range syzBuf.Values {140 match, devID := cs.matchFilename([]byte(val), []byte(straceBuf))141 if match {142 return match, devID143 }144 }145 return false, -1146}147type defaultCallSelector struct {148 *selectorCommon149}150// Select returns the best matching descrimination for this syscall.151func (cs *defaultCallSelector) Select(call *parser.Syscall) *prog.Syscall {152 var match *prog.Syscall153 discriminators := discriminatorArgs[call.CallName]154 if len(discriminators) == 0 {155 return nil156 }157 score := 0158 for _, meta := range cs.callSet(call.CallName) {159 if score1 := cs.matchCall(meta, call, discriminators); score1 > score {160 match, score = meta, score1161 }162 }163 return match164}165// matchCall returns match score between meta and call.166// Higher score means better match, -1 if they are not matching at all.167func (cs *defaultCallSelector) matchCall(meta *prog.Syscall, call *parser.Syscall, discriminators []int) int {168 score := 0169 for _, i := range discriminators {170 if i >= len(meta.Args) || i >= len(call.Args) {171 return -1172 }173 typ := meta.Args[i].Type174 arg := call.Args[i]175 switch t := typ.(type) {176 case *prog.ConstType:177 // Consts must match precisely.178 constant, ok := arg.(parser.Constant)179 if !ok || constant.Val() != t.Val {180 return -1181 }182 score += 10183 case *prog.FlagsType:184 // Flags may or may not match, but matched flags increase score.185 constant, ok := arg.(parser.Constant)186 if !ok {187 return -1188 }189 val := constant.Val()190 for _, v := range t.Vals {191 if v == val {192 score++193 break194 }195 }196 case *prog.ResourceType:197 // Resources must match one of subtypes,198 // the more precise match, the higher the score.199 retArg := cs.returnCache.get(t, arg)200 if retArg == nil {201 return -1202 }203 matched := false204 for i, kind := range retArg.Type().(*prog.ResourceType).Desc.Kind {205 if kind == t.Desc.Name {206 score += i + 1207 matched = true208 break209 }210 }211 if !matched {212 return -1213 }214 case *prog.PtrType:215 switch r := t.Elem.(type) {216 case *prog.BufferType:217 matched := false218 buffer, ok := arg.(*parser.BufferType)219 if !ok {220 return -1221 }222 if r.Kind != prog.BufferString {223 return -1224 }225 for _, val := range r.Values {226 matched, _ = cs.matchFilename([]byte(val), []byte(buffer.Val))227 if matched {228 score++229 break230 }231 }232 if !matched {233 return -1234 }235 }236 }237 }238 return score239}...

Full Screen

Full Screen

CallSet

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if err != nil {4 log.Fatal(err)5 }6 privateKey, err := crypto.HexToECDSA("2e1b1c8d8e3b0f1b3d3f3b0c8d6e1e0b7f1d0d1c8d1c1c1d0c0d0c0b2e1f1b")7 if err != nil {8 log.Fatal(err)9 }10 publickey := privateKey.Public()11 publickeyECDSA, ok := publickey.(*ecdsa.PublicKey)12 if !ok {13 log.Fatal("error casting public key to ECDSA")14 }15 fromAddress := crypto.PubkeyToAddress(*publickeyECDSA)16 nonce, err := client.PendingNonceAt(context.Background(), fromAddress)17 if err != nil {18 log.Fatal(err)19 }20 gasPrice, err := client.SuggestGasPrice(context.Background())21 if err != nil {22 log.Fatal(err)23 }24 auth := bind.NewKeyedTransactor(privateKey)25 auth.Nonce = big.NewInt(int64(nonce))26 address := common.HexToAddress("0x0e7e4c1f4d4d4b0f4b0f4b0f4b0f4b0f4b0f4b0f")27 instance, err := NewProg(address, client)28 if err != nil {

Full Screen

Full Screen

CallSet

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(prog.CallSet())4}5import (6func CallSet() []int {7 s := make([]int, 0, 10)8 for i := 0; i < 10; i++ {9 s = append(s, i)10 }11 fmt.Println(s)12}

Full Screen

Full Screen

CallSet

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 beego.Router("/test", &testController{})4 beego.Run()5}6type testController struct {7}8func (this *testController) Get() {9 this.Ctx.WriteString("hello world")10}11func (this *testController) Post() {12 this.Ctx.WriteString("hello world")13}14func (this *testController) CallSet() {15 this.Ctx.WriteString("hello world")16}17func (this *testController) CallGet() {18 this.Ctx.WriteString("hello world")19}20func (this *testController) CallPost() {21 this.Ctx.WriteString("hello world")22}23func (this *testController) CallDelete() {24 this.Ctx.WriteString("hello world")25}26func (this *testController) CallPatch() {27 this.Ctx.WriteString("hello world")28}29func (this *testController) CallHead() {30 this.Ctx.WriteString("hello world")31}32func (this *testController) CallOptions() {33 this.Ctx.WriteString("hello world")34}35func (this *testController) CallPut() {36 this.Ctx.WriteString("hello world")37}38func (this *testController) CallTrace() {39 this.Ctx.WriteString("hello world")40}41func (this *testController) CallConnect() {42 this.Ctx.WriteString("hello world")43}44func (this *testController) CallOther() {45 this.Ctx.WriteString("hello world")46}47func (this *testController) CallCustom() {48 this.Ctx.WriteString("hello world")49}50func (this *testController) CallCustom2() {51 this.Ctx.WriteString("hello world")52}53import (54func main() {55 beego.Router("/test", &testController{})56 beego.Run()57}58type testController struct {59}60func (this *testController) Get() {61 this.Ctx.WriteString("

Full Screen

Full Screen

CallSet

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p.CallSet()4 fmt.Println(p)5}6import (7type Prog struct {8}9func (p *Prog) Set() {10 fmt.Println("Set")11}12func (p *Prog) CallSet() {13 p.Set()14}

Full Screen

Full Screen

CallSet

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 vm := otto.New()4 vm.Run(`5 function test() {6 return "Hello World!";7 }8 value, _ := vm.Call("test", nil)9 fmt.Println(value.String())10}11import (12func main() {13 vm := otto.New()14 vm.Run(`15 function test() {16 return "Hello World!";17 }18 value, _ := vm.Call("test", nil, "Hello", "World")19 fmt.Println(value.String())20}21import (22func main() {23 vm := otto.New()24 vm.Run(`25 function test() {26 return "Hello World!";27 }28 value, _ := vm.Call("test", nil, "Hello", "World")29 fmt.Println(value.String())30}

Full Screen

Full Screen

CallSet

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p := prog.Prog{}4 p.CallSet()5 fmt.Println("Hello, world.")6}7import (8func (p *Prog) CallSet() {9 p.Set()10}11func (p *Prog) Set() {12 fmt.Println("in Set method")13}14prog/prog.go:10: cannot use p (type *Prog) as type Prog in argument to p.Set15prog/prog.go:10: cannot use p (type *Prog) as type Prog in argument to p.Set

Full Screen

Full Screen

CallSet

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 prog := program.Prog{}4 prog.CallSet()5 fmt.Println(prog.Get())6}7import (8func main() {9 prog := program.Prog{}10 prog.Set("Hello World!")11 fmt.Println(prog.Get())12}13import (14func main() {15 prog := program.Prog{}16 prog.Set("Hello World!")17 fmt.Println(prog.Get())18}19import (20func main() {21 prog := program.Prog{}22 prog.Set("Hello World!")23 fmt.Println(prog.Get())24}25import (26func main() {27 prog := program.Prog{}28 prog.Set("Hello World!")29 fmt.Println(prog.Get())30}31import (32func main() {33 prog := program.Prog{}34 prog.Set("Hello World!")35 fmt.Println(prog.Get())36}37import (38func main() {39 prog := program.Prog{}40 prog.Set("Hello World!")41 fmt.Println(prog.Get())42}43import (44func main() {45 prog := program.Prog{}46 prog.Set("Hello World!")47 fmt.Println(prog.Get())48}49import (50func main() {51 prog := program.Prog{}52 prog.Set("Hello World!")53 fmt.Println(prog.Get())54}55import (56func main() {

Full Screen

Full Screen

CallSet

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p.CallSet()4 fmt.Println("Hello, playground")5}6import (7func main() {8 p.CallSet()9 fmt.Println("Hello, playground")10}11import (12func main() {13 p.CallGet()14 fmt.Println("Hello, playground")15}16import (17func main() {18 p.CallGetSet()19 fmt.Println("Hello, playground")20}21import (22func main() {23 p.CallGetSet()24 fmt.Println("Hello, playground")25}26import (27func main() {28 p.CallGetSet()29 fmt.Println("Hello, playground")30}31import (32func main() {33 p.CallGetSet()34 fmt.Println("Hello, playground")35}36import (

Full Screen

Full Screen

CallSet

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 a.CallSet()4}5import "fmt"6func main() {7 a.CallSetPointer()8}9import "fmt"10func main() {11 a.CallSetPointerToFunction()12}13import "fmt"14func main() {15 a.CallSetFunction()16}

Full Screen

Full Screen

CallSet

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 obj := new(prog.Prog)4 obj.CallSet()5 fmt.Println("Value of the variable6 obj.GetVar())7}8import (9func main() {10 obj := new(prog.Prog)11 obj.Call()12}13import (14type Prog struct {15}16func (obj *Prog) SetVar() {17}18func (obj *Prog) PrintVar() {19 fmt.Println("Value of the variable20}21func (obj *Prog) CallSet() {22 obj.SetVar()23}24func (obj *Prog) Call() {25 obj.PrintVar()26}

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.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful