Skip to content

Commit

Permalink
支持hexdump和颜色
Browse files Browse the repository at this point in the history
  • Loading branch information
SeeFlowerX committed Jan 2, 2024
1 parent 8e2c9e8 commit ee16894
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions user/argtype/argtype_complex.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ func parse_BUFFER(ctx IArgType, ptr uint64, buf *bytes.Buffer, parse_more bool)
if err := binary.Read(buf, binary.LittleEndian, &payload); err != nil {
panic(err)
}
if ctx.GetDumpHex() {
return fmt.Sprintf("0x%x%s", ptr, arg.HexFormat(payload, ctx.GetColor()))
}
return fmt.Sprintf("0x%x%s", ptr, arg.Format(payload))
}

Expand Down
24 changes: 24 additions & 0 deletions user/argtype/iargtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ type IArgType interface {
SetTypeIndex(uint32)
GetTypeIndex() uint32
SetParentIndex(uint32)
SetDumpHex(bool)
SetColor(bool)
GetDumpHex() bool
GetColor() bool
GetParentIndex() uint32
GetSize() uint32
AddOpList(p IArgType)
Expand All @@ -47,6 +51,8 @@ type ArgType struct {
// 可选的别名
AliaNames []string
ParseCB ParseFN
DumpHex bool
Color bool
}

func (this *ArgType) Init(name string, base_type, type_index, size uint32) {
Expand All @@ -67,6 +73,8 @@ func (this *ArgType) Clone() IArgType {
at.OpList = append(at.OpList, this.OpList...)
at.AliaNames = append(at.AliaNames, this.AliaNames...)
at.ParseCB = this.ParseCB
at.DumpHex = this.DumpHex
at.Color = this.Color
return &at
}

Expand All @@ -90,6 +98,22 @@ func (this *ArgType) DumpOpList() {
}
}

func (this *ArgType) SetDumpHex(dump_hex bool) {
this.DumpHex = dump_hex
}

func (this *ArgType) SetColor(color bool) {
this.Color = color
}

func (this *ArgType) GetDumpHex() bool {
return this.DumpHex
}

func (this *ArgType) GetColor() bool {
return this.Color
}

func (this *ArgType) AddOp(op *OpConfig) {
this.OpList = append(this.OpList, OPM.AddOp(op).Index)
}
Expand Down
14 changes: 14 additions & 0 deletions user/config/config_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type StackUprobeConfig struct {
LibName string
LibPath string
Points []*UprobeArgs
DumpHex bool
Color bool
}

func ParseStrAsNum(v string) (uint64, error) {
Expand Down Expand Up @@ -126,6 +128,8 @@ func (this *StackUprobeConfig) ParseArgType(arg_str string, point_arg *PointArg)
at = argtype.R_BUFFER_REG(GetRegIndex(size_str))
}
}
at.SetDumpHex(this.DumpHex)
at.SetColor(this.Color)
point_arg.SetTypeIndex(at.GetTypeIndex())
// 这个设定用于指示是否进一步读取和解析
point_arg.SetGroupType(EBPF_UPROBE_ENTER)
Expand Down Expand Up @@ -206,6 +210,14 @@ func (this *StackUprobeConfig) SetArgFilterRule(arg_filter *[]ArgFilter) {
this.arg_filter = arg_filter
}

func (this *StackUprobeConfig) SetDumpHex(dump_hex bool) {
this.DumpHex = dump_hex
}

func (this *StackUprobeConfig) SetColor(color bool) {
this.Color = color
}

func (this *StackUprobeConfig) Parse_HookPoint(configs []string) (err error) {
if this.LibPath == "" {
return errors.New("library is empty, plz set with -l/--lib")
Expand Down Expand Up @@ -514,6 +526,8 @@ func (this *ModuleConfig) InitSyscallConfig() {

func (this *ModuleConfig) InitStackUprobeConfig() {
config := &StackUprobeConfig{}
config.SetDumpHex(this.DumpHex)
config.SetColor(this.Color)
config.SetArgFilterRule(&this.ArgFilterRule)
this.StackUprobeConf = config
}
Expand Down

0 comments on commit ee16894

Please sign in to comment.