-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.go
50 lines (41 loc) · 1.14 KB
/
main.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
package main
import (
"flag"
"fmt"
"github.com/jakewins/findbtc/detector"
"time"
)
func main() {
startOffset := flag.Int64("s", 0, "Start at byte offset")
flag.Parse()
path := flag.Arg(0)
err := detector.Scan(*startOffset, path, func(detection detector.Detection) {
fmt.Printf(
"[main] Found possible wallet trace:\n"+
" %s\n", detection.Description)
}, (&progressReporter{}).onProgress)
if err != nil {
fmt.Printf("[main] Exiting due to error: %s\n", err.Error())
return
}
fmt.Println("[COMPLETE]")
}
const PROGRESS_REPORT_INTERVAL = 10
type progressReporter struct {
lastReport int64
}
func (p *progressReporter) onProgress(pg detector.ProgressInfo) {
now := time.Now().Unix()
if now-PROGRESS_REPORT_INTERVAL > p.lastReport {
p.lastReport = now
additionalTargets := ""
if pg.UnscannedTargets > 0 {
additionalTargets = fmt.Sprintf(" (%d additional targets)", pg.UnscannedTargets)
}
if pg.TotalBytes <= 0 {
fmt.Printf("[%dmb/??mb]%s\n", pg.ScannedBytes/(1024*1024), additionalTargets)
} else {
fmt.Printf("[%.2f%%]%s\n", (float64(pg.ScannedBytes)/float64(pg.TotalBytes))*100, additionalTargets)
}
}
}