{"modulePath":"github.com/aquasecurity/tracee","version":"v0.24.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package bufferdecoder\n\nPackage bufferdecoder implements simple translation between byte sequences and the user-defined structs.\n\nThe package favors efficiency over flexibility. The provided API allows fast decoding of byte sequence sent by the Tracee eBPF program from kernel-space to user-space.\n\nPackage bufferdecoder implements the structs (protocol indeed) used in the communication between code eBPF running in the Kernel and the Tracee-eBPF user-space application.\n\n## Functions\n\n```go\nfunc Print16BytesSliceIP(in []byte) string\n```\nPrint16BytesSliceIP prints the IP address encoded as 16 bytes long PrintBytesSliceIP It would be more correct to accept a \\[16]byte instead of variable length slice, but that would cause unnecessary memory copying and type conversions\n\n```go\nfunc PrintUint32IP(in uint32) string\n```\nPrintUint32IP prints the IP address encoded as a uint32\n\n## Types\n\n```go\ntype BinType uint8\n```\nBinType is an enum that specifies the type of binary data sent in the file perf map binary types should match defined values in ebpf code\n\n```go\nconst (\n\tSendVfsWrite BinType = iota + 1\n\tSendMprotect\n\tSendKernelModule\n\tSendBpfObject\n\tSendVfsRead\n)\n```\n\n```go\ntype BpfObjectMeta struct {\n\tName [16]byte\n\tRand uint32\n\tPid  uint32\n\tSize uint32\n}\n```\n\n```go\nfunc (BpfObjectMeta) GetSizeBytes() uint32\n```\n\n```go\ntype ChunkMeta struct {\n\tBinType  BinType\n\tCgroupID uint64\n\tMetadata [28]byte\n\tSize     int32\n\tOff      uint64\n}\n```\n\n```go\nfunc (ChunkMeta) GetSizeBytes() uint32\n```\n\n```go\ntype EbpfDecoder struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc New(rawBuffer []byte, typeDecoder TypeDecoder) *EbpfDecoder\n```\nNew creates and initializes a new EbpfDecoder using rawBuffer as its initial content. The EbpfDecoder takes ownership of rawBuffer, and the caller should not use rawBuffer after this call. New is intended to prepare a buffer to read existing data from it, translating it to protocol defined structs. The protocol is specific between the Trace eBPF program and the Tracee-eBPF user space application.\n\n```go\nfunc (decoder *EbpfDecoder) BuffLen() int\n```\nBuffLen returns the total length of the buffer owned by decoder.\n\n```go\nfunc (decoder *EbpfDecoder) BytesRead() int\n```\nBytesRead returns the total amount of bytes that decoder has read from its buffer up until now.\n\n```go\nfunc (decoder *EbpfDecoder) DecodeArguments(args []trace.Argument, argnum int, evtFields []events.DataField, evtName string, eventId events.ID) error\n```\nDecodeArguments decodes the remaining buffer's argument values, according to the given event definition. It should be called last, and after decoding the argnum with DecodeUint8.\n\nArgument array passed should be initialized with the size of len(evtFields).\n\n```go\nfunc (decoder *EbpfDecoder) DecodeBool(msg *bool) error\n```\nDecodeBool translates data from the decoder buffer, starting from the decoder cursor, to bool.\n\n```go\nfunc (decoder *EbpfDecoder) DecodeBpfObjectMeta(bpfObjectMeta *BpfObjectMeta) error\n```\nDecodeBpfObjectMeta translates data from the decoder buffer, starting from the decoder cursor, to bufferdecoder.BpfObjectMeta struct.\n\n```go\nfunc (decoder *EbpfDecoder) DecodeBytes(msg []byte, size int) error\n```\nDecodeBytes copies from the decoder buffer, starting from the decoder cursor, to msg, size bytes.\n\n```go\nfunc (decoder *EbpfDecoder) DecodeChunkMeta(chunkMeta *ChunkMeta) error\n```\nDecodeChunkMeta translates data from the decoder buffer, starting from the decoder cursor, to bufferdecoder.ChunkMeta struct.\n\n```go\nfunc (decoder *EbpfDecoder) DecodeContext(eCtx *EventContext) error\n```\nDecodeContext translates data from the decoder buffer, starting from the decoder cursor, to bufferdecoder.EventContext struct.\n\n```go\nfunc (decoder *EbpfDecoder) DecodeInt16(msg *int16) error\n```\nDecodeInt16 translates data from the decoder buffer, starting from the decoder cursor, to int16.\n\n```go\nfunc (decoder *EbpfDecoder) DecodeInt32(msg *int32) error\n```\nDecodeInt32 translates data from the decoder buffer, starting from the decoder cursor, to int32.\n\n```go\nfunc (decoder *EbpfDecoder) DecodeInt32Array(msg []int32, size int) error\n```\nDecodeInt32Array translate from the decoder buffer, starting from the decoder cursor, to msg, size \\* 4 bytes (in order to get int32).\n\n```go\nfunc (decoder *EbpfDecoder) DecodeInt64(msg *int64) error\n```\nDecodeInt64 translates data from the decoder buffer, starting from the decoder cursor, to int64.\n\n```go\nfunc (decoder *EbpfDecoder) DecodeInt8(msg *int8) error\n```\nDecodeInt8 translates data from the decoder buffer, starting from the decoder cursor, to int8.\n\n```go\nfunc (decoder *EbpfDecoder) DecodeKernelModuleMeta(kernelModuleMeta *KernelModuleMeta) error\n```\nDecodeKernelModuleMeta translates data from the decoder buffer, starting from the decoder cursor, to bufferdecoder.KernelModuleMeta struct.\n\n```go\nfunc (decoder *EbpfDecoder) DecodeMprotectWriteMeta(mprotectWriteMeta *MprotectWriteMeta) error\n```\nDecodeMprotectWriteMeta translates data from the decoder buffer, starting from the decoder cursor, to bufferdecoder.MprotectWriteMeta struct.\n\n```go\nfunc (decoder *EbpfDecoder) DecodeSlimCred(slimCred *SlimCred) error\n```\nDecodeSlimCred translates data from the decoder buffer, starting from the decoder cursor, to SlimCred struct.\n\n```go\nfunc (decoder *EbpfDecoder) DecodeUint16(msg *uint16) error\n```\nDecodeUint16 translates data from the decoder buffer, starting from the decoder cursor, to uint16.\n\n```go\nfunc (decoder *EbpfDecoder) DecodeUint16BigEndian(msg *uint16) error\n```\nDecodeUint16BigEndian translates data from the decoder buffer, starting from the decoder cursor, to uint16.\n\n```go\nfunc (decoder *EbpfDecoder) DecodeUint32(msg *uint32) error\n```\nDecodeUint32 translates data from the decoder buffer, starting from the decoder cursor, to uint32.\n\n```go\nfunc (decoder *EbpfDecoder) DecodeUint32BigEndian(msg *uint32) error\n```\nDecodeUint32BigEndian translates data from the decoder buffer, starting from the decoder cursor, to uint32.\n\n```go\nfunc (decoder *EbpfDecoder) DecodeUint64(msg *uint64) error\n```\nDecodeUint64 translates data from the decoder buffer, starting from the decoder cursor, to uint64.\n\n```go\nfunc (decoder *EbpfDecoder) DecodeUint64Array(msg *[]uint64) error\n```\nDecodeUint64Array translate from the decoder buffer, starting from the decoder cursor, to msg, size \\* 8 bytes (in order to get int64).\n\n```go\nfunc (decoder *EbpfDecoder) DecodeUint8(msg *uint8) error\n```\nDecodeUint8 translates data from the decoder buffer, starting from the decoder cursor, to uint8.\n\n```go\nfunc (decoder *EbpfDecoder) DecodeVfsFileMeta(vfsFileMeta *VfsFileMeta) error\n```\nDecodeVfsFileMeta translates data from the decoder buffer, starting from the decoder cursor, to bufferdecoder.VfsFileMeta struct.\n\n```go\nfunc (decoder *EbpfDecoder) MoveCursor(n int) int\n```\nMoveCursor moves the buffer cursor over n bytes. This is useful to skip unwanted data. It returns the new cursor position. If the cursor overflows (length of buffer is not overflow but end of buffer), it will not move and will return the same value.\n\n```go\nfunc (decoder *EbpfDecoder) ReadBytesLen(len int) ([]byte, error)\n```\nReadBytesLen is a helper which allocates a known size bytes buffer and decodes the bytes from the buffer into it.\n\n```go\nfunc (decoder *EbpfDecoder) SetBuffer(newBuffer []byte)\n```\nSetBuffer resets the decoder with a new buffer and resets the cursor to 0. This allows reusing decoder instances from a pool.\n\n```go\ntype ErrBufferTooShort struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (e ErrBufferTooShort) Error() string\n```\n\n```go\ntype EventContext struct {\n\tTs uint64\n\n\t// task_context start\n\tStartTime       uint64\n\tCgroupID        uint64\n\tPid             uint32\n\tTid             uint32\n\tPpid            uint32\n\tHostPid         uint32\n\tHostTid         uint32\n\tHostPpid        uint32\n\tUid             uint32\n\tMntID           uint32\n\tPidID           uint32\n\tComm            [16]byte\n\tUtsName         [16]byte\n\tFlags           uint32\n\tLeaderStartTime uint64\n\tParentStartTime uint64\n\n\tEventID         events.ID // int32\n\tSyscall         int32\n\tRetval          int64\n\tStackID         uint32\n\tProcessorId     uint16\n\tPoliciesVersion uint16\n\tMatchedPolicies uint64\n}\n```\nEventContext contains common metadata that is collected for all types of events.\n\nNOTE: Use pahole to ensure this struct reflects the \\`event\\_context“ struct in the eBPF code.\n\n```go\nfunc (EventContext) GetSizeBytes() int\n```\n\n```go\ntype KernelModuleMeta struct {\n\tDevID uint32\n\tInode uint64\n\tPid   uint32\n\tSize  uint32\n}\n```\n\n```go\nfunc (KernelModuleMeta) GetSizeBytes() uint32\n```\n\n```go\ntype MprotectWriteMeta struct {\n\tTs  uint64\n\tPid uint32\n}\n```\n\n```go\nfunc (MprotectWriteMeta) GetSizeBytes() uint32\n```\n\n```go\ntype SlimCred struct {\n\tUid            uint32 /* real UID of the task */\n\tGid            uint32 /* real GID of the task */\n\tSuid           uint32 /* saved UID of the task */\n\tSgid           uint32 /* saved GID of the task */\n\tEuid           uint32 /* effective UID of the task */\n\tEgid           uint32 /* effective GID of the task */\n\tFsuid          uint32 /* UID for VFS ops */\n\tFsgid          uint32 /* GID for VFS ops */\n\tUserNamespace  uint32 /* User Namespace of the of the event */\n\tSecureBits     uint32 /* SUID-less security management */\n\tCapInheritable uint64 /* caps our children can inherit */\n\tCapPermitted   uint64 /* caps we're permitted */\n\tCapEffective   uint64 /* caps we can actually use */\n\tCapBounding    uint64 /* capability bounding set */\n\tCapAmbient     uint64 /* Ambient capability set */\n}\n```\nSlimCred struct is a slim version of the kernel's cred struct it is used to unmarshal binary data and therefore should match (bit by bit) to the \\`slim\\_cred\\_t\\` struct in the ebpf code. ANY CHANGE TO THIS STRUCT WILL BE REQUIRED ALSO TO detect.SlimCred and bufferdecoder.SlimCred\n\n```go\nfunc (s SlimCred) GetSizeBytes() uint32\n```\n\n```go\ntype TypeDecoder []map[string]presentorFunc\n```\n\n```go\nfunc NewTypeDecoder() TypeDecoder\n```\n\n```go\ntype VfsFileMeta struct {\n\tDevID uint32\n\tInode uint64\n\tMode  uint32\n\tPid   uint32\n}\n```\n\n```go\nfunc (VfsFileMeta) GetSizeBytes() uint32\n```\n\n","path":"github.com/aquasecurity/tracee/pkg/bufferdecoder","name":"bufferdecoder","synopsis":"Package bufferdecoder implements simple translation between byte sequences and the user-defined structs.","isRedistributable":true}
