-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostCallAnalysis.cpp
More file actions
69 lines (60 loc) · 2.64 KB
/
PostCallAnalysis.cpp
File metadata and controls
69 lines (60 loc) · 2.64 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
#include "PostCallAnalysis.h"
#include "BaseAnalysis.h"
#include "DynamicAnalysis.h"
#include "../DynamicUtils.h"
#include <vector>
void PostCallAnalysis::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]);
}
}
PostCallAnalysis::PostCallAnalysis(void const* _func_supplier, CallOp_t* callop) {
SharedInit(_func_supplier, callop->function_name, callop->params, callop->num_params);
target_funcs = {callop->target_function};
}
PostCallAnalysis::PostCallAnalysis(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 PostCallAnalysis::functionPreCBImpl(void* const& func, CallsiteInfo const& callsite) {
for (void const* const& target_func : target_funcs) {
if (target_func == func) {
// Target function found, maybe analysis success
// Check params if needed
if (params.empty()) {
uncheckedCallsites.clear();
return Fulfillment::UNKNOWN; // Cannot return fulfilled until program exit, there may be more callsites to come
}
// Check which callsites are satisfied, remove from unchecked
for (auto callsite_iter = uncheckedCallsites.begin(); callsite_iter != uncheckedCallsites.end();) {
if (DynamicUtils::checkFuncCallMatch(target_func, params, callsite, *callsite_iter, target_str)) {
callsite_iter = uncheckedCallsites.erase(callsite_iter);
} else {
callsite_iter++;
}
}
// For the rest: Maybe actual fulfillment comes later
return Fulfillment::UNKNOWN;
}
}
if (func == func_supplier) {
for (CallsiteInfo& uncheckedCallsite : uncheckedCallsites) {
if (uncheckedCallsite.location == callsite.location) {
uncheckedCallsite = callsite;
goto exit_postcall_funccb;
}
}
uncheckedCallsites.push_back(callsite);
}
exit_postcall_funccb:
// Irrelevant function
return Fulfillment::UNKNOWN;
}
Fulfillment PostCallAnalysis::exitCBImpl(CodePtr const& location) {
for (CallsiteInfo const& callsite : uncheckedCallsites) {
references.push_back(callsite.location);
}
return uncheckedCallsites.empty() ? Fulfillment::FULFILLED : Fulfillment::VIOLATED;
}