-
Notifications
You must be signed in to change notification settings - Fork 50
/
ui.go
204 lines (158 loc) · 4.33 KB
/
ui.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package hashcatlauncher
import (
"errors"
"fmt"
"github.com/ncruces/zenity"
"github.com/zserge/lorca"
)
func (a *App) NewUI() error {
if lorca.LocateChrome() == "" {
return errors.New("Chrome browser not found")
}
ui, err := lorca.New(
"data:text/html,<html><head><title>hashcat.launcher</title></head><body>Loading...</body></html>",
"",
1080,
720,
[]string{"--class=hashcat.launcher"}...,
)
if err != nil {
return err
}
ui.SetBounds(lorca.Bounds{
WindowState: lorca.WindowStateMaximized,
})
a.UI = ui
return nil
}
func (a *App) BindUI() {
a.UI.Bind("GOgetVersion", func() string {
return Version
})
a.UI.Bind("GOscan", func() error {
return a.Scan()
})
a.UI.Bind("GOgetHashes", func() []string {
return a.Hashes
})
a.UI.Bind("GOgetAlgorithms", func() map[int64]string {
return a.Hashcat.Algorithms
})
a.UI.Bind("GOgetDictionaries", func() []string {
return a.Dictionaries
})
a.UI.Bind("GOgetRules", func() []string {
return a.Rules
})
a.UI.Bind("GOgetMasks", func() []string {
return a.Masks
})
a.UI.Bind("GOcreateTask", func(args HashcatArgs, priority int64) error {
return a.NewTask(args, priority)
})
a.UI.Bind("GOstartTask", func(taskID string) error {
if task, ok := a.Tasks[taskID]; ok {
return task.Start()
}
return errors.New("task not found")
})
a.UI.Bind("GOrefreshTask", func(taskID string) error {
if task, ok := a.Tasks[taskID]; ok {
return task.Refresh()
}
return errors.New("task not found")
})
a.UI.Bind("GOpauseTask", func(taskID string) error {
if task, ok := a.Tasks[taskID]; ok {
return task.Pause()
}
return errors.New("task not found")
})
a.UI.Bind("GOresumeTask", func(taskID string) error {
if task, ok := a.Tasks[taskID]; ok {
return task.Resume()
}
return errors.New("task not found")
})
a.UI.Bind("GOcheckpointTask", func(taskID string) error {
if task, ok := a.Tasks[taskID]; ok {
return task.Checkpoint()
}
return errors.New("task not found")
})
a.UI.Bind("GOskipTask", func(taskID string) error {
if task, ok := a.Tasks[taskID]; ok {
return task.Skip()
}
return errors.New("task not found")
})
a.UI.Bind("GOquitTask", func(taskID string) error {
if task, ok := a.Tasks[taskID]; ok {
return task.Quit()
}
return errors.New("task not found")
})
a.UI.Bind("GOpriorityTask", func(taskID string, priority int64) error {
if task, ok := a.Tasks[taskID]; ok {
task.Priority = priority
return nil
}
return errors.New("task not found")
})
a.UI.Bind("GOstartNextTask", func() {
a.StartNextTask()
})
a.UI.Bind("GOrestoreTasks", func() error {
return a.RestoreTasks()
})
a.UI.Bind("GOdeleteTask", func(taskID string) error {
return a.DeleteTask(taskID)
})
a.UI.Bind("GOhashcatDevices", func() (string, error) {
return a.Hashcat.Devices()
})
a.UI.Bind("GOhashcatBenchmark", func(hashMode HashcatHashMode) (string, error) {
return a.Hashcat.Benchmark(hashMode)
})
a.UI.Bind("GOexportConfig", func(config interface{}) (string, error) {
return a.ExportConfig(config)
})
a.UI.Bind("GOsaveHash", func(hash []byte, filename string) (string, error) {
return a.SaveHash(hash, filename)
})
a.UI.Bind("GOsettingsCurrentTaskCounter", func() int {
return a.Settings.CurrentTaskCounter()
})
a.UI.Bind("GOsettingsNextTaskCounter", func() int {
return a.Settings.NextTaskCounter()
})
a.UI.Bind("GOsettingsResetTaskCounter", func() int {
return a.Settings.ResetTaskCounter()
})
a.UI.Bind("GOsettingsCurrentLanguage", func() string {
return a.Settings.CurrentLanguage()
})
a.UI.Bind("GOsettingsChangeLanguage", func(lang string) error {
return a.Settings.ChangeLanguage(lang)
})
a.UI.Bind("GOsaveDialog", func() (string, error) {
return zenity.SelectFileSave(zenity.ConfirmOverwrite())
})
}
func (a *App) LoadUI() error {
return a.UI.Load(fmt.Sprintf("http://%s/frontend/hashcat.launcher/build", a.Server.Addr()))
}
func (a *App) RestrictUI() {
a.UI.Eval(`window.addEventListener("contextmenu", function(e) { e.preventDefault(); })`)
a.UI.Eval(`
document.onkeydown = function (event) {
if (event.ctrlKey) { // Ctrl is pressed
// Allown only A, X, C, V
if (event.keyCode != 65 && event.keyCode != 88 && event.keyCode != 67 && event.keyCode != 86)
return false;
}
if (event.keyCode >= 112 && event.keyCode <= 123) // F1 to F12
return false;
}
`)
}