This repository has been archived by the owner on May 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
79 lines (66 loc) · 1.99 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
package main
import (
"errors"
"fmt"
"github.com/ericr/solanalyzer/analyzers"
"github.com/ericr/solanalyzer/reports"
"github.com/ericr/solanalyzer/sessions"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/x-cray/logrus-prefixed-formatter"
"time"
)
var version = "0.1-beta"
type options struct {
Verbose bool
}
func main() {
options := &options{}
rootCmd := &cobra.Command{
Use: "solanalyzer path",
Short: "SolAnalyzer is a static analyzer for the Solidity programming " +
"language, with a focus on finding security bugs.",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("Missing target path")
}
return nil
},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
logrus.SetFormatter(&prefixed.TextFormatter{FullTimestamp: true})
setLoggingLevel(options)
},
Run: func(cmd *cobra.Command, args []string) {
printHeader()
logrus.Info("Starting new session")
session := sessions.NewSession()
logrus.Info("Parsing sources")
session.ParsePath(args)
if analyzer, err := analyzers.NewCompilerVersionAnalyzer(); err != nil {
logrus.Warnf("Error initializing compiler version analyzer: %s", err)
} else {
session.AddAnalyzer(analyzer)
}
session.AddAnalyzer(&analyzers.FunctionVisibilityAnalyzer{})
session.AddAnalyzer(&analyzers.CallGraphAnalyzer{})
logrus.Info("Analyzing sources")
session.Analyze()
logrus.Info("Generating report")
session.GenerateReport(&reports.ConsoleReport{})
},
}
rootCmd.PersistentFlags().BoolVarP(&options.Verbose, "verbose", "v", false,
"verbose output")
rootCmd.Execute()
}
func setLoggingLevel(options *options) {
if options.Verbose {
logrus.SetLevel(logrus.DebugLevel)
}
}
func printHeader() {
fmt.Printf("\nSolAnalyzer v%s\n", version)
fmt.Printf("Copyright %d Eric Rafaloff\n\n", time.Now().Year())
fmt.Printf("This is beta software. Please report issues at " +
"https://github.com/EricR/solanalyzer/issues/.\n\n")
}