-
Notifications
You must be signed in to change notification settings - Fork 7
/
safety_finder.rb
101 lines (90 loc) · 2.71 KB
/
safety_finder.rb
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
95
96
97
98
99
100
101
#!/usr/bin/ruby
#
# stoat - LLVM Based Static Analysis Tool
# Copyright (C) 2015 Mark McCurry
#
# This file is part of stoat.
#
# stoat is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# stoat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with stoat. If not, see <http://www.gnu.org/licenses/>.
#
require 'set'
require 'yaml'
require 'pp'
data = YAML.load_file ARGV[0]
callgraph = data["callgraph"]
whitelist = data["whitelist"]
blacklist = data["blacklist"]
has_code = data["has_code"]
symbols = Set.new
data["callgraph"].each do |key, value|
symbols << key
value.each do |x|
symbols << x
end
end
symbols_known = Hash.new
symbols_unknown = symbols.clone
#Remove already known symbols as the user shouldn't care about them
whitelist.each {|x,_| symbols_unknown.delete x}
blacklist.each {|x,_| symbols_unknown.delete x}
#Remove symbols without a body, as we cannot classify them
del_list = []
symbols_unknown.each do |sym|
if(!callgraph.include? sym)
del_list << sym
if(has_code.include?(sym) && !whitelist.include?(sym))
whitelist[sym] = "Added with no calling funcs"
end
end
end
del_list.each do |x|
symbols_unknown.delete x
end
# Go through the unknown symbol list and find if a function calls all known functions
# If it does, then it is placed in the known symbols list with wheather it is
# realtime or not
while !symbols_unknown.empty?
del_list = []
symbols_unknown.each do |sym|
do_classify = true
safe = true
rational = nil
callgraph[sym].each do |x|
do_classify &&= !symbols_unknown.include?(x)
safe &&= whitelist.include? x
if(!whitelist.include?(x))
rational ||= x
end
end
if(do_classify)
if(safe)
whitelist[sym] = "added along the way {WHITELIST}"
symbols_known[sym] = "safe"
else
blacklist[sym] = "added along the way {BLACKLIST}"
symbols_known[sym] = "unsafe{#{rational}}"
end
del_list << sym
end
end
del_list.each do |x|
symbols_unknown.delete x
end
if(del_list.empty?)
break
end
end
symbols_known.each do |line|
puts "#{line[0]} #{line[1]}"
end