/
main.go
94 lines (79 loc) · 1.74 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
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
package main
import (
"flag"
"fmt"
"os"
"github.com/CTSRD-SOAAP/gosoaap"
"github.com/dustin/go-humanize"
)
func main() {
//
// Command-line arguments:
//
output := flag.String("output", "-", "output GraphViz file")
flag.Parse()
if len(flag.Args()) != 1 {
printUsage()
return
}
input := flag.Args()[0]
//
// Open input and output files:
//
f, err := os.Open(input)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
return
}
var outfile *os.File
if *output == "-" {
outfile = os.Stdout
} else {
outfile, err = os.Create(*output)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
return
}
}
//
// Parse SOAAP results:
//
results, err := soaap.LoadResults(f, reportProgress)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
return
}
fmt.Println("Loaded:")
fmt.Println(" -", human(len(results.Vulnerabilities)),
"past-vulnerability warnings")
fmt.Println(" -", human(len(results.PrivateAccess)),
"private data accesses")
fmt.Println(" -", human(len(results.Traces)),
"call graph traces")
//
// Encode it as a gob of data:
//
fmt.Print("Encoding...")
results.Save(outfile)
fmt.Println(" done.")
outfile.Sync()
}
func printUsage() {
fmt.Fprintf(os.Stderr,
"Usage: soaap-graph [options] <input file>\n\n")
fmt.Fprintf(os.Stderr, "Options:\n")
flag.PrintDefaults()
}
//
// Find a human-readable version of the size of a slice.
//
// Note that the argument had better be a slice, but the Go compiler is
// incapable of checking this type requirement for us!
// (see https://github.com/golang/go/wiki/InterfaceSlice for details)
//
func human(count int) string {
return humanize.SI(float64(count), "")
}
func reportProgress(message string) {
fmt.Println(message)
}