diff --git a/cmd/aa-log/main.go b/cmd/aa-log/main.go index 1d91bc59..7536f9c5 100644 --- a/cmd/aa-log/main.go +++ b/cmd/aa-log/main.go @@ -40,7 +40,10 @@ type AppArmorLog map[string]string // AppArmorLogs describes all apparmor log entries type AppArmorLogs []AppArmorLog -var quoted bool +var ( + quoted bool + isHexa = regexp.MustCompile("^[0-9A-Fa-f]+$") +) func splitQuoted(r rune) bool { if r == '"' { @@ -56,6 +59,14 @@ func toQuote(str string) string { return str } +func decodeHex(str string) string { + if isHexa.MatchString(str) { + bs, _ := hex.DecodeString(str) + return string(bs) + } + return str +} + func removeDuplicateLog(logs []string) []string { list := []string{} keys := map[string]interface{}{"": true} @@ -113,6 +124,10 @@ func NewApparmorLogs(file *os.File, profile string) AppArmorLogs { aa[kv[0]] = strings.Trim(kv[1], `"`) } } + aa["profile"] = decodeHex(aa["profile"]) + if name, ok := aa["name"]; ok { + aa["name"] = decodeHex(name) + } aaLogs = append(aaLogs, aa) }