-
Notifications
You must be signed in to change notification settings - Fork 1
/
do_pastseed.go
55 lines (49 loc) · 1.1 KB
/
do_pastseed.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
package main
import (
"bufio"
"fmt"
"os"
"regexp"
"github.com/FuzzyMonkeyCo/monkey/pkg/code"
"github.com/FuzzyMonkeyCo/monkey/pkg/cwid"
rt "github.com/FuzzyMonkeyCo/monkey/pkg/runtime"
)
var rePastseed = regexp.MustCompile(rt.PastSeedMagic + ` ([^\s]+)`)
// Looks in the logs for the youngest seed that triggered a bug
// Only ever prints best seed and a newline character
// so it can be used as --seed=$(monkey pastseed)
func doPastseed(starfile string) int {
for offset := uint64(1); true; offset++ {
var seed string
ret := -1
func() {
if err := cwid.MakePwdID(binName, starfile, offset); err != nil {
// Fails silently
ret = code.Failed
return
}
fn := cwid.LogFile()
f, err := os.Open(fn)
if err != nil {
ret = code.Failed
return
}
defer f.Close()
s := bufio.NewScanner(f)
for s.Scan() {
matches := rePastseed.FindStringSubmatch(s.Text())
if len(matches) != 0 && matches[1] != "" {
seed = matches[1]
}
}
}()
if ret != -1 {
return ret
}
if seed != "" {
fmt.Println(seed)
return code.OK
}
}
return code.Failed
}