(configs []string)
| 328 | } |
| 329 | |
| 330 | func (this *StackUprobeConfig) Parse_HookPoint(configs []string) (err error) { |
| 331 | if this.LibPath == "" { |
| 332 | return errors.New("library is empty, plz set with -l/--lib") |
| 333 | } |
| 334 | if len(configs) > 6 { |
| 335 | return errors.New("max uprobe hook point count is 6") |
| 336 | } |
| 337 | |
| 338 | // strstr+0x0[str,str] 命中 strstr + 0x0 时将x0和x1读取为字符串 |
| 339 | // write[int,buf:128,int] 命中 write 时将x0读取为int、x1读取为字节数组、x2读取为int |
| 340 | for point_index, config_str := range configs { |
| 341 | exit_read := false |
| 342 | bind_syscall := false |
| 343 | if strings.HasSuffix(config_str, "]s") { |
| 344 | // 临时方案 将 uprobe 用法绑定到 syscall 上 |
| 345 | config_str = config_str[:len(config_str)-1] |
| 346 | bind_syscall = true |
| 347 | } |
| 348 | if strings.HasSuffix(config_str, "]ss") { |
| 349 | // 两个s表示对于sys_exit也要进行详细输出 |
| 350 | config_str = config_str[:len(config_str)-2] |
| 351 | exit_read = true |
| 352 | bind_syscall = true |
| 353 | } |
| 354 | |
| 355 | var exit_offset uint64 = 0x0 |
| 356 | items := strings.Split(config_str, "]") |
| 357 | if len(items) == 2 { |
| 358 | config_str = items[0] + "]" |
| 359 | if items[1] != "" { |
| 360 | exit_read = true |
| 361 | exit_offset = util.StrToNum64(items[1]) |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | reg := regexp.MustCompile(`(\w+)(\+0x[[:xdigit:]]+)?(\[.+?\])?`) |
| 366 | match := reg.FindStringSubmatch(config_str) |
| 367 | |
| 368 | if len(match) > 0 { |
| 369 | hook_point := &UprobeArgs{} |
| 370 | hook_point.BindSyscall = bind_syscall |
| 371 | hook_point.ExitRead = exit_read |
| 372 | hook_point.ExitOffset = exit_offset |
| 373 | hook_point.Index = uint32(point_index) |
| 374 | hook_point.Offset = 0x0 |
| 375 | hook_point.LibPath = this.LibPath |
| 376 | hook_point.RealFilePath = this.RealFilePath |
| 377 | hook_point.NonElfOffset = this.NonElfOffset |
| 378 | sym_or_off := match[1] |
| 379 | hook_point.Name = sym_or_off |
| 380 | if strings.HasPrefix(sym_or_off, "0x") { |
| 381 | offset, err := strconv.ParseUint(strings.TrimPrefix(sym_or_off, "0x"), 16, 64) |
| 382 | if err != nil { |
| 383 | return errors.New(fmt.Sprintf("parse for %s failed, sym_or_off:%s err:%v", config_str, sym_or_off, err)) |
| 384 | } |
| 385 | hook_point.Offset = offset |
| 386 | hook_point.Symbol = "" |
| 387 | } else { |
no test coverage detected