Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat: concrete type arguments #4353

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,5 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
kernel.org/pub/linux/libs/security/libcap/psx v1.2.70 // indirect
)

replace github.com/aquasecurity/tracee/types => ./types
28 changes: 23 additions & 5 deletions pkg/bufferdecoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ func (decoder *EbpfDecoder) BuffLen() int {
return len(decoder.buffer)
}

// ReadAmountBytes returns the total amount of bytes that decoder has read from its buffer up until now.
func (decoder *EbpfDecoder) ReadAmountBytes() int {
// BytesRead returns the total amount of bytes that decoder has read from its buffer up until now.
func (decoder *EbpfDecoder) BytesRead() int {
return decoder.cursor
}

// MoveCursor moves the buffer cursor over n bytes. Returns the new cursor position.
func (decoder *EbpfDecoder) MoveCursor(n int) int {
decoder.cursor += n
return decoder.cursor
}

Expand Down Expand Up @@ -107,7 +113,7 @@ func (decoder *EbpfDecoder) DecodeArguments(args []trace.Argument, argnum int, e
args[idx] = arg
}

// Fill missing arguments metadata
// Fill missing arguments
for i := 0; i < len(evtParams); i++ {
if args[i].Value == nil {
args[i].ArgMeta = evtParams[i]
Expand Down Expand Up @@ -260,8 +266,20 @@ func (decoder *EbpfDecoder) DecodeBytes(msg []byte, size int) error {
return nil
}

// DecodeIntArray translate from the decoder buffer, starting from the decoder cursor, to msg, size * 4 bytes (in order to get int32).
func (decoder *EbpfDecoder) DecodeIntArray(msg []int32, size int) error {
// ReadBytesLen is a helper which allocates a known size bytes buffer and decodes
// the bytes from the buffer into it.
func (decoder *EbpfDecoder) ReadBytesLen(len int) ([]byte, error) {
var err error
res := make([]byte, len)
err = decoder.DecodeBytes(res[:], len)
if err != nil {
return nil, errfmt.Errorf("error reading byte array: %v", err)
}
return res, nil
}

// DecodeInt32Array translate from the decoder buffer, starting from the decoder cursor, to msg, size * 4 bytes (in order to get int32).
func (decoder *EbpfDecoder) DecodeInt32Array(msg []int32, size int) error {
offset := decoder.cursor
if len(decoder.buffer[offset:]) < size*4 {
return ErrBufferTooShort
Expand Down
2 changes: 1 addition & 1 deletion pkg/bufferdecoder/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func TestDecodeIntArray(t *testing.T) {
raw = append(raw, 1, 2, 3, 4, 5, 6, 7, 8)
decoder := New(raw)
var obtained [2]int32
err := decoder.DecodeIntArray(obtained[:], 2)
err := decoder.DecodeInt32Array(obtained[:], 2)
assert.Equal(t, nil, err)
rawcp := append(raw, 1, 2, 3, 4, 5, 6, 7, 8)
dataBuff := bytes.NewBuffer(rawcp)
Expand Down
Loading
Loading