From 5970632c3106fdf78d65719fb6950292e096d42a Mon Sep 17 00:00:00 2001 From: yo Date: Tue, 4 Jan 2022 10:47:10 +0100 Subject: [PATCH] AUT_TEXT support --- libbsm.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/libbsm.go b/libbsm.go index 1064b51..53cf84e 100644 --- a/libbsm.go +++ b/libbsm.go @@ -275,6 +275,12 @@ type Exit struct { Ret uint32 } +type Text struct { + Length uint16 + Text []byte +} + + /* Utilities */ func PrintIpv6FromInt(ipv6int [4]uint32) string { //return fmt.Sprintf("%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x", @@ -1281,6 +1287,37 @@ func (e *Exit) Print(file *os.File, delimiter string, flags int) { } } +func NewText(t Text) *Text { + return &Text{ + Length: t.Length, + Text: t.Text, + } +} + +func (t *Text) GetType() uint8 { + return AUT_TEXT +} + +func (t *Text) LoadFromBinary(file *os.File) error { + err := binary.Read(file, binary.BigEndian, &t.Length) + if err != nil { return fmt.Errorf("Unable to read Text.Length from file: %v", err) } + + + text := make([]byte, t.Length) + err = binary.Read(file, binary.BigEndian, &text) + if err != nil { return fmt.Errorf("Unable to read Text.Text from file: %v", err) } + t.Text = text + + return nil +} + +func (t *Text) Print(file *os.File, delimiter string, flags int) { + fmt.Fprintf(file, "text%s%s", delimiter, t.Text) + if 0 == (flags & PRT_ONELINE) { + fmt.Fprintf(file, "\n") + } +} + func readRecordToStruct(file *os.File) (Record, error) { var rec Record @@ -1376,6 +1413,11 @@ func readRecordToStruct(file *os.File) (Record, error) { err := p.LoadFromBinary(file) if err != nil { return rec, fmt.Errorf("Unable to read file: %v", err) } return NewProcess64Ex(p), nil + case AUT_TEXT: + var t Text + err := t.LoadFromBinary(file) + if err != nil { return rec, fmt.Errorf("Unable to read file: %v", err) } + return NewText(t), nil } startOf, _ := file.Seek(0, io.SeekCurrent)