Best Syzkaller code snippet using prog.MakeConstArg
vma_call_handlers.go
Source:vma_call_handlers.go
...43 length := uint64(0)44 length = ParseLength(syscall.Args[1], ctx)45 length = (length/pageSize + 1)*pageSize46 addrArg, start := ParseAddr(length, mmap.Args[0], syscall.Args[0], ctx)47 lengthArg := prog.MakeConstArg(mmap.Args[1], length)48 protArg := ParseFlags(mmap.Args[2], syscall.Args[2], ctx, false)49 flagArg := ParseFlags(mmap.Args[3], syscall.Args[3], ctx, true)50 fdArg := ParseFd(mmap.Args[4], syscall.Args[4], ctx)51 call.Args = []prog.Arg {52 addrArg,53 lengthArg,54 protArg,55 flagArg,56 fdArg,57 prog.MakeConstArg(mmap.Args[5], 0),58 }59 ctx.State.Tracker.CreateMapping(call, len(ctx.Prog.Calls), call.Args[0], start, start+length) //All mmaps have fixed mappings in syzkaller60 return call61}62func ParseMremap(mremap *prog.Syscall, syscall *strace_types.Syscall, ctx *Context) *prog.Call {63 call := &prog.Call{64 Meta: mremap,65 Ret: strace_types.ReturnArg(mremap.Ret),66 }67 ctx.CurrentSyzCall = call68 oldAddrArg, start := ParseAddr(pageSize, mremap.Args[0], syscall.Args[0], ctx)69 oldSz := ParseLength(syscall.Args[1], ctx)70 newSz := ParseLength(syscall.Args[2], ctx)71 oldSzArg := prog.MakeConstArg(mremap.Args[1], oldSz)72 newSzArg := prog.MakeConstArg(mremap.Args[2], newSz)73 flagArg := ParseFlags(mremap.Args[3], syscall.Args[3], ctx, true)74 var destAddrArg prog.Arg75 var destAddr uint6476 if len(syscall.Args) > 4 {77 destAddrArg, destAddr = ParseAddr(pageSize, mremap.Args[4], syscall.Args[4], ctx)78 } else {79 straceAddrArg := strace_types.NewExpression(strace_types.NewIntType(syscall.Ret))80 destAddrArg, destAddr = ParseAddr(pageSize, mremap.Args[4], straceAddrArg, ctx)81 }82 AddDependency(start, oldSz, oldAddrArg, ctx)83 call.Args = []prog.Arg {84 oldAddrArg,85 oldSzArg,86 newSzArg,87 flagArg,88 destAddrArg,89 }90 ctx.State.Tracker.CreateMapping(call, len(ctx.Prog.Calls), call.Args[4], destAddr, destAddr+newSz) //All mmaps have fixed mappings in syzkaller91 return call92}93func ParseMsync(msync *prog.Syscall, syscall *strace_types.Syscall, ctx *Context) *prog.Call {94 call := &prog.Call{95 Meta: msync,96 Ret: strace_types.ReturnArg(msync.Ret),97 }98 ctx.CurrentSyzCall = call99 addrArg, address := ParseAddr(pageSize, msync.Args[0], syscall.Args[0], ctx)100 length := uint64(0)101 length = ParseLength(syscall.Args[1], ctx)102 lengthArg := prog.MakeConstArg(msync.Args[1], length)103 protArg := ParseFlags(msync.Args[2], syscall.Args[2], ctx, false)104 AddDependency(address, length, addrArg, ctx)105 call.Args = []prog.Arg {106 addrArg,107 lengthArg,108 protArg,109 }110 return call111}112func ParseMprotect(mprotect *prog.Syscall, syscall *strace_types.Syscall, ctx *Context) *prog.Call {113 call := &prog.Call {114 Meta: mprotect,115 Ret: strace_types.ReturnArg(mprotect.Ret),116 }117 ctx.CurrentSyzCall = call118 addrArg, address := ParseAddr(pageSize, mprotect.Args[0], syscall.Args[0], ctx)119 length := ParseLength(syscall.Args[1], ctx)120 lengthArg := prog.MakeConstArg(mprotect.Args[1], length)121 protArg := ParseFlags(mprotect.Args[2], syscall.Args[2], ctx, false)122 AddDependency(address, length, addrArg, ctx)123 call.Args = []prog.Arg {124 addrArg,125 lengthArg,126 protArg,127 }128 return call129}130func ParseMunmap(munmap *prog.Syscall, syscall *strace_types.Syscall, ctx *Context) *prog.Call {131 call := &prog.Call {132 Meta: munmap,133 Ret: strace_types.ReturnArg(munmap.Ret),134 }135 ctx.CurrentSyzCall = call136 addrArg, address := ParseAddr(pageSize, munmap.Args[0], syscall.Args[0], ctx)137 length := ParseLength(syscall.Args[1], ctx)138 lengthArg := prog.MakeConstArg(munmap.Args[1], length)139 AddDependency(address, length, addrArg, ctx)140 call.Args = []prog.Arg{141 addrArg,142 lengthArg,143 }144 return call145}146func ParseMadvise(madvise *prog.Syscall, syscall *strace_types.Syscall, ctx *Context) *prog.Call {147 call := &prog.Call {148 Meta: madvise,149 Ret: strace_types.ReturnArg(madvise.Ret),150 }151 ctx.CurrentSyzCall = call152 addrArg, address := ParseAddr(pageSize, madvise.Args[0], syscall.Args[0], ctx)153 length := ParseLength(syscall.Args[1], ctx)154 lengthArg := prog.MakeConstArg(madvise.Args[1], length)155 var adviceArg prog.Arg156 switch a := syscall.Args[2].(type) {157 case *strace_types.Expression:158 adviceArg = strace_types.ConstArg(madvise.Args[2], a.Eval(ctx.Target))159 default:160 panic("Madvise advice arg is not expression")161 }162 AddDependency(address, length, addrArg, ctx)163 call.Args = []prog.Arg {164 addrArg,165 lengthArg,166 adviceArg,167 }168 return call169}170func ParseMlock(mlock *prog.Syscall, syscall *strace_types.Syscall, ctx *Context) *prog.Call {171 call := &prog.Call {172 Meta: mlock,173 Ret : strace_types.ReturnArg(mlock.Ret),174 }175 ctx.CurrentSyzCall = call176 addrArg, address := ParseAddr(pageSize, mlock.Args[0], syscall.Args[0], ctx)177 length := ParseLength(syscall.Args[1], ctx)178 flagArg := strace_types.ConstArg(mlock.Args[1], length)179 AddDependency(address, length, addrArg, ctx)180 call.Args = []prog.Arg {181 addrArg,182 flagArg,183 }184 return call185}186func ParseMunlock(munlock *prog.Syscall, syscall *strace_types.Syscall, ctx *Context) *prog.Call {187 call := &prog.Call {188 Meta: munlock,189 Ret : strace_types.ReturnArg(munlock.Ret),190 }191 ctx.CurrentSyzCall = call192 addrArg, address := ParseAddr(pageSize, munlock.Args[0], syscall.Args[0], ctx)193 length := ParseLength(syscall.Args[1], ctx)194 flagArg := strace_types.ConstArg(munlock.Args[1], length)195 AddDependency(address, length, addrArg, ctx)196 call.Args = []prog.Arg {197 addrArg,198 flagArg,199 }200 return call201}202func ParseShmat(shmat *prog.Syscall, syscall *strace_types.Syscall, ctx *Context) *prog.Call {203 /*204 * Shmat will create a shared memory map which we should track.205 * If the second argument is NULL then shmat will create the memory map and206 * store it at that address if successful.207 */208 shmid := uint64(0)209 var fd prog.Arg210 call := &prog.Call{211 Meta: shmat,212 Ret: strace_types.ReturnArg(shmat.Ret),213 }214 ctx.CurrentSyzCall = call215 if arg := ctx.Cache.Get(shmat.Args[0], syscall.Args[0]); arg != nil {216 fd = strace_types.ResultArg(shmat.Args[0], arg.(*prog.ResultArg), arg.Type().Default())217 } else {218 switch a := syscall.Args[0].(type) {219 case *strace_types.Expression:220 shmid = a.Eval(ctx.Target)221 default:222 shmid = 0223 }224 fd = strace_types.ResultArg(shmat.Args[0], nil, shmid)225 }226 addrArg, address := ParseAddr(pageSize, shmat.Args[1], syscall.Args[1], ctx)227 flags := ParseFlags(shmat.Args[2], syscall.Args[2], ctx, false)228 call.Args = []prog.Arg{229 fd,230 addrArg,231 flags,232 }233 //Cache the mapped address since it is a resource type as well234 call.Ret = prog.MakeReturnArg(shmat.Ret)235 straceRet := strace_types.NewExpression(strace_types.NewIntType(syscall.Ret))236 ctx.Cache.Cache(call.Ret.Type(), straceRet, call.Ret)237 length := uint64(4096)238 if req := ctx.State.Tracker.FindShmRequest(shmid); req != nil {239 length = req.GetSize()240 }241 ctx.State.Tracker.CreateMapping(call, len(ctx.Prog.Calls), call.Args[1], address, address + length)242 return call243}244func ParseAddr(length uint64, syzType prog.Type, straceType strace_types.Type, ctx *Context) (prog.Arg, uint64){245 defAddrStart := (ctx.Target.NumPages-2)*ctx.Target.PageSize246 switch a := straceType.(type) {247 case *strace_types.PointerType:248 var addrStart uint64249 if a.IsNull() {250 //Anonymous MMAP251 addrStart = uint64(ctx.CurrentStraceCall.Ret)252 return prog.MakeVmaPointerArg(syzType, defAddrStart, length), addrStart253 } else {254 return prog.MakeVmaPointerArg(syzType, defAddrStart, length), a.Address255 }256 case *strace_types.Expression:257 addrStart := a.Eval(ctx.Target)258 return prog.MakeVmaPointerArg(syzType, defAddrStart, length), addrStart259 default:260 panic("Failed to parse mmap")261 }262}263func AddDependency(start, length uint64, addr prog.Arg, ctx *Context) {264 if mapping := ctx.State.Tracker.FindLatestOverlappingVMA(start); mapping != nil {265 dependsOn := make(map[*prog.Call]int, 0)266 dependsOn[mapping.GetCall()] = mapping.GetCallIdx()267 for _, dep := range mapping.GetUsedBy() {268 dependsOn[ctx.Prog.Calls[dep.Callidx]] = dep.Callidx269 }270 ctx.DependsOn[ctx.CurrentSyzCall] = dependsOn271 dep := tracker.NewMemDependency(len(ctx.Prog.Calls), addr, start, start+length)272 mapping.AddDependency(dep)273 }274}275func ParseLength(straceType strace_types.Type, ctx *Context) uint64 {276 switch a := straceType.(type) {277 case *strace_types.Expression:278 return a.Eval(ctx.Target)279 default:280 panic("Parsing Mmap length but type is not expression")281 }282}283func ParseFlags(syzType prog.Type, straceType strace_types.Type, ctx *Context, mapFlag bool) prog.Arg {284 switch a := straceType.(type) {285 case *strace_types.Expression:286 if mapFlag {287 val := a.Eval(ctx.Target) | GetFixedFlag(ctx)288 return prog.MakeConstArg(syzType, val)289 } else {290 return prog.MakeConstArg(syzType, a.Eval(ctx.Target))291 }292 default:293 panic("Parsing Flags")294 }295}296func ParseFd(syzType prog.Type, straceType strace_types.Type, ctx *Context) prog.Arg {297 if arg := ctx.Cache.Get(syzType, straceType); arg != nil {298 return prog.MakeResultArg(arg.Type(), arg.(*prog.ResultArg), arg.Type().Default())299 }300 switch a := straceType.(type) {301 case *strace_types.Expression:302 return prog.MakeResultArg(syzType, nil, a.Eval(ctx.Target))303 default:304 panic("Failed to Parse Fd because type is not Expression")...
vmaCallHandlers.go
Source:vmaCallHandlers.go
...38 ctx.CurrentSyzCall = call39 length := (parseLength(syscall.Args[1], ctx)/ctx.Target.PageSize + 1) * ctx.Target.PageSize //RoundUp PageSize40 log.Logf(3, "mmap call: %#v requires %d memory", syscall, length)41 addrArg, start := parseAddr(length, mmap.Args[0], syscall.Args[0], ctx)42 lengthArg := prog.MakeConstArg(mmap.Args[1], length)43 protArg := parseFlags(mmap.Args[2], syscall.Args[2], ctx, false)44 flagArg := parseFlags(mmap.Args[3], syscall.Args[3], ctx, true)45 fdArg := parseFd(mmap.Args[4], syscall.Args[4], ctx)46 call.Args = []prog.Arg{47 addrArg,48 lengthArg,49 protArg,50 flagArg,51 fdArg,52 prog.MakeConstArg(mmap.Args[5], 0),53 }54 //All mmaps have fixed mappings in syzkaller55 ctx.Tracker.createMapping(call, len(ctx.Prog.Calls), call.Args[0], start, start+length)56 return call57}58func parseMremap(mremap *prog.Syscall, syscall *parser.Syscall, ctx *Context) *prog.Call {59 call := &prog.Call{60 Meta: mremap,61 Ret: prog.MakeReturnArg(mremap.Ret),62 }63 ctx.CurrentSyzCall = call64 oldAddrArg, start := parseAddr(ctx.Target.PageSize, mremap.Args[0], syscall.Args[0], ctx)65 oldSz := parseLength(syscall.Args[1], ctx)66 newSz := parseLength(syscall.Args[2], ctx)67 oldSzArg := prog.MakeConstArg(mremap.Args[1], oldSz)68 newSzArg := prog.MakeConstArg(mremap.Args[2], newSz)69 flagArg := parseFlags(mremap.Args[3], syscall.Args[3], ctx, true)70 var destAddrArg prog.Arg71 var destAddr uint6472 if len(syscall.Args) > 4 {73 destAddrArg, destAddr = parseAddr(ctx.Target.PageSize, mremap.Args[4], syscall.Args[4], ctx)74 } else {75 straceAddrArg := parser.NewIntsType([]int64{syscall.Ret})76 destAddrArg, destAddr = parseAddr(ctx.Target.PageSize, mremap.Args[4], straceAddrArg, ctx)77 }78 addDependency(start, oldSz, oldAddrArg, ctx)79 call.Args = []prog.Arg{80 oldAddrArg,81 oldSzArg,82 newSzArg,83 flagArg,84 destAddrArg,85 }86 //All mmaps have fixed mappings in syzkaller87 ctx.Tracker.createMapping(call, len(ctx.Prog.Calls), call.Args[4], destAddr, destAddr+newSz)88 return call89}90func parseMsync(msync *prog.Syscall, syscall *parser.Syscall, ctx *Context) *prog.Call {91 var length uint6492 call := &prog.Call{93 Meta: msync,94 Ret: prog.MakeReturnArg(msync.Ret),95 }96 ctx.CurrentSyzCall = call97 addrArg, address := parseAddr(ctx.Target.PageSize, msync.Args[0], syscall.Args[0], ctx)98 length = parseLength(syscall.Args[1], ctx)99 lengthArg := prog.MakeConstArg(msync.Args[1], length)100 protArg := parseFlags(msync.Args[2], syscall.Args[2], ctx, false)101 addDependency(address, length, addrArg, ctx)102 call.Args = []prog.Arg{103 addrArg,104 lengthArg,105 protArg,106 }107 return call108}109func parseMprotect(mprotect *prog.Syscall, syscall *parser.Syscall, ctx *Context) *prog.Call {110 call := &prog.Call{111 Meta: mprotect,112 Ret: prog.MakeReturnArg(mprotect.Ret),113 }114 ctx.CurrentSyzCall = call115 addrArg, address := parseAddr(ctx.Target.PageSize, mprotect.Args[0], syscall.Args[0], ctx)116 length := parseLength(syscall.Args[1], ctx)117 lengthArg := prog.MakeConstArg(mprotect.Args[1], length)118 protArg := parseFlags(mprotect.Args[2], syscall.Args[2], ctx, false)119 addDependency(address, length, addrArg, ctx)120 call.Args = []prog.Arg{121 addrArg,122 lengthArg,123 protArg,124 }125 return call126}127func parseMunmap(munmap *prog.Syscall, syscall *parser.Syscall, ctx *Context) *prog.Call {128 call := &prog.Call{129 Meta: munmap,130 Ret: prog.MakeReturnArg(munmap.Ret),131 }132 ctx.CurrentSyzCall = call133 addrArg, address := parseAddr(ctx.Target.PageSize, munmap.Args[0], syscall.Args[0], ctx)134 length := parseLength(syscall.Args[1], ctx)135 lengthArg := prog.MakeConstArg(munmap.Args[1], length)136 addDependency(address, length, addrArg, ctx)137 call.Args = []prog.Arg{138 addrArg,139 lengthArg,140 }141 return call142}143func parseMadvise(madvise *prog.Syscall, syscall *parser.Syscall, ctx *Context) *prog.Call {144 call := &prog.Call{145 Meta: madvise,146 Ret: prog.MakeReturnArg(madvise.Ret),147 }148 ctx.CurrentSyzCall = call149 addrArg, address := parseAddr(ctx.Target.PageSize, madvise.Args[0], syscall.Args[0], ctx)150 length := parseLength(syscall.Args[1], ctx)151 lengthArg := prog.MakeConstArg(madvise.Args[1], length)152 var adviceArg prog.Arg153 switch a := syscall.Args[2].(type) {154 case parser.Expression:155 adviceArg = prog.MakeConstArg(madvise.Args[2], a.Eval(ctx.Target))156 default:157 log.Fatalf("Madvise advice arg is not expression")158 }159 addDependency(address, length, addrArg, ctx)160 call.Args = []prog.Arg{161 addrArg,162 lengthArg,163 adviceArg,164 }165 return call166}167func parseMlock(mlock *prog.Syscall, syscall *parser.Syscall, ctx *Context) *prog.Call {168 call := &prog.Call{169 Meta: mlock,170 Ret: prog.MakeReturnArg(mlock.Ret),171 }172 ctx.CurrentSyzCall = call173 addrArg, address := parseAddr(ctx.Target.PageSize, mlock.Args[0], syscall.Args[0], ctx)174 length := parseLength(syscall.Args[1], ctx)175 flagArg := prog.MakeConstArg(mlock.Args[1], length)176 addDependency(address, length, addrArg, ctx)177 call.Args = []prog.Arg{178 addrArg,179 flagArg,180 }181 return call182}183func parseMunlock(munlock *prog.Syscall, syscall *parser.Syscall, ctx *Context) *prog.Call {184 call := &prog.Call{185 Meta: munlock,186 Ret: prog.MakeReturnArg(munlock.Ret),187 }188 ctx.CurrentSyzCall = call189 addrArg, address := parseAddr(ctx.Target.PageSize, munlock.Args[0], syscall.Args[0], ctx)190 length := parseLength(syscall.Args[1], ctx)191 flagArg := prog.MakeConstArg(munlock.Args[1], length)192 addDependency(address, length, addrArg, ctx)193 call.Args = []prog.Arg{194 addrArg,195 flagArg,196 }197 return call198}199func parseShmat(shmat *prog.Syscall, syscall *parser.Syscall, ctx *Context) *prog.Call {200 /*201 * Shmat will create a shared memory map which we should track.202 * If the second argument is NULL then shmat will create the memory map and203 * store it at that address if successful.204 */205 shmid := uint64(0)206 var fd prog.Arg207 call := &prog.Call{208 Meta: shmat,209 Ret: prog.MakeReturnArg(shmat.Ret),210 }211 ctx.CurrentSyzCall = call212 if arg := ctx.ReturnCache.get(shmat.Args[0], syscall.Args[0]); arg != nil {213 switch a := arg.Type().(type) {214 case *prog.ResourceType:215 fd = prog.MakeResultArg(shmat.Args[0], arg.(*prog.ResultArg), a.Default())216 default:217 log.Fatalf("Expected first argument of Shmat to be resource type. Got: %s", a.Name())218 }219 } else {220 switch a := syscall.Args[0].(type) {221 case parser.Expression:222 shmid = a.Eval(ctx.Target)223 default:224 shmid = 0225 }226 fd = prog.MakeResultArg(shmat.Args[0], nil, shmid)227 }228 addrArg, address := parseAddr(ctx.Target.PageSize, shmat.Args[1], syscall.Args[1], ctx)229 flags := parseFlags(shmat.Args[2], syscall.Args[2], ctx, false)230 call.Args = []prog.Arg{231 fd,232 addrArg,233 flags,234 }235 //Cache the mapped address since it is a resource type as well236 call.Ret = prog.MakeReturnArg(shmat.Ret)237 straceRet := parser.NewIntsType([]int64{syscall.Ret})238 ctx.ReturnCache.cache(call.Ret.Type(), straceRet, call.Ret)239 length := uint64(4096)240 if req := ctx.Tracker.findShmRequest(shmid); req != nil {241 length = req.getSize()242 }243 ctx.Tracker.createMapping(call, len(ctx.Prog.Calls), call.Args[1], address, address+length)244 return call245}246func parseAddr(length uint64, syzType prog.Type, traceType parser.IrType, ctx *Context) (prog.Arg, uint64) {247 defAddrStart := (ctx.Target.NumPages - 2) * ctx.Target.PageSize248 switch a := traceType.(type) {249 case *parser.PointerType:250 var addrStart uint64251 if a.IsNull() {252 //Anonymous MMAP253 addrStart = uint64(ctx.CurrentStraceCall.Ret)254 return prog.MakeVmaPointerArg(syzType, defAddrStart, length), addrStart255 }256 return prog.MakeVmaPointerArg(syzType, defAddrStart, length), a.Address257 case parser.Expression:258 addrStart := a.Eval(ctx.Target)259 return prog.MakeVmaPointerArg(syzType, defAddrStart, length), addrStart260 default:261 log.Fatalf("Failed to parse mmap")262 }263 return nil, 0264}265func addDependency(start, length uint64, addr prog.Arg, ctx *Context) {266 if mapping := ctx.Tracker.findLatestOverlappingVMA(start); mapping != nil {267 dependsOn := make(map[*prog.Call]int)268 dependsOn[mapping.getCall()] = mapping.getCallIdx()269 for _, dep := range mapping.getUsedBy() {270 dependsOn[ctx.Prog.Calls[dep.Callidx]] = dep.Callidx271 }272 ctx.DependsOn[ctx.CurrentSyzCall] = dependsOn273 dep := newMemDependency(len(ctx.Prog.Calls), addr, start, start+length)274 mapping.addDependency(dep)275 }276}277func parseLength(straceType parser.IrType, ctx *Context) uint64 {278 switch a := straceType.(type) {279 case parser.Expression:280 return a.Eval(ctx.Target)281 default:282 log.Fatalf("Parsing Mmap length but type is not expression")283 }284 return 0285}286func parseFlags(syzType prog.Type, straceType parser.IrType, ctx *Context, mapFlag bool) prog.Arg {287 switch a := straceType.(type) {288 case parser.Expression:289 if mapFlag {290 val := a.Eval(ctx.Target)291 return prog.MakeConstArg(syzType, val)292 }293 return prog.MakeConstArg(syzType, a.Eval(ctx.Target))294 default:295 log.Fatalf("Parsing Flags")296 }297 return nil298}299func parseFd(syzType prog.Type, straceType parser.IrType, ctx *Context) prog.Arg {300 log.Logf(3, "Parsing file descriptor for call: %s", ctx.CurrentStraceCall.CallName)301 if arg := ctx.ReturnCache.get(syzType, straceType); arg != nil {302 log.Logf(3, "File descriptor: %s in the cache", straceType.String())303 switch a := syzType.(type) {304 case *prog.ResourceType:305 return prog.MakeResultArg(arg.Type(), arg.(*prog.ResultArg), a.Default())306 default:307 log.Fatalf("Parsing fd for memory call. Expected resource type. Got: %s", a.String())...
parseInnerCalls.go
Source:parseInnerCalls.go
...29 arg2 := traceType.Args[1].(parser.Expression)30 major = int64(arg1.Eval(ctx.Target))31 minor = int64(arg2.Eval(ctx.Target))32 id = ((minor & 0xff) | ((major & 0xfff) << 8) | ((minor & ^0xff) << 12) | ((major & ^0xfff) << 32))33 return prog.MakeConstArg(syzType, uint64(id))34}35func htonsHtonl(syzType prog.Type, traceType *parser.Call, ctx *Context) prog.Arg {36 if len(traceType.Args) > 1 {37 log.Fatalf("Cannot evaluate htonsHtonl since it has more than one arg.")38 }39 switch typ := syzType.(type) {40 case *prog.ProcType:41 switch a := traceType.Args[0].(type) {42 case parser.Expression:43 val := a.Eval(ctx.Target)44 if val >= typ.ValuesPerProc {45 return prog.MakeConstArg(syzType, typ.ValuesPerProc-1)46 }47 return prog.MakeConstArg(syzType, val)48 default:49 log.Fatalf("Expected first arg of Htons/Htonl to be expression. Got: %s", a.Name())50 }51 case *prog.ConstType, *prog.IntType, *prog.FlagsType:52 switch a := traceType.Args[0].(type) {53 case parser.Expression:54 val := a.Eval(ctx.Target)55 return prog.MakeConstArg(syzType, val)56 default:57 log.Fatalf("Expected first arg of Htons/Htonl to be expression. Got: %s", a.Name())58 }59 default:60 log.Fatalf("First arg of Htons/Htonl is not const Type: %s\n", syzType.Name())61 }62 return nil63}64func inetAddr(syzType prog.Type, traceType *parser.Call, ctx *Context) prog.Arg {65 var ip uint6466 ip4Addr := func(ipaddr string) uint64 {67 var (68 ip = strings.Split(ipaddr, ".")69 ip1, ip2, ip3, ip4 uint6470 ret uint6471 )72 ip1, _ = strconv.ParseUint(ip[0], 10, 8)73 ip2, _ = strconv.ParseUint(ip[1], 10, 8)74 ip3, _ = strconv.ParseUint(ip[2], 10, 8)75 ip4, _ = strconv.ParseUint(ip[3], 10, 8)76 ret = ip1<<24 + ip2<<16 + ip3<<8 + ip477 return ret78 }79 if len(traceType.Args) > 1 {80 log.Logf(3, "%#v", traceType.Args)81 log.Fatalf("inetAddr should only have one argument. Found: %d\n", len(traceType.Args))82 }83 switch a := traceType.Args[0].(type) {84 case *parser.BufferType:85 ip = ip4Addr(a.Val)86 default:87 log.Fatalf("Parsing inet_addr and inner arg has non ipv4 type")88 }89 switch a := syzType.(type) {90 case *prog.UnionType:91 for _, field := range a.Fields {92 if !strings.Contains(field.FieldName(), "rand") {93 continue94 }95 switch field.(type) {96 case *prog.IntType:97 return prog.MakeUnionArg(syzType, prog.MakeConstArg(field, ip))98 default:99 log.Fatalf("Rand field isn't int type. Instead is %s", field.Name())100 }101 }102 default:103 log.Fatalf("Parsing ip address for non-union type %s", a.Name())104 }105 log.Logf(4, "Generating default arg for ip address")106 return prog.DefaultArg(syzType)107}108func inetPton(syzType prog.Type, traceType *parser.Call, ctx *Context) prog.Arg {109 log.Logf(4, "type name: %s", syzType.Name())110 unionType := syzType.(*prog.UnionType)111 var optType prog.Type...
MakeConstArg
Using AI Code Generation
1import (2func main() {3 target, err := prog.GetTarget("linux", "amd64")4 if err != nil {5 panic(err)6 }7 p := target.MakeProg()8 c := target.MakeConstArg(target.ConstMap["O_RDWR"], 0)9 p.Calls = append(p.Calls, &prog.Call{10 Args: []prog.Arg{c},11 })12 data, err := p.Serialize()13 if err != nil {14 panic(err)15 }16 p1, err := target.Deserialize(data, prog.NonStrict)17 if err != nil {18 panic(err)19 }20 fmt.Println(p1.String())21}22open(O_RDWR, 0x0, 0x0)23import (24func main() {25 target, err := prog.GetTarget("linux", "amd64")26 if err != nil {27 panic(err)28 }29 p := target.MakeProg()30 d := target.MakeDataArg([]byte("hello world"), 0)31 p.Calls = append(p.Calls, &prog.Call{32 Args: []prog.Arg{d},33 })34 data, err := p.Serialize()35 if err != nil {36 panic(err)37 }38 p1, err := target.Deserialize(data, prog.NonStrict)39 if err != nil {40 panic(err)41 }42 fmt.Println(p1.String())43}44open("hello world", 0x0,
MakeConstArg
Using AI Code Generation
1import (2func main() {3 target, err := prog.GetTarget("linux", "amd64")4 if err != nil {5 panic(err)6 }7 prog := &prog.Prog{8 }9 buf := prog.MakeBufferArg(10)10 constArg := prog.MakeConstArg(sys.IntType, 2)11 structArg := prog.MakeGroupArg(sys.StructType, []prog.Arg{buf, constArg})12 structArg2 := prog.MakeGroupArg(sys.StructType, []prog.Arg{buf, constArg})13 slice := prog.MakeDataArg("slice", []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9})14 unionArg := prog.MakeUnionArg(sys.UnionType, "buf", buf)15 unionArg2 := prog.MakeUnionArg(sys.UnionType, "slice", slice)16 array := prog.MakeGroupArg(sys.ArrayType, []prog.Arg{buf, constArg, structArg, structArg2, unionArg, unionArg2})17 str := prog.MakeDataArg("str", []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9})18 structArg3 := prog.MakeGroupArg(sys.StructType, []prog.Arg{buf, constArg, structArg, array, str})19 ptr := prog.MakePointerArg(structArg3)20 ptr2 := prog.MakePointerArg(ptr)
MakeConstArg
Using AI Code Generation
1import (2func main() {3 target := prog.GetTarget("linux", "amd64")4int main(void) {5 struct sockaddr_in addr = {6 .sin_port = htons(12345),7 .sin_addr.s_addr = htonl(0x7f000001),8 };9 return 0;10}11 p, err := compiler.Compile(target, src)12 if err != nil {13 panic(err)14 }15 fmt.Printf("p: %+v16}17p: &{Target:0xc42000e000 Entries:[0xc4200a0000 0xc4200a0080 0xc4200a0100 0xc4200a0180 0xc4200a0200 0xc4200a0280 0xc4200a0300 0xc4200a0380 0xc4200a0400 0xc4200a0480 0xc4200a0500 0xc4200a0580 0xc4200a0600 0xc4200a0680 0xc4200a0700 0xc4200a0780 0xc4200a0800 0xc4200a0880 0xc4200a0900 0xc4200a0980 0xc4200a0a00 0xc4200a0a80 0xc4200a0b00 0xc4200a0b80 0xc4200a0c00 0xc4200a0c80 0xc4200a0d00 0xc4200a0d80 0xc4200a0e00 0xc4200a0e80 0xc4200a0f00 0xc4200a0f80 0xc4200a1000 0xc420
MakeConstArg
Using AI Code Generation
1import (2func main() {3 target, err := targets.Get("linux", "amd64")4 if err != nil {5 panic(err)6 }7 prog := prog.MakeTargetProg(target, 10)8 constArg := prog.MakeConstArg(target.ConstMap["O_RDONLY"], 1)9 fmt.Println(constArg)10}11import (12func main() {13 target, err := targets.Get("linux", "amd64")14 if err != nil {15 panic(err)16 }17 prog := prog.MakeTargetProg(target, 10)18 resultArg := prog.MakeResultArg(nil, 1)19 fmt.Println(resultArg)20}21import (22func main() {23 target, err := targets.Get("linux", "amd64")24 if err != nil {25 panic(err)26 }27 prog := prog.MakeTargetProg(target, 10)28 returnArg := prog.MakeReturnArg(1)29 fmt.Println(returnArg)30}
MakeConstArg
Using AI Code Generation
1import (2func main() {3 target, err := prog.GetTarget("linux", "amd64")4 if err != nil {5 panic(err)6 }
MakeConstArg
Using AI Code Generation
1import (2func main() {3 p := prog.MakeTarget("linux", "amd64", "test").Prog()4 p.MakeConstArg(1, 42)5 fmt.Println(p.Serialize())6}7syz_open_dev$1(0x0, 0x2a, 0x0)8syz_open_dev$1(0x0, 0x2a, 0x0)9import (10func main() {11 p := prog.MakeTarget("linux", "amd64", "test").Prog()12 p.MakeReturnArg(1)13 fmt.Println(p.Serialize())14}15syz_open_dev$1(0x0, 0x0, 0x0)16syz_open_dev$1(0x0, 0x0, 0x0)17import (18func main() {19 p := prog.MakeTarget("linux", "amd64", "test").Prog()20 p.MakeDataArg(1, []byte("Hello World"))21 fmt.Println(p.Serialize())22}23syz_open_dev$1(0x0, "Hello World", 0x0)24syz_open_dev$1(0x0, "Hello World", 0x0)25import (26func main() {27 p := prog.MakeTarget("linux", "amd64", "test").Prog()28 p.MakeResultArg(1, 0)29 fmt.Println(p.Serialize())30}31syz_open_dev$1(0x0, 0x0, 0x0)32syz_open_dev$1(0x0, 0x0, 0x0)
MakeConstArg
Using AI Code Generation
1import (2func main() {3 p := prog.MakeTarget("linux", "amd64", "test", "syzkaller")4 a := prog.MakeConstArg(p.Target, p.Target.ConstMap["AF_INET"], 2)5 fmt.Println(a)6}7Const{AF_INET}[2]8import (9func main() {10 p := prog.MakeTarget("linux", "amd64", "test", "syzkaller")11 a := prog.MakeResultArg(p.Target, p.Target.ConstMap["AF_INET"], 2)12 fmt.Println(a)13}14Result{Const{AF_INET}[2]}15import (16func main() {17 p := prog.MakeTarget("linux", "amd64", "test", "syzkaller")18 a := prog.MakeReturnArg(p.Target, p.Target.ConstMap["AF_INET"], 2)19 fmt.Println(a)20}21Return{Const{AF_INET}[2]}22import (23func main() {24 p := prog.MakeTarget("linux", "amd64", "test", "syzkaller")25 a := prog.MakePointerArg(p.Target, prog.MakeConstArg(p.Target, p.Target.ConstMap["AF_INET"], 2), 0)26 fmt.Println(a)27}28Ptr{Const{AF_INET}[2]}29import (30func main() {31 p := prog.MakeTarget("linux", "amd64", "test
MakeConstArg
Using AI Code Generation
1import (2func main() {3 p := compiler.Prog{}4 c := compiler.ConstArg{}5 c = p.MakeConstArg(1, 1)6 fmt.Printf("The value of c is: %v7}8The value of c is: {1 1}9import (10func main() {11 p := compiler.Prog{}12 c := compiler.ConstArg{}13 c = p.MakeConstArg(1, 1)14 fmt.Printf("The value of c is: %v15}16The value of c is: {1 1}17import (18func main() {19 p := compiler.Prog{}20 c := compiler.ConstArg{}21 c = p.MakeConstArg(1, 1)22 fmt.Printf("The value of c is: %v23}24The value of c is: {1 1}25import (26func main() {27 p := compiler.Prog{}28 c := compiler.ConstArg{}
MakeConstArg
Using AI Code Generation
1import (2func main() {3 p.MakeConstArg(1, 2)4 fmt.Println(p.a)5}6import (7type prog struct {8}9func (p *prog) MakeConstArg(a, b int) {10}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!