How to use replaceArg method of prog Package

Best Syzkaller code snippet using prog.replaceArg

prog.go

Source:prog.go Github

copy

Full Screen

...298 newCalls = append(newCalls, p.Calls[idx+1:]...)299 }300 p.Calls = newCalls301}302// replaceArg replaces arg with arg1 in a program.303func replaceArg(arg, arg1 Arg) {304 log.Logf(3, "In replaceArg: replacing %s with %s\n", arg, arg1)305 switch a := arg.(type) {306 case *ConstArg:307 *a = *arg1.(*ConstArg)308 case *ResultArg:309 replaceResultArg(a, arg1.(*ResultArg))310 case *PointerArg:311 *a = *arg1.(*PointerArg)312 case *UnionArg:313 *a = *arg1.(*UnionArg)314 case *DataArg:315 *a = *arg1.(*DataArg)316 case *GroupArg:317 a1 := arg1.(*GroupArg)318 size := len(a.Inner)319 if len(a.Inner) > len(a1.Inner) {320 // panic(fmt.Sprintf("replaceArg: group fields don't match: %v/%v",321 // len(a.Inner), len(a1.Inner)))322 fmt.Sprintf("replaceArg: group fields don't match: %v/%v",323 len(a.Inner), len(a1.Inner))324 size = len(a1.Inner)325 }326 a.ArgCommon = a1.ArgCommon327 for i := 0; i < size; i++ {328 replaceArg(a.Inner[i], a1.Inner[i])329 }330 default:331 panic(fmt.Sprintf("replaceArg: bad arg kind %#v", arg))332 }333}334func replaceResultArg(arg, arg1 *ResultArg) {335 // Remove link from `a.Res` to `arg`.336 if arg.Res != nil {337 delete(arg.Res.uses, arg)338 }339 // Copy all fields from `arg1` to `arg` except for the list of args that use `arg`.340 uses := arg.uses341 *arg = *arg1342 arg.uses = uses343 // Make the link in `arg.Res` (which is now `Res` of `arg1`) to point to `arg` instead of `arg1`.344 if arg.Res != nil {345 resUses := arg.Res.uses...

Full Screen

Full Screen

splice.go

Source:splice.go Github

copy

Full Screen

...63 chosenIdx := sort.Search(len(mt.args), func(i int) bool { return mt.args[i].priority >= goal })64 arg := mt.args[chosenIdx]65 return arg.arg, arg.ctx, chosenIdx66}67func replaceArg(arg, arg1 prog.Arg) {68 if arg == arg1 {69 panic("same arg")70 }71 fmt.Printf("\nReplacing\n%s\nwith\n%s\n", arg, arg1)72 switch a := arg.(type) {73 case *prog.ConstArg:74 *a = *arg1.(*prog.ConstArg)75 case *prog.ResultArg:76 // replaceResultArg(a, arg1.(*prog.ResultArg))77 case *prog.PointerArg:78 *a = *arg1.(*prog.PointerArg)79 case *prog.UnionArg:80 *a = *arg1.(*prog.UnionArg)81 case *prog.DataArg:82 *a = *arg1.(*prog.DataArg)83 case *prog.GroupArg:84 a1 := arg1.(*prog.GroupArg)85 if len(a.Inner) != len(a1.Inner) {86 panic(fmt.Sprintf("replaceArg: group fields don't match: %v/%v",87 len(a.Inner), len(a1.Inner)))88 }89 a.ArgCommon = a1.ArgCommon90 for i := range a.Inner {91 replaceArg(a.Inner[i], a1.Inner[i])92 }93 default:94 panic(fmt.Sprintf("replaceArg: bad arg kind %#v", arg))95 }96}97func parseArg(p *prog.Prog) map[string]mutationTypes {98 argMap := make(map[string]mutationTypes)99 for _, c := range p.Calls {100 fmt.Printf("syscall: %s\n", c.Meta.Name)101 mt := &mutationTypes{target: p.Target, prioSum: float64(0)}102 prog.ForeachArg(c, mt.collectTypes)103 for _, aa := range mt.args {104 fmt.Printf("This is the arg: %s(%T): %s\n", aa.arg.Type().String(), aa.arg, aa.arg)105 }106 argMap[c.Meta.Name] = *mt107 }108 return argMap109}110func logArgMap(argMap map[string]mutationTypes) {111 for syscall, mt := range argMap {112 fmt.Printf("in syscall %s\n", syscall)113 for _, aa := range mt.args {114 fmt.Printf("This is the arg: %s(%T)\n", aa.arg.Type().String(), aa.arg)115 }116 }117}118func getSimilarTypes(a, b map[string]mutationTypes) map[string]*mutationTypes {119 sameArg := make(map[string]*mutationTypes)120 prioSum := float64(0)121 for syscallA, mtA := range a {122 for syscallB, mtB := range b {123 if syscallA == syscallB {124 Mts := &mutationTypes{}125 Mts.args = make([]mutationType, 0)126 Mts.similarArgs = make([]mutationType, 0)127 for _, argA := range mtA.args {128 for _, argB := range mtB.args {129 if argA.arg.Type().String() == argB.arg.Type().String() {130 fmt.Printf("Adding: %s\n", argA.arg.Type().String())131 prioSum += argA.prio132 Mts.args = append(Mts.args, mutationType{argA.arg, argA.ctx, prioSum, argA.prio})133 Mts.similarArgs = append(Mts.similarArgs, argB)134 }135 }136 }137 Mts.target = mtA.target138 Mts.prioSum = prioSum139 if len(Mts.args) == 0 {140 continue141 }142 sameArg[syscallA] = Mts143 }144 }145 }146 return sameArg147}148func main() {149 flag.Parse()150 if *flagPoc == "" {151 fmt.Printf("please specify the poc by -poc\n")152 os.Exit(1)153 }154 target, err := prog.GetTarget(*flagOS, *flagArch)155 if err != nil {156 fmt.Fprintf(os.Stderr, "%v", err)157 os.Exit(1)158 }159 seed := time.Now().UnixNano()160 rs := rand.NewSource(seed)161 r := rand.New(rs)162 var syscalls map[*prog.Syscall]bool163 if *flagEnable != "" {164 enabled := strings.Split(*flagEnable, ",")165 syscallsIDs, err := mgrconfig.ParseEnabledSyscalls(target, enabled, nil)166 if err != nil {167 fmt.Fprintf(os.Stderr, "failed to parse enabled syscalls: %v", err)168 os.Exit(1)169 }170 syscalls = make(map[*prog.Syscall]bool)171 for _, id := range syscallsIDs {172 syscalls[target.Syscalls[id]] = true173 }174 var disabled map[*prog.Syscall]string175 syscalls, disabled = target.TransitivelyEnabledCalls(syscalls)176 for c, reason := range disabled {177 fmt.Fprintf(os.Stderr, "disabling %v: %v\n", c.Name, reason)178 }179 }180 data, err := ioutil.ReadFile(*flagPoc)181 if err != nil {182 fmt.Fprintf(os.Stderr, "failed to read prog file: %v\n", err)183 os.Exit(1)184 }185 poc, err := target.Deserialize(data, prog.NonStrict)186 if err != nil {187 fmt.Fprintf(os.Stderr, "failed to deserialize the program: %v\n", err)188 os.Exit(1)189 }190 PocArgMaps := parseArg(poc)191 // logArgMap(PocArgMaps)192 var p *prog.Prog193 if flag.NArg() == 0 {194 fmt.Printf("please specify the input to be mutated\n")195 os.Exit(-1)196 } else {197 data, err := ioutil.ReadFile(flag.Arg(0))198 if err != nil {199 fmt.Fprintf(os.Stderr, "failed to read prog file: %v\n", err)200 os.Exit(1)201 }202 p, err = target.Deserialize(data, prog.NonStrict)203 pOriginal := p.Clone()204 if err != nil {205 fmt.Fprintf(os.Stderr, "failed to deserialize the program: %v\n", err)206 os.Exit(1)207 }208 fmt.Printf("Original input: %s\n", p.Serialize())209 SeedArgMaps := parseArg(p)210 // logArgMap(SeedArgMaps)211 SimilarArgMap := getSimilarTypes(SeedArgMaps, PocArgMaps)212 fmt.Printf("size of similar ArgMap : %v\n", len(SimilarArgMap))213 if len(SimilarArgMap) == 0 {214 fmt.Printf("Not similar inputs\n")215 return216 }217 // choose syscall218 sumPrio := float64(0)219 for _, mts := range SimilarArgMap {220 sumPrio += mts.prioSum221 }222 goal := sumPrio * rand.Float64()223 var syscall string224 sumPrio = float64(0)225 for sys, mts := range SimilarArgMap {226 sumPrio += mts.prioSum227 if sumPrio > goal {228 syscall = sys229 break230 }231 }232 fmt.Printf("Splicing syscall %s\n", syscall)233 targetMt := SimilarArgMap[syscall]234 if len(targetMt.args) == 0 {235 fmt.Printf("no similar args")236 return237 }238 for {239 arg, _, chosenIdx := targetMt.chooseType(r)240 targetArg := targetMt.similarArgs[chosenIdx].arg241 if _, ok := arg.(*prog.UnionArg); ok {242 fmt.Printf("Replacing UnionArg\n")243 fmt.Printf("Replacing %s\n", arg.Type().String())244 fmt.Printf("Before Mutation:\n%s\n", p.Serialize())245 replaceArg(arg, targetArg)246 fmt.Printf("After Mutation:\n%s\n", p.Serialize())247 } else if argGroup, ok := arg.(*prog.GroupArg); ok {248 for idx, inner := range argGroup.Inner {249 // 3 outof 10 to mutate the inner250 switch inner.Type().(type) {251 case *prog.UnionType, *prog.IntType, *prog.PtrType,252 *prog.FlagsType, *prog.LenType,253 *prog.VmaType, *prog.BufferType, *prog.ArrayType:254 targetArgGroup := targetArg.(*prog.GroupArg)255 if r.Intn(10) < 3 {256 fmt.Printf("Replacing %s(%T)\n", arg.Type().String(), inner.Type())257 fmt.Printf("Before Mutation:\n%s\n", p.Serialize())258 replaceArg(argGroup.Inner[idx], targetArgGroup.Inner[idx])259 fmt.Printf("After Mutation:\n%s\n", p.Serialize())260 }261 }262 }263 } else {264 panic("Unknown arg")265 }266 if r.Intn(5) < 3 {267 break268 }269 }270 fmt.Printf("\nBefore mutation:\n%s\n", pOriginal.Serialize())271 fmt.Printf("This is poc:\n%s\n", poc.Serialize())272 fmt.Printf("after mutation:\n%s\n", p.Serialize())...

Full Screen

Full Screen

sss.go

Source:sss.go Github

copy

Full Screen

...41// delete(resUses, arg1)42// resUses[arg] = true43// }44// }45func replaceArg(arg, arg1 prog.Arg) {46 switch a := arg.(type) {47 case *prog.ConstArg:48 *a = *arg1.(*prog.ConstArg)49 case *prog.ResultArg:50 // replaceResultArg(a, arg1.(*prog.ResultArg))51 case *prog.PointerArg:52 *a = *arg1.(*prog.PointerArg)53 case *prog.UnionArg:54 *a = *arg1.(*prog.UnionArg)55 case *prog.DataArg:56 *a = *arg1.(*prog.DataArg)57 case *prog.GroupArg:58 a1 := arg1.(*prog.GroupArg)59 if len(a.Inner) != len(a1.Inner) {60 panic(fmt.Sprintf("replaceArg: group fields don't match: %v/%v",61 len(a.Inner), len(a1.Inner)))62 }63 a.ArgCommon = a1.ArgCommon64 for i := range a.Inner {65 replaceArg(a.Inner[i], a1.Inner[i])66 }67 default:68 panic(fmt.Sprintf("replaceArg: bad arg kind %#v", arg))69 }70}71func parseArg(p *prog.Prog) map[string][]prog.Arg {72 argMap := make(map[string][]prog.Arg)73 for _, c := range p.Calls {74 args := make([]prog.Arg, 0)75 prog.ForeachArg(c, func(arg prog.Arg, ctx *prog.ArgCtx) {76 switch arg.Type().(type) {77 case *prog.UnionType, *prog.ConstType, *prog.IntType,78 *prog.FlagsType, *prog.LenType, *prog.CsumType,79 *prog.VmaType, *prog.BufferType, *prog.ArrayType:80 fmt.Printf("adding %s\n", arg.Type().String())81 args = append(args, arg)82 }83 })84 argMap[c.Meta.Name] = args85 }86 return argMap87}88func logArgMap(argMap map[string][]prog.Arg) {89 for syscall, args := range argMap {90 fmt.Printf("in syscall %s\n", syscall)91 for _, arg := range args {92 fmt.Printf("arg Type %s, template: %s (%T)\n", arg.Type().String(), arg.Type().TemplateName(), arg)93 }94 }95}96func main() {97 flag.Parse()98 if *flagPoc == "" {99 fmt.Printf("please specify the poc by -poc\n")100 os.Exit(1)101 }102 target, err := prog.GetTarget(*flagOS, *flagArch)103 if err != nil {104 fmt.Fprintf(os.Stderr, "%v", err)105 os.Exit(1)106 }107 seed := time.Now().UnixNano()108 rs := rand.NewSource(seed)109 r := rand.New(rs)110 var syscalls map[*prog.Syscall]bool111 if *flagEnable != "" {112 enabled := strings.Split(*flagEnable, ",")113 syscallsIDs, err := mgrconfig.ParseEnabledSyscalls(target, enabled, nil)114 if err != nil {115 fmt.Fprintf(os.Stderr, "failed to parse enabled syscalls: %v", err)116 os.Exit(1)117 }118 syscalls = make(map[*prog.Syscall]bool)119 for _, id := range syscallsIDs {120 syscalls[target.Syscalls[id]] = true121 }122 var disabled map[*prog.Syscall]string123 syscalls, disabled = target.TransitivelyEnabledCalls(syscalls)124 for c, reason := range disabled {125 fmt.Fprintf(os.Stderr, "disabling %v: %v\n", c.Name, reason)126 }127 }128 data, err := ioutil.ReadFile(flag.Arg(0))129 if err != nil {130 fmt.Fprintf(os.Stderr, "failed to read prog file: %v\n", err)131 os.Exit(1)132 }133 poc, err := target.Deserialize(data, prog.NonStrict)134 if err != nil {135 fmt.Fprintf(os.Stderr, "failed to deserialize the program: %v\n", err)136 os.Exit(1)137 }138 argMaps := parseArg(poc)139 logArgMap(argMaps)140 var p *prog.Prog141 if flag.NArg() == 0 {142 fmt.Printf("please specify the input to be mutated\n")143 os.Exit(-1)144 } else {145 data, err := ioutil.ReadFile(flag.Arg(0))146 if err != nil {147 fmt.Fprintf(os.Stderr, "failed to read prog file: %v\n", err)148 os.Exit(1)149 }150 p, err = target.Deserialize(data, prog.NonStrict)151 if err != nil {152 fmt.Fprintf(os.Stderr, "failed to deserialize the program: %v\n", err)153 os.Exit(1)154 }155 fmt.Printf("Original input: %s\n", p.Serialize())156 for _, c := range p.Calls {157 args := argMaps[c.Meta.Name]158 if len(args) == 0 {159 fmt.Printf("skip %s\n", c.Meta.Name)160 continue161 }162 prog.ForeachArg(c, func(arg prog.Arg, ctx *prog.ArgCtx) {163 switch arg.(type) {164 // case *prog.UnionArg, *prog.GroupArg, *prog.StructArg:165 default:166 for _, pocArg := range args {167 if pocArg.Type().String() == arg.Type().String() &&168 pocArg.Type().TemplateName() == arg.Type().TemplateName() {169 fmt.Printf("Found %s != %s\n", pocArg.Type().String(), arg.Type().String())170 if r.Intn(8) > 1 {171 continue172 }173 replaceArg(arg, pocArg)174 fmt.Printf("after mutation: %s\n", p.Serialize())175 break176 } else {177 fmt.Printf("Skip %s != %s\n", pocArg.Type().String(), arg.Type().String())178 }179 }180 }181 // case *prog.PointerArg, *prog.UnionArg:182 // fmt.Printf("%s : %s\n", arg.Type().String(), arg.Type().Name())183 // fmt.Printf("Temple name: %s\n", arg.Type().TemplateName())184 // fmt.Printf("ARG: %T\n", arg)185 // fmt.Printf("Type2: %T\n\n", arg.Type())186 // case *prog.GroupArg:187 // fmt.Printf("%s : %s\n", arg.Type().String(), arg.Type().Name())...

Full Screen

Full Screen

replaceArg

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Before swap, value of a : ", a)4 fmt.Println("Before swap, value of b : ", b)5 swap(&a, &b)6 fmt.Println("After swap, value of a : ", a)7 fmt.Println("After swap, value of b : ", b)8}9func swap(x *int, y *int) {10}11import "fmt"12func main() {13 fmt.Printf("Before swap, value of a : %d\n", a )14 fmt.Printf("Before swap, value of b : %d\n", b )15 swap(&a, &b)16 fmt.Printf("After swap, value of a : %d\n", a )17 fmt.Printf("After swap, value of b : %d\n", b )18}19func swap(x *int, y *int) {

Full Screen

Full Screen

replaceArg

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 prog := Prog{args: []string{"a", "b", "c", "d"}}4 fmt.Println(prog.args)5 prog.replaceArg(1, "x")6 fmt.Println(prog.args)7 prog.replaceArg(0, "y")8 fmt.Println(prog.args)9 prog.replaceArg(3, "z")10 fmt.Println(prog.args)11}12import (13func TestProg_replaceArg(t *testing.T) {14 type fields struct {15 }16 type args struct {17 }18 tests := []struct {19 }{20 {name: "replaceArg test", fields: fields{args: []string{"a", "b", "c", "d"}}, args: args{i: 1, arg: "x"}, want: []string{"a", "x", "c", "d"}},21 }22 for _, tt := range tests {23 t.Run(tt.name, func(t *testing.T) {24 p := Prog{25 }26 if got := p.replaceArg(tt.args.i, tt.args.arg); !reflect.DeepEqual(got, tt.want) {27 t.Errorf("Prog.replaceArg() = %v, want %v", got, tt.want)28 }29 })30 }31}32import (33func main() {34 prog := Prog{args: []string{"a", "b", "c", "d"}}35 fmt.Println(prog.args)36 prog.replaceArg(1, "x")37 fmt.Println(prog.args)38 prog.replaceArg(0, "y")39 fmt.Println(prog.args)40 prog.replaceArg(3, "z")41 fmt.Println(prog.args)42}

Full Screen

Full Screen

replaceArg

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if len(args) != 2 {4 fmt.Println("Usage: ", args[0], "string")5 os.Exit(1)6 }7 fmt.Println("The string is: ", args[1])8}

Full Screen

Full Screen

replaceArg

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

replaceArg

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if len(os.Args) != 3 {4 fmt.Println("Please provide two strings")5 os.Exit(1)6 }7 fmt.Println("Before replacing: ", os.Args)8 fmt.Println("After replacing: ", os.Args)9}

Full Screen

Full Screen

replaceArg

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 prog := myPackage.NewProg()4 fmt.Println(prog.GetArg())5 prog.ReplaceArg("test")6 fmt.Println(prog.GetArg())7}8type Prog struct {9}10func NewProg() *Prog {11 return &Prog{arg: "default"}12}13func (p *Prog) GetArg() string {14}15func (p *Prog) ReplaceArg(arg string) {16}

Full Screen

Full Screen

replaceArg

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

replaceArg

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 n, _ = strconv.Atoi(os.Args[2])4 p.replaceArg(str, n)5}6type prog struct {7}8func (p prog) replaceArg(str string, n int) {9 fmt.Println("Replaced argument is:", p.args[n])10}

Full Screen

Full Screen

replaceArg

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 p := prog{args: []string{"one", "two", "three"}}4 p.replaceArg(1, "test")5 fmt.Println(p.args)6}7import "fmt"8func main() {9 p := prog{args: []string{"one", "two", "three"}}10 p.replaceArg(1, "test")11 fmt.Println(p.args)12 p.printArgs()13}14import "fmt"15func main() {16 p := prog{args: []string{"one", "two", "three"}}17 p.replaceArg(1, "test")18 fmt.Println(p.args)19 p.printArgs()20 p.printArgs()21}22import "fmt"23func main() {24 p := prog{args: []string{"one", "two", "three"}}25 p.replaceArg(1, "test")26 fmt.Println(p.args)27 p.printArgs()28 p.printArgs()29 p.printArgs()30}

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