-
Notifications
You must be signed in to change notification settings - Fork 1
/
detect.go
120 lines (105 loc) · 2.53 KB
/
detect.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package gdth
import (
"fmt"
"strconv"
"strings"
)
// Idk, I'll look at a way of doing Enum or Struct. This looks ugly lol
const (
Color_reset = "\033[0m"
Color_cyan = "\033[36m"
Color_red = "\033[31m"
Color_green = "\033[32m"
)
func printTableLine(paddings ...int) string {
sum := 0
for _, v := range paddings {
sum += v
}
result := strings.Repeat("-", sum)
if sum%2 == 0 {
result += strings.Repeat("-", 8)
} else {
result += strings.Repeat("-", 7)
}
return result + "+"
}
// Text will be in the middle
func prepareTableItem(item string, padding int) string {
paddingToApply := (padding - len(item))
result := ""
if paddingToApply%2 != 0 {
result += " "
}
result += strings.Repeat(" ", paddingToApply/2) + item + strings.Repeat(" ", paddingToApply/2) + " |"
return result
}
func PrintTable(hashes []HashInfo, headers []string, paddings ...int) {
fmt.Println(printTableLine(paddings...))
fmt.Print(prepareTableItem(headers[0], paddings[0]))
fmt.Print(prepareTableItem(headers[1], paddings[1]))
fmt.Print(prepareTableItem(headers[2], paddings[2]))
fmt.Println(prepareTableItem(headers[3], paddings[3]))
fmt.Println(printTableLine(paddings...))
for _, v := range hashes {
fmt.Print(prepareTableItem(v.Name, paddings[0]))
if v.Hashcat == -1 {
fmt.Print(prepareTableItem("N/A", paddings[1]))
} else {
fmt.Print(prepareTableItem(strconv.Itoa(v.Hashcat), paddings[1]))
}
if v.John == "" {
fmt.Print(prepareTableItem("N/A", paddings[2]))
} else {
fmt.Print(prepareTableItem(v.John, paddings[2]))
}
if v.Extended {
fmt.Print(prepareTableItem("True", paddings[3]))
} else {
fmt.Print(prepareTableItem("False", paddings[3]))
}
fmt.Println()
}
fmt.Println(printTableLine(paddings...))
}
func PrintCSV(hashes []HashInfo) {
fmt.Println("Name,HashCat,John,Extended")
for _, v := range hashes {
fmt.Print(v.Name + ",")
if v.Hashcat == -1 {
fmt.Print("N/A,")
} else {
fmt.Print(strconv.Itoa(v.Hashcat) + ",")
}
if v.John == "" {
fmt.Print("N/A,")
} else {
fmt.Print(v.John + ",")
}
if v.Extended {
fmt.Println("True")
} else {
fmt.Println("False")
}
}
}
// returns a slice of possible hashes
func Detect(hash string) []HashInfo {
var hashes []HashInfo
for _, proto := range prototypes {
if proto.match(hash) {
hashes = append(hashes, proto.mode...)
}
}
return hashes
}
func IsSupported(hashcatID int) bool {
for _, proto := range prototypes {
for _, mode := range proto.mode {
if mode.Hashcat == hashcatID {
return true
}
}
}
return false
}