-
Notifications
You must be signed in to change notification settings - Fork 32
/
ssdeep.go
72 lines (61 loc) · 1.32 KB
/
ssdeep.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"flag"
"fmt"
"os"
"github.com/glaslos/ssdeep"
)
var (
// VERSION is set by the makefile
VERSION = "v0.0.0"
// BUILDDATE is set by the makefile
BUILDDATE = ""
)
var (
forceHash bool
showVersion bool
)
func main() {
fmt.Printf("ssdeep,%s--blocksize:hash:hash,filename\n", VERSION)
flag.BoolVar(&forceHash, "force", false, "Force hash on error or invalid input length")
flag.BoolVar(&showVersion, "version", false, "Print version")
flag.Parse()
if showVersion {
fmt.Printf("%s %s\n", VERSION, BUILDDATE)
return
}
ssdeep.Force = forceHash
args := flag.Args()
if len(args) < 1 {
fmt.Println("Please provide a file path: ./ssdeep /tmp/file")
os.Exit(1)
}
h1, err := ssdeep.FuzzyFilename(args[0])
if err != nil && !ssdeep.Force {
fmt.Println(err)
os.Exit(1)
}
if len(args) == 2 {
var h2 string
h2, err = ssdeep.FuzzyFilename(args[1])
if err != nil && !ssdeep.Force {
fmt.Println(err)
os.Exit(1)
}
var score int
score, err = ssdeep.Distance(h1, h2)
if score != 0 {
fmt.Printf("%s matches %s (%d)\n", args[0], args[1], score)
} else if err != nil {
fmt.Println(err)
} else {
fmt.Println("The files doesn't match")
}
} else {
if err != nil {
fmt.Printf("%s,\"%s\"\n%s\n", h1, args[0], err)
} else {
fmt.Printf("%s,\"%s\"\n", h1, args[0])
}
}
}