How to use genPtr method of proggen Package

Best Syzkaller code snippet using proggen.genPtr

proggen.go

Source:proggen.go Github

copy

Full Screen

...154 return ctx.parseProc(a, dir, traceArg)155 case *prog.ResourceType:156 return ctx.genResource(a, dir, traceArg)157 case *prog.PtrType:158 return ctx.genPtr(a, dir, traceArg)159 case *prog.BufferType:160 return ctx.genBuffer(a, dir, traceArg)161 case *prog.StructType:162 return ctx.genStruct(a, dir, traceArg)163 case *prog.ArrayType:164 return ctx.genArray(a, dir, traceArg)165 case *prog.UnionType:166 return ctx.genUnionArg(a, dir, traceArg)167 case *prog.VmaType:168 return ctx.genVma(a, dir, traceArg)169 default:170 log.Fatalf("unsupported type: %#v", syzType)171 }172 return nil173}174func (ctx *context) genVma(syzType *prog.VmaType, dir prog.Dir, _ parser.IrType) prog.Arg {175 npages := uint64(1)176 if syzType.RangeBegin != 0 || syzType.RangeEnd != 0 {177 npages = syzType.RangeEnd178 }179 return prog.MakeVmaPointerArg(syzType, dir, ctx.builder.AllocateVMA(npages), npages)180}181func (ctx *context) genArray(syzType *prog.ArrayType, dir prog.Dir, traceType parser.IrType) prog.Arg {182 var args []prog.Arg183 switch a := traceType.(type) {184 case *parser.GroupType:185 for i := 0; i < len(a.Elems); i++ {186 args = append(args, ctx.genArg(syzType.Elem, dir, a.Elems[i]))187 }188 default:189 log.Fatalf("unsupported type for array: %#v", traceType)190 }191 return prog.MakeGroupArg(syzType, dir, args)192}193func (ctx *context) genStruct(syzType *prog.StructType, dir prog.Dir, traceType parser.IrType) prog.Arg {194 var args []prog.Arg195 switch a := traceType.(type) {196 case *parser.GroupType:197 j := 0198 if ret, recursed := ctx.recurseStructs(syzType, dir, a); recursed {199 return ret200 }201 for i := range syzType.Fields {202 fldDir := syzType.Fields[i].Dir(dir)203 if prog.IsPad(syzType.Fields[i].Type) {204 args = append(args, syzType.Fields[i].DefaultArg(fldDir))205 continue206 }207 // If the last n fields of a struct are zero or NULL, strace will occasionally omit those values208 // this creates a mismatch in the number of elements in the ir type and in209 // our descriptions. We generate default values for omitted fields210 if j >= len(a.Elems) {211 args = append(args, syzType.Fields[i].DefaultArg(fldDir))212 } else {213 args = append(args, ctx.genArg(syzType.Fields[i].Type, fldDir, a.Elems[j]))214 }215 j++216 }217 case *parser.BufferType:218 // We could have a case like the following:219 // ioctl(3, 35111, {ifr_name="\x6c\x6f", ifr_hwaddr=00:00:00:00:00:00}) = 0220 // if_hwaddr gets parsed as a BufferType but our syscall descriptions have it as a struct type221 return syzType.DefaultArg(dir)222 default:223 log.Fatalf("unsupported type for struct: %#v", a)224 }225 return prog.MakeGroupArg(syzType, dir, args)226}227// recurseStructs handles cases where syzType corresponds to struct descriptions like228// sockaddr_storage_in6 {229// addr sockaddr_in6230// } [size[SOCKADDR_STORAGE_SIZE], align_ptr]231// which need to be recursively generated. It returns true if we needed to recurse232// along with the generated argument and false otherwise.233func (ctx *context) recurseStructs(syzType *prog.StructType, dir prog.Dir, traceType *parser.GroupType) (prog.Arg, bool) {234 // only consider structs with one non-padded field235 numFields := 0236 for _, field := range syzType.Fields {237 if prog.IsPad(field.Type) {238 continue239 }240 numFields++241 }242 if numFields != 1 {243 return nil, false244 }245 // the strace group type needs to have more one field (a mismatch)246 if len(traceType.Elems) == 1 {247 return nil, false248 }249 // first field needs to be a struct250 switch t := syzType.Fields[0].Type.(type) {251 case *prog.StructType:252 var args []prog.Arg253 // first element and traceType should have the same number of elements254 if len(t.Fields) != len(traceType.Elems) {255 return nil, false256 }257 args = append(args, ctx.genStruct(t, dir, traceType))258 for _, field := range syzType.Fields[1:] {259 args = append(args, field.DefaultArg(field.Dir(dir)))260 }261 return prog.MakeGroupArg(syzType, dir, args), true262 }263 return nil, false264}265func (ctx *context) genUnionArg(syzType *prog.UnionType, dir prog.Dir, straceType parser.IrType) prog.Arg {266 if straceType == nil {267 log.Logf(1, "generating union arg. straceType is nil")268 return syzType.DefaultArg(dir)269 }270 log.Logf(4, "generating union arg: %s %#v", syzType.TypeName, straceType)271 // Unions are super annoying because they sometimes need to be handled case by case272 // We might need to lookinto a matching algorithm to identify the union type that most closely273 // matches our strace type.274 switch syzType.TypeName {275 case "sockaddr_storage":276 return ctx.genSockaddrStorage(syzType, dir, straceType)277 case "sockaddr_nl":278 return ctx.genSockaddrNetlink(syzType, dir, straceType)279 case "ifr_ifru":280 return ctx.genIfrIfru(syzType, dir, straceType)281 }282 return prog.MakeUnionArg(syzType, dir, ctx.genArg(syzType.Fields[0].Type, syzType.Fields[0].Dir(dir), straceType), 0)283}284func (ctx *context) genBuffer(syzType *prog.BufferType, dir prog.Dir, traceType parser.IrType) prog.Arg {285 if dir == prog.DirOut {286 if !syzType.Varlen() {287 return prog.MakeOutDataArg(syzType, dir, syzType.Size())288 }289 switch a := traceType.(type) {290 case *parser.BufferType:291 return prog.MakeOutDataArg(syzType, dir, uint64(len(a.Val)))292 default:293 switch syzType.Kind {294 case prog.BufferBlobRand:295 size := rand.Intn(256)296 return prog.MakeOutDataArg(syzType, dir, uint64(size))297 case prog.BufferBlobRange:298 max := rand.Intn(int(syzType.RangeEnd) - int(syzType.RangeBegin) + 1)299 size := max + int(syzType.RangeBegin)300 return prog.MakeOutDataArg(syzType, dir, uint64(size))301 default:302 log.Fatalf("unexpected buffer type kind: %v. call %v arg %#v", syzType.Kind, ctx.currentSyzCall, traceType)303 }304 }305 }306 var bufVal []byte307 switch a := traceType.(type) {308 case *parser.BufferType:309 bufVal = []byte(a.Val)310 case parser.Constant:311 val := a.Val()312 bArr := make([]byte, 8)313 binary.LittleEndian.PutUint64(bArr, val)314 bufVal = bArr315 default:316 log.Fatalf("unsupported type for buffer: %#v", traceType)317 }318 // strace always drops the null byte for buffer types but we only need to add it back for filenames and strings319 switch syzType.Kind {320 case prog.BufferFilename, prog.BufferString:321 bufVal = append(bufVal, '\x00')322 }323 if !syzType.Varlen() {324 size := syzType.Size()325 for uint64(len(bufVal)) < size {326 bufVal = append(bufVal, 0)327 }328 bufVal = bufVal[:size]329 }330 return prog.MakeDataArg(syzType, dir, bufVal)331}332func (ctx *context) genPtr(syzType *prog.PtrType, dir prog.Dir, traceType parser.IrType) prog.Arg {333 switch a := traceType.(type) {334 case parser.Constant:335 if a.Val() == 0 {336 return prog.MakeSpecialPointerArg(syzType, dir, 0)337 }338 // Likely have a type of the form bind(3, 0xfffffffff, [3]);339 res := syzType.Elem.DefaultArg(syzType.ElemDir)340 return ctx.addr(syzType, dir, res.Size(), res)341 default:342 res := ctx.genArg(syzType.Elem, syzType.ElemDir, a)343 return ctx.addr(syzType, dir, res.Size(), res)344 }345}346func (ctx *context) genConst(syzType prog.Type, dir prog.Dir, traceType parser.IrType) prog.Arg {...

Full Screen

Full Screen

genPtr

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 if len(os.Args) != 2 {4 fmt.Println("Usage: ", os.Args[0], "count")5 os.Exit(1)6 }7 count, _ := strconv.Atoi(os.Args[1])8 proggen := new(ProgGen)9 for i := 0; i < count; i++ {10 fmt.Println(proggen.genPtr())11 }12}13import "fmt"14func main() {15}16import "fmt"17func main() {18}19import "fmt"20func main() {21}

Full Screen

Full Screen

genPtr

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 proggen.GenPtr()4}5import (6type proggen struct {7}8func GenPtr() {9 var p *proggen = new(proggen)10 fmt.Println("Pointer generated")11 p.genProg()12}13func (p *proggen) genProg() {14 fmt.Println("Program generated")15 p.runProg()16}17func (p *proggen) runProg() {18 fmt.Println("Program running")19 p.delProg()20}21func (p *proggen) delProg() {22 fmt.Println("Program deleted")23 p.delPtr()24}25func (p *proggen) delPtr() {26 fmt.Println("Pointer deleted")27 p.delFile()28}29func (p *proggen) delFile() {30 err := os.Remove("2.go")31 if err != nil {32 fmt.Println(err)33 }34 fmt.Println("File deleted")35 p.delDir()36}37func (p *proggen) delDir() {38 cmd := exec.Command("rmdir", "proggen")39 cmd.Run()40 fmt.Println("Directory deleted")41}

Full Screen

Full Screen

genPtr

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

genPtr

Using AI Code Generation

copy

Full Screen

1int main()2{3 proggen p;4 int *ptr;5 ptr = p.genPtr();6 cout << *ptr;7 return 0;8}

Full Screen

Full Screen

genPtr

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 g.GenPtr()4 fmt.Println(g)5}6import (7type ProgGen struct {8}9func (g *ProgGen) GenPtr() {10 rand.Seed(time.Now().UnixNano())11 g.prog = make([]string, 10)12 for i := 0; i < 10; i++ {13 g.prog[i] = fmt.Sprintf("%d", rand.Intn(100))14 }15}16func (g ProgGen) Gen() {17 rand.Seed(time.Now().UnixNano())18 g.prog = make([]string, 10)19 for i := 0; i < 10; i++ {20 g.prog[i] = fmt.Sprintf("%d", rand.Intn(100))21 }22}23func (g ProgGen) String() string {24 return fmt.Sprintf("%v", g.prog)25}

Full Screen

Full Screen

genPtr

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

genPtr

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "github.com/raff/godet"3func main() {4 var p *program = pg.genPtr()5 fmt.Println(p)6 gd.Connect("localhost:9222")7 gd.NewTab("")8 gd.Close()9}10import "fmt"11import "github.com/raff/godet"12func main() {13 var p *program = pg.genPtr()14 fmt.Println(p)15 gd.Connect("localhost:9222")16 gd.NewTab("")17 gd.Close()18}19import "fmt"20import "github.com/raff/godet"21func main() {22 var p *program = pg.genPtr()23 fmt.Println(p)24 gd.Connect("localhost:9222")

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