-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreCallAnalysis.cpp
More file actions
60 lines (52 loc) · 2.14 KB
/
PreCallAnalysis.cpp
File metadata and controls
60 lines (52 loc) · 2.14 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
#include "PreCallAnalysis.h"
#include "BaseAnalysis.h"
#include "DynamicAnalysis.h"
#include "../DynamicUtils.h"
#include <vector>
void PreCallAnalysis::SharedInit(void const* _func_supplier, const char* _target_str, CallParam_t *_params, int64_t num_params) {
func_supplier = _func_supplier;
target_str = _target_str;
for (int i = 0; i < num_params; i++) {
params.push_back(&_params[i]);
}
}
PreCallAnalysis::PreCallAnalysis(void const* _func_supplier, CallOp_t* callop) {
SharedInit(_func_supplier, callop->function_name, callop->params, callop->num_params);
target_funcs = {callop->target_function};
}
PreCallAnalysis::PreCallAnalysis(void const* _func_supplier, CallTagOp_t* callop) {
SharedInit(_func_supplier, callop->target_tag, callop->params, callop->num_params);
target_funcs = DynamicUtils::getFunctionsForTag(callop->target_tag);
}
Fulfillment PreCallAnalysis::functionPreCBImpl(void* const& func, CallsiteInfo const& callsite) {
for (void const* const& target_func : target_funcs) {
if (target_func == func) {
// Possible match for precall
possible_matches[target_func].push_back(callsite);
return Fulfillment::UNKNOWN;
}
}
if (func == func_supplier) {
// Contract supplier found, need to resolve now
if (possible_matches.empty()) {
// No matches, verification failed
references.push_back(callsite.location);
return Fulfillment::VIOLATED;
}
// Check params if needed
if (params.empty()) return Fulfillment::FULFILLED;
for (auto const& possible_match : possible_matches) {
for (CallsiteInfo const& match_params : possible_match.second) {
if (DynamicUtils::checkFuncCallMatch(possible_match.first, params, match_params, callsite, target_str)) {
// Success!
return Fulfillment::FULFILLED;
}
}
}
// Nothing matched
references.push_back(callsite.location);
return Fulfillment::VIOLATED;
}
// Irrelevant function
return Fulfillment::UNKNOWN;
}