forked from BoB-WebFuzzing/fuzzer
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtimer.go
More file actions
60 lines (47 loc) · 1.18 KB
/
Copy pathtimer.go
File metadata and controls
60 lines (47 loc) · 1.18 KB
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
package main
import (
"fmt"
"io/ioutil"
"os"
"os/signal"
"syscall"
"time"
)
func runTimer(fuzzingPath string, timeout int) {
timerChan := make(chan os.Signal, 1)
interval := 1 * time.Second
var crashes int
signal.Notify(timerChan, syscall.SIGINT, syscall.SIGTERM)
time.Sleep(interval)
for i := 0; i < timeout; i++ {
select {
case <-timerChan:
fmt.Println("\nInterrupt signal received. Exiting...")
return
default:
progress := float64(i) / float64(timeout) * 100
files, err := ioutil.ReadDir(fuzzingPath + "/output/default/crashes")
if err != nil {
panic(err)
}
for _, file := range files {
crashes = 0
if !file.IsDir() {
if startsWith(file.Name(), "id:") {
crashes++
}
}
}
fmt.Print("\033[K")
fmt.Printf(" [%ds/%ds %.2f%%] completed", i, timeout, progress)
fmt.Printf(" found total \033[32;5;3m%d crashes\033[0m\r", crashes)
time.Sleep(interval)
}
}
termChan <- syscall.SIGTERM
fmt.Printf(" [%ds/%ds %.2f%%] completed\n", timeout, timeout, 100.0)
fmt.Println("Task completed!")
}
func startsWith(str string, prefix string) bool {
return len(str) >= len(prefix) && str[:len(prefix)] == prefix
}