-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetclasscalls.rb
More file actions
181 lines (162 loc) · 3.43 KB
/
getclasscalls.rb
File metadata and controls
181 lines (162 loc) · 3.43 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/ruby
$class_name = ""
$class_super = ""
$source_file = ""
$method_name = ""
$entry_vertex = "ENTRY"
$main_entry = "MAIN_ENTRY"
$line = nil
$last_line = nil
$line_num = ""
$all_lines = []
$intent_destination = ""
$declared_methods = []
$called_methods = []
$soup = {}
$getnext = false
def strip_method_name_args(method)
path =''
if ($method_name.split(' ').size == 1 ) then
path += method
else
sr = $method_name.split(' ')
path += sr[sr.size - 1] # add method name
end
argument_start = path.index("(")
path = path[0..argument_start - 1]
end
def strip_classpath(method)
split_result = method.split('/')
if (split_result.size == 0) then
return method
end
return split_result[split_result.size - 1]
end
def canonicalize_method_name(method)
path = ""
if ($class_name.split(' ').size == 0 ) then
path = ""
elsif ($class_name.split(' ').size == 1 ) then
path = $class_name
else
sr = $class_name.split(' ')
path = path + sr[sr.size - 1]
end
path += "/"
path += strip_method_name_args(method)
path
end
def finish_function()
$method_name = canonicalize_method_name($method_name)
$declared_methods.push($method_name)
$method_name = ""
end
def handle_line(line, directive, data)
case directive
when "class"
$split = data.split
$class_name = $split[$split.length-1]
when "super"
$class_super = data
$soup[$class_name] = $class_super
when "source"
$source_file = data
when "field"
#nothing
when "method"
$method_name = data
when "limit"
#nothing
when "line"
$line_num = data
when "end"
if data.strip == "method" then
finish_function()
end
end
end
def handle_instruction(line, directive, data)
function_name = clean_invokation(line)
case directive
when "virtual"
if (function_name =~ /.*getClass$/) then
$getnext = true
end
end
return 0
end
#Returns canonicalized function name
def clean_invokation(line)
semi_split = line.split(';')
comment = semi_split[1].strip
fn_split = semi_split[0].split(',')
function_name = fn_split[fn_split.size() - 1].strip
return function_name
end
def handle_comment(line)
end
def parse_line(line)
if (/\S/ !~ line) then
return #blank line
end
if ($getnext) then
if (line.strip =~ /.* : L(.*);/) then
$called_methods.push($1)
return
end
$getnext=false
end
if (line.strip =~ /^\.(interface) (.*)/) then
return 10
elsif (line.strip =~ /^\.(class|super|source|field|method|limit|line|end) (.*)/) then
handle_line(line, $1, $2)
elsif (line.strip =~ /^;/) then
handle_comment(line)
elsif(line.strip =~ /^invoke-(virtual|direct|super|static|interface)(.*?)/) then
handle_instruction(line, $1, $2)
end
end
def read_file(fn)
f = File.new(fn)
begin
while ($line = f.readline)
if ( parse_line($line) == 10 )
break
end
$last_line = $line
$all_lines.push($line)
end
rescue EOFError
f.close
end
#Reset all lines parsed for each file
$all_lines = []
end
def get_file_list(fn)
f = File.new(fn)
fl = []
begin
while (line = f.readline)
line.chomp!
fl.push(line)
end
rescue EOFError
f.close
end
fl
end
def print_found_methods_api()
for method in $called_methods do
print method + "\n"
end
end
def main()
ARGV.each() do |filelist|
get_file_list(filelist).each() do |filename|
$printed_banner = false
read_file(filename)
end
end
print_found_methods_api()
end
main()