How to use generateParticularCall method of prog Package

Best Syzkaller code snippet using prog.generateParticularCall

rand.go

Source:rand.go Github

copy

Full Screen

...244 // Now we have a set of candidate calls that can create the necessary resource.245 for i := 0; i < 1e3; i++ {246 // Generate one of them.247 meta := metas[r.Intn(len(metas))]248 calls := r.generateParticularCall(s, meta)249 s1 := newState(r.target, s.ct)250 s1.analyze(calls[len(calls)-1])251 // Now see if we have what we want.252 var allres []Arg253 for kind1, res1 := range s1.resources {254 if r.target.isCompatibleResource(kind, kind1) {255 allres = append(allres, res1...)256 }257 }258 if len(allres) != 0 {259 // Bingo!260 arg := MakeResultArg(res, allres[r.Intn(len(allres))], 0)261 return arg, calls262 }263 // Discard unsuccessful calls.264 // Note: s.ma/va have already noted allocations of the new objects265 // in discarded syscalls, ideally we should recreate state266 // by analyzing the program again.267 for _, c := range calls {268 ForeachArg(c, func(arg Arg, _ *ArgCtx) {269 if a, ok := arg.(*ResultArg); ok && a.Res != nil {270 delete(*a.Res.(ArgUsed).Used(), arg)271 }272 })273 }274 }275 // Generally we can loop several times, e.g. when we choose a call that returns276 // the resource in an array, but then generateArg generated that array of zero length.277 // But we must succeed eventually.278 var ctors []string279 for _, meta := range metas {280 ctors = append(ctors, meta.Name)281 }282 panic(fmt.Sprintf("failed to create a resource %v with %v",283 res.Desc.Kind[0], strings.Join(ctors, ", ")))284}285func (r *randGen) generateText(kind TextKind) []byte {286 switch kind {287 case Text_arm64:288 // Just a stub, need something better.289 text := make([]byte, 50)290 for i := range text {291 text[i] = byte(r.Intn(256))292 }293 return text294 default:295 cfg := createIfuzzConfig(kind)296 return ifuzz.Generate(cfg, r.Rand)297 }298}299func (r *randGen) mutateText(kind TextKind, text []byte) []byte {300 switch kind {301 case Text_arm64:302 return mutateData(r, text, 40, 60)303 default:304 cfg := createIfuzzConfig(kind)305 return ifuzz.Mutate(cfg, r.Rand, text)306 }307}308func createIfuzzConfig(kind TextKind) *ifuzz.Config {309 cfg := &ifuzz.Config{310 Len: 10,311 Priv: true,312 Exec: true,313 MemRegions: []ifuzz.MemRegion{314 {0 << 12, 1 << 12},315 {1 << 12, 1 << 12},316 {2 << 12, 1 << 12},317 {3 << 12, 1 << 12},318 {4 << 12, 1 << 12},319 {5 << 12, 1 << 12},320 {6 << 12, 1 << 12},321 {7 << 12, 1 << 12},322 {8 << 12, 1 << 12},323 {9 << 12, 1 << 12},324 {0xfec00000, 0x100}, // ioapic325 },326 }327 switch kind {328 case Text_x86_real:329 cfg.Mode = ifuzz.ModeReal16330 case Text_x86_16:331 cfg.Mode = ifuzz.ModeProt16332 case Text_x86_32:333 cfg.Mode = ifuzz.ModeProt32334 case Text_x86_64:335 cfg.Mode = ifuzz.ModeLong64336 }337 return cfg338}339// nOutOf returns true n out of outOf times.340func (r *randGen) nOutOf(n, outOf int) bool {341 if n <= 0 || n >= outOf {342 panic("bad probability")343 }344 v := r.Intn(outOf)345 return v < n346}347func (r *randGen) generateCall(s *state, p *Prog) []*Call {348 idx := 0349 if s.ct == nil {350 idx = r.Intn(len(r.target.Syscalls))351 } else {352 // 如果p.call为空,那么随机选择一个函数;否则从现有的函数中随机选择一个函数,353 // 根据这个函数的优先级列表随机生成函数;354 call := -1355 if len(p.Calls) != 0 {356 call = p.Calls[r.Intn(len(p.Calls))].Meta.ID357 }358 idx = s.ct.Choose(r.Rand, call)359 }360 meta := r.target.Syscalls[idx]361 return r.generateParticularCall(s, meta)362}363func (r *randGen) myGenerateCall(s *state, p *Prog) []*Call {364 idx := 0365 if s.ct == nil {366 idx = r.Intn(len(r.target.Syscalls))367 } else {368 // 如果p.call为空,那么随机选择一个函数;否则从现有的函数中随机选择一个函数,369 // 根据这个函数的优先级列表随机生成函数;370 call := -1371 if len(p.Calls) != 0 {372 // 选择最后一个函数373 call = p.Calls[len(p.Calls)-1].Meta.ID374 }375 // 全为0,重新选择函数376 if call != -1 && s.ct.run[call][len(r.target.Syscalls)-1] == 0 {377 call = -1378 }379 // 从选择的函数中选择下一个函数的下标380 idx = s.ct.MyChoose(r.Rand, call)381 }382 meta := r.target.Syscalls[idx]383 return r.generateParticularCall(s, meta)384}385func (r *randGen) generateParticularCall(s *state, meta *Syscall) (calls []*Call) {386 c := &Call{387 Meta: meta,388 Ret: MakeReturnArg(meta.Ret),389 }390 c.Args, calls = r.generateArgs(s, meta.Args)391 r.target.assignSizesCall(c)392 calls = append(calls, c)393 for _, c1 := range calls {394 r.target.SanitizeCall(c1)395 }396 return calls397}398// GenerateAllSyzProg generates a program that contains all pseudo syz_ calls for testing.399func (target *Target) GenerateAllSyzProg(rs rand.Source) *Prog {400 p := &Prog{401 Target: target,402 }403 r := newRand(target, rs)404 s := newState(target, nil)405 handled := make(map[string]bool)406 for _, meta := range target.Syscalls {407 if !strings.HasPrefix(meta.CallName, "syz_") || handled[meta.CallName] {408 continue409 }410 handled[meta.CallName] = true411 calls := r.generateParticularCall(s, meta)412 for _, c := range calls {413 s.analyze(c)414 p.Calls = append(p.Calls, c)415 }416 }417 if err := p.validate(); err != nil {418 panic(err)419 }420 return p421}422// GenerateSimpleProg generates the simplest non-empty program for testing423// (e.g. containing a single mmap).424func (target *Target) GenerateSimpleProg() *Prog {425 return &Prog{...

Full Screen

Full Screen

any_test.go

Source:any_test.go Github

copy

Full Screen

...21 continue22 }23 for i := 0; i < iters; i++ {24 s := newState(target, ct, nil)25 calls := r.generateParticularCall(s, meta)26 p := &Prog{Target: target, Calls: calls}27 for _, arg := range p.complexPtrs() {28 compl[arg.Res.Type().String()] = true29 }30 }31 }32 var arr []string33 for id := range compl {34 arr = append(arr, id)35 }36 sort.Strings(arr)37 t.Log("complex types:\n" + strings.Join(arr, "\n"))38}39func TestSquash(t *testing.T) {...

Full Screen

Full Screen

generation.go

Source:generation.go Github

copy

Full Screen

...37 s := newState(target, ct, corpus)38 for _, c := range p.Calls[:insertPos] {39 s.analyze(c)40 }41 calls := r.generateParticularCall(s, meta)42 for _, c := range calls {43 s.analyze(c)44 }45 // trim the rest46 // for _, c := range p.Calls[insertPos:len(p.Calls)] {47 // s.analyze(c)48 // calls = append(calls, c)49 // }50 p.Calls = append(p.Calls[:insertPos], calls...)51 p.sanitizeFix()52 p.debugValidate()53 return p54}55func (target *Target) GenerateValidProgram2(rs rand.Source, meta *Syscall, ct *ChoiceTable) *Prog {56 p := &Prog{57 Target: target,58 }59 r := newRand(target, rs)60 r.generate = true61 s := newState(target, ct, nil)62 calls := r.generateParticularCall(s, meta)63 for _, c := range calls {64 s.analyze(c)65 p.Calls = append(p.Calls, c)66 }67 p.sanitizeFix()68 p.debugValidate()69 return p70}...

Full Screen

Full Screen

generateParticularCall

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println(prog.generateParticularCall())4}5import "fmt"6func main() {7 fmt.Println(prog.generateParticularCall())8}9import "fmt"10func main() {11 fmt.Println(prog.generateParticularCall())12}13import "fmt"14func main() {15 fmt.Println(prog.generateParticularCall())16}17import "fmt"18func main() {19 fmt.Println(prog.generateParticularCall())20}21import "fmt"22func main() {23 fmt.Println(prog.generateParticularCall())24}25import "fmt"26func main() {27 fmt.Println(prog.generateParticularCall())28}29import "fmt"30func main() {31 fmt.Println(prog.generateParticularCall())32}33import "fmt"34func main() {35 fmt.Println(prog.generateParticularCall())36}37import "fmt"38func main() {39 fmt.Println(prog.generateParticularCall())40}41import "fmt"42func main() {43 fmt.Println(prog.generateParticularCall())44}45import "fmt"46func main() {47 fmt.Println(prog.generateParticularCall())48}49import "fmt

Full Screen

Full Screen

generateParticularCall

Using AI Code Generation

copy

Full Screen

1import (2func main() {3prog.GenerateParticularCall()4}5import (6func main() {7prog.GenerateParticularCall()8}9import (10func GenerateParticularCall() {11fmt.Println("GenerateParticularCall")12}

Full Screen

Full Screen

generateParticularCall

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 prog := NewProg()4 prog.generateParticularCall(2)5}6import (7type Prog struct {8}9func NewProg() *Prog {10 return &Prog{}11}12func (p *Prog) generateParticularCall(a int) {13 fmt.Println(a)14}

Full Screen

Full Screen

generateParticularCall

Using AI Code Generation

copy

Full Screen

1func main() {2 prog.generateParticularCall("test", "test", "test", "test", "test")3}4func main() {5 prog.generateParticularCall("test", "test", "test", "test", "test")6}7func main() {8 prog.generateParticularCall("test", "test", "test", "test", "test")9}10func main() {11 prog.generateParticularCall("test", "test", "test", "test", "test")12}13func main() {14 prog.generateParticularCall("test", "test", "test", "test", "test")15}16func main() {17 prog.generateParticularCall("test", "test", "test", "test", "test")18}19func main() {20 prog.generateParticularCall("test", "test", "test", "test", "test")21}22func main() {23 prog.generateParticularCall("test", "test", "test", "test", "test")24}25func main() {26 prog.generateParticularCall("test", "test", "test", "test", "test")27}28func main() {29 prog.generateParticularCall("test", "test", "test", "test", "test")

Full Screen

Full Screen

generateParticularCall

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 prog := program.Prog{}4 prog.GenerateParticularCall()5}6import (7func main() {8 prog := program.Prog{}9 prog.GenerateParticularCall()10}11import (12func main() {13 prog := program.Prog{}14 prog.GenerateParticularCall()15}16import (17func main() {18 prog := program.Prog{}19 prog.GenerateParticularCall()20}21import (22func main() {23 prog := program.Prog{}24 prog.GenerateParticularCall()25}26import (27func main() {28 prog := program.Prog{}29 prog.GenerateParticularCall()30}31import (32func main() {33 prog := program.Prog{}34 prog.GenerateParticularCall()35}36import (37func main() {38 prog := program.Prog{}39 prog.GenerateParticularCall()40}41import (

Full Screen

Full Screen

generateParticularCall

Using AI Code Generation

copy

Full Screen

1func generateParticularCall(prog *ssa.Program, methodName string, paramCount int) *ssa.Function {2 mainPkg := prog.Package(prog.Created[0].Pkg.Pkg)3 mainFunc := mainPkg.Func("main")4 mainBody := mainFunc.Blocks[0].Instrs[0].(*ssa.Call).Common().Value.(*ssa.Function).Blocks[0]5 for _, instr := range mainBody.Instrs {6 if call, ok := instr.(*ssa.Call); ok {7 method := call.Common().Value.(*ssa.Function)8 if method.Name() == methodName {9 if len(method.Params) == paramCount {10 }11 }12 }13 }14}15func generateParticularCall(prog *ssa.Program, methodName string, paramCount int) *ssa.Function {16 mainPkg := prog.Package(prog.Created[0].Pkg.Pkg)17 mainFunc := mainPkg.Func("main")18 mainBody := mainFunc.Blocks[0].Instrs[0].(*ssa.Call).Common().Value.(*ssa.Function).Blocks[0]19 for _, instr := range mainBody.Instrs {

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