How to use calcResourceCtors method of prog Package

Best Syzkaller code snippet using prog.calcResourceCtors

resources.go

Source:resources.go Github

copy

Full Screen

...9var timespecRes = &ResourceDesc{10 Name: "timespec",11 Kind: []string{"timespec"},12}13func (target *Target) calcResourceCtors(kind []string, precise bool) []*Syscall {14 //fmt.Printf("calcResourceCtors: kind=%+v\n", kind)15 // Find calls that produce the necessary resources.16 var metas []*Syscall17 for _, meta := range target.Syscalls {18 // Recurse into arguments to see if there is an out/inout arg of necessary type.19 ok := false20 //if meta.Name != "pipe$9p" { continue }21 //fmt.Printf("found pipe$9p\n")22 ForeachType(meta, func(typ Type) {23 if ok {24 return25 }26 switch typ1 := typ.(type) {27 case *ResourceType:28 //fmt.Printf(" output: %+v\n", typ1.Desc.Kind)29 if typ1.Dir() != DirIn && isCompatibleResourceImpl(kind, typ1.Desc.Kind, precise) {30 ok = true31 }32 }33 })34 if ok {35 metas = append(metas, meta)36 }37 }38 if kind[0] == timespecRes.Name {39 if c := target.SyscallMap["clock_gettime"]; c != nil {40 metas = append(metas, c)41 }42 }43 return metas44}45// isCompatibleResource returns true if resource of kind src can be passed as an argument of kind dst.46func (target *Target) isCompatibleResource(dst, src string) bool {47 if dst == target.any.res16.TypeName ||48 dst == target.any.res32.TypeName ||49 dst == target.any.res64.TypeName ||50 dst == target.any.resdec.TypeName ||51 dst == target.any.reshex.TypeName ||52 dst == target.any.resoct.TypeName {53 return true54 }55 dstRes := target.resourceMap[dst]56 if dstRes == nil {57 panic(fmt.Sprintf("unknown resource '%v'", dst))58 }59 srcRes := target.resourceMap[src]60 if srcRes == nil {61 panic(fmt.Sprintf("unknown resource '%v'", src))62 }63 return isCompatibleResourceImpl(dstRes.Kind, srcRes.Kind, false)64}65// isCompatibleResourceImpl returns true if resource of kind src can be passed as an argument of kind dst.66// If precise is true, then it does not allow passing a less specialized resource (e.g. fd)67// as a more specialized resource (e.g. socket). Otherwise it does.68func isCompatibleResourceImpl(dst, src []string, precise bool) bool {69 //fmt.Printf("isCompatibleResourceImpl: %+v/%v vs %+v/%v\n", dst, len(dst), src, len(src))70 if len(dst) > len(src) {71 // dst is more specialized, e.g dst=socket, src=fd.72 if precise {73 //fmt.Printf(" = false1\n")74 return false75 }76 dst = dst[:len(src)]77 }78 if len(src) > len(dst) {79 // src is more specialized, e.g dst=fd, src=socket.80 src = src[:len(dst)]81 }82 for i, k := range dst {83 if k != src[i] {84 //fmt.Printf(" = false2\n")85 return false86 }87 }88 //fmt.Printf(" = true\n")89 return true90}91func (target *Target) inputResources(c *Syscall) []*ResourceDesc {92 var resources []*ResourceDesc93 ForeachType(c, func(typ Type) {94 if typ.Dir() == DirOut {95 return96 }97 switch typ1 := typ.(type) {98 case *ResourceType:99 if !typ1.IsOptional {100 resources = append(resources, typ1.Desc)101 }102 case *StructType:103 if target.OS == "linux" && (typ1.Name() == "timespec" || typ1.Name() == "timeval") {104 resources = append(resources, timespecRes)105 }106 }107 })108 return resources109}110func (target *Target) outputResources(c *Syscall) []*ResourceDesc {111 var resources []*ResourceDesc112 ForeachType(c, func(typ Type) {113 switch typ1 := typ.(type) {114 case *ResourceType:115 if typ1.Dir() != DirIn {116 resources = append(resources, typ1.Desc)117 }118 }119 })120 if c.CallName == "clock_gettime" {121 resources = append(resources, timespecRes)122 }123 return resources124}125func (target *Target) TransitivelyEnabledCalls(enabled map[*Syscall]bool) (map[*Syscall]bool, map[*Syscall]string) {126 supported := make(map[*Syscall]bool)127 disabled := make(map[*Syscall]string)128 canCreate := make(map[string]bool)129 inputResources := make(map[*Syscall][]*ResourceDesc)130 for c := range enabled {131 inputResources[c] = target.inputResources(c)132 if c.Name == "pipe$9p" {133 fmt.Printf("%v: input resource: %+v\n", c.Name, inputResources[c])134 }135 }136 for {137 n := len(supported)138 for c := range enabled {139 if supported[c] {140 continue141 }142 ready := true143 for _, res := range inputResources[c] {144 if !canCreate[res.Name] {145 ready = false146 break147 }148 }149 if ready {150 supported[c] = true151 for _, res := range target.outputResources(c) {152 for _, kind := range res.Kind {153 canCreate[kind] = true154 }155 }156 }157 }158 if n == len(supported) {159 break160 }161 }162 ctors := make(map[string][]string)163 for c := range enabled {164 if supported[c] {165 continue166 }167 for _, res := range inputResources[c] {168 if canCreate[res.Name] {169 continue170 }171 if ctors[res.Name] == nil {172 var names []string173 for _, call := range target.calcResourceCtors(res.Kind, true) {174 names = append(names, call.Name)175 }176 ctors[res.Name] = names177 }178 disabled[c] = fmt.Sprintf("no syscalls can create resource %v,"+179 " enable some syscalls that can create it %v",180 res.Name, ctors[res.Name])181 break182 }183 }184 if len(enabled) != len(supported)+len(disabled) {185 panic("lost syscalls")186 }187 return supported, disabled...

Full Screen

Full Screen

calcResourceCtors

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 conf := config.LoadFile("test.tf")4 graph := terraform.NewGraph(conf, nil)5 program := terraform.NewProgram(graph, nil)6 resourceCtors := program.CalcResourceCtors()7 for _, resourceCtor := range resourceCtors {8 fmt.Println(resourceCtor)9 }10}11resource "aws_instance" "web" {12 tags {13 }14}15resource "aws_security_group" "allow_all" {16 ingress {

Full Screen

Full Screen

calcResourceCtors

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 prog.CalcResourceCtors()4 fmt.Println(prog.ResourceCtors)5}6import (7func main() {8 prog.CalcResourceCtors()9 fmt.Println(prog.ResourceCtors)10}11import (12func main() {13 prog.CalcResourceCtors()14 fmt.Println(prog.ResourceCtors)15}16import (17func main() {18 prog.CalcResourceCtors()19 fmt.Println(prog.ResourceCtors)20}21import (22func main() {23 prog.CalcResourceCtors()24 fmt.Println(prog.ResourceCtors)25}26import (27func main() {28 prog.CalcResourceCtors()29 fmt.Println(prog.ResourceCtors)30}31import (32func main() {33 prog.CalcResourceCtors()34 fmt.Println(prog.ResourceCtors)35}

Full Screen

Full Screen

calcResourceCtors

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(aws.Prog().CalcResourceCtors())4}5import (6func main() {7 fmt.Println(aws.Prog().CalcResourceCtors())8}

Full Screen

Full Screen

calcResourceCtors

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p := terraform.NewContext(nil)4 fmt.Println(p.CalcResourceCtors())5}6import (7func main() {8 fmt.Println(terraform.NewContext(nil).Prog().CalcResourceCtors())9}10import (11func main() {12 p := terraform.NewContext(nil).Prog()13 fmt.Println(p.CalcResourceCtors())14}15import (16func main() {17 p := terraform.NewContext(nil).Prog()18 fmt.Println(p.CalcResourceCtors())19}20import (21func main() {22 p := terraform.NewContext(nil)23 fmt.Println(p.CalcResourceCtors())24}25import (26func main() {27 p := terraform.NewContext(nil)28 fmt.Println(p.CalcResourceCtors())29}30import (31func main() {32 p := terraform.NewContext(nil)33 fmt.Println(p.CalcResourceCtors())34}35import (

Full Screen

Full Screen

calcResourceCtors

Using AI Code Generation

copy

Full Screen

1func main() {2 p := prog.CreateFromFiles(build.Default, "src", nil, "net/http")3 for _, ct := range p.CalcResourceCtors() {4 fmt.Printf("%v5 }6}7net/http.(*Client).Do8net/http.(*Client).Get9net/http.(*Client).Head10net/http.(*Client).Post11net/http.(*Client).PostForm12net/http.(*Client).Do13net/http.(*Client).Get14net/http.(*Client).Head15net/http.(*Client).Post16net/http.(*Client).PostForm17net/http.(*Client).Do18net/http.(*Client).Get19net/http.(*Client).Head20net/http.(*Client).Post21net/http.(*Client).PostForm22net/http.(*Client).Do23net/http.(*Client).Get24net/http.(*Client).Head25net/http.(*Client).Post26net/http.(*Client).PostForm27net/http.(*Client).Do28net/http.(*Client).Get29net/http.(*Client).Head30net/http.(*Client).Post31net/http.(*Client).PostForm32net/http.(*Client).Do33net/http.(*Client).Get34net/http.(*Client).Head35net/http.(*Client).Post36net/http.(*Client).PostForm37net/http.(*Client).Do38net/http.(*Client).Get39net/http.(*Client).Head40net/http.(*Client).Post41net/http.(*Client).PostForm42net/http.(*Client).Do43net/http.(*Client).Get44net/http.(*Client).Head45net/http.(*Client).Post46net/http.(*Client).PostForm47net/http.(*Client).Do48net/http.(*Client).Get49net/http.(*Client).Head50net/http.(*Client).Post51net/http.(*Client).PostForm52net/http.(*Client).Do53net/http.(*Client).Get54net/http.(*Client).Head55net/http.(*Client).Post56net/http.(*Client).PostForm57net/http.(*Client).Do58net/http.(*Client).Get59net/http.(*Client).Head60net/http.(*Client).Post61net/http.(*Client).PostForm62net/http.(*Client).Do63net/http.(*Client).Get64net/http.(*Client).Head65net/http.(*Client).Post66net/http.(*Client).PostForm67net/http.(*Client).Do68net/http.(*

Full Screen

Full Screen

calcResourceCtors

Using AI Code Generation

copy

Full Screen

1for (ResourceCtor rc : prog.calcResourceCtors()) {2 System.out.println(rc);3}4public static void main(java.lang.String[])5public static void main(java.lang.String[], java.lang.String[])6public static void main(java.lang.String[], java.lang.String[], java.lang.String[])7public static void main(java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[])8public static void main(java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[])9public static void main(java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[])10public static void main(java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[])11public static void main(java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[])

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