Skip to content

Commit

Permalink
fix formatting for hashdeep when no sha256
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Jul 19, 2022
1 parent b6528f3 commit b7ca767
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions processor/formatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,7 @@ func toJSON(input chan Result) string {

func toHashDeep(input chan Result) string {
var str strings.Builder

// TODO you can turn on/off hashes in hashdeep EG hashdeep -c sha1,sha256 processor/*
// TODO which is not currently supported below


pwd, err := os.Getwd()
if err != nil {
printError(fmt.Sprintf("unable to determine working directory: %s", err.Error()))
Expand All @@ -210,8 +207,14 @@ func toHashDeep(input chan Result) string {
str.WriteString(fmt.Sprintf("## $ %s\n", strings.Join(os.Args, " ")))
str.WriteString("##\n")

for res := range input {
str.WriteString(fmt.Sprintf("%d,%s,%s,%s\n", res.Bytes, res.MD5, res.SHA256, res.File))
if !contains(Hash, "sha256") && !contains(Hash, "all") {
for res := range input {
str.WriteString(fmt.Sprintf("%d,%s,%s\n", res.Bytes, res.MD5, res.File))
}
} else {
for res := range input {
str.WriteString(fmt.Sprintf("%d,%s,%s,%s\n", res.Bytes, res.MD5, res.SHA256, res.File))
}
}

return str.String()
Expand All @@ -231,3 +234,13 @@ func printHashes() {
fmt.Println(fmt.Sprintf(" SHA3-384 (%s)", HashNames.Sha3384))
fmt.Println(fmt.Sprintf(" SHA3-512 (%s)", HashNames.Sha3512))
}

func contains(list []string, v string) bool {
for _, x := range list {
if x == v {
return true
}
}

return false
}

0 comments on commit b7ca767

Please sign in to comment.