/
graph.go
74 lines (68 loc) · 1.91 KB
/
graph.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
package taint
import (
"strconv"
"github.com/cokeBeer/goot/pkg/example/dataflow/taint/rule"
"golang.org/x/tools/go/ssa"
)
// TaintGraph represents a graph contain static call nodes and edges
type TaintGraph struct {
Nodes *map[string]*Node
Edges *map[string]*Edge
}
// NewTaintGraph returns a TaintGraph
func NewTaintGraph(allFuncs *map[*ssa.Function]bool, ruler rule.Ruler) *TaintGraph {
callGraph := new(TaintGraph)
nodes := make(map[string]*Node)
edges := make(map[string]*Edge)
callGraph.Nodes = &nodes
callGraph.Edges = &edges
for f := range *allFuncs {
if f.Signature.Recv() != nil {
node := &Node{Function: f, Canonical: f.String(), Index: 0, Out: make([]*Edge, 0), In: make([]*Edge, 0)}
decidePropertry(node, ruler)
node.IsStatic = true
(*callGraph.Nodes)[f.String()+"#"+strconv.Itoa(0)] = node
n := f.Signature.Params().Len()
for i := 0; i < n; i++ {
node := &Node{Function: f, Canonical: f.String(), Index: i + 1, Out: make([]*Edge, 0), In: make([]*Edge, 0)}
decidePropertry(node, ruler)
node.IsStatic = true
(*callGraph.Nodes)[f.String()+"#"+strconv.Itoa(i+1)] = node
}
} else {
n := f.Signature.Params().Len()
for i := 0; i < n; i++ {
node := &Node{Function: f, Canonical: f.String(), Index: i, Out: make([]*Edge, 0), In: make([]*Edge, 0)}
decidePropertry(node, ruler)
node.IsStatic = true
(*callGraph.Nodes)[f.String()+"#"+strconv.Itoa(i)] = node
}
}
}
return callGraph
}
// Node represents a taint node
type Node struct {
Function *ssa.Function
IsSignature bool
IsMethod bool
IsStatic bool
IsSource bool
IsSink bool
IsIntra bool
Canonical string
Index int
Out []*Edge
In []*Edge
}
// Edge represents a taint edge
type Edge struct {
From string
FromIndex int
To string
ToIndex int
ToIsMethod bool
ToIsSink bool
ToIsSignature bool
ToIsStatic bool
}