@@ -21,6 +21,8 @@ void ValidPathSearcher::initialize() {
21
21
s2e ()->getExecutor ()->setSearcher (this );
22
22
m_onStateForkConn =
23
23
s2e ()->getCorePlugin ()->onStateFork .connect (sigc::mem_fun (*this , &ValidPathSearcher::onStateFork));
24
+ m_onTranslateBlockEndConn = s2e ()->getCorePlugin ()->onTranslateBlockEnd .connect (
25
+ sigc::mem_fun (*this , &ValidPathSearcher::onTranslateBlockEnd));
24
26
25
27
onARMFunctionConn = s2e ()->getPlugin <ARMFunctionMonitor>();
26
28
onARMFunctionConn->onARMFunctionCallEvent .connect (sigc::mem_fun (*this , &ValidPathSearcher::onARMFunctionCall));
@@ -31,67 +33,37 @@ void ValidPathSearcher::initialize() {
31
33
m_searcherActive = false ;
32
34
}
33
35
34
- bool ValidPathSearcher::insertToForkStates (uint32_t callerPC, uint32_t forkPC, S2EExecutionState *state) {
35
- const auto &foundSameCallerPC = m_forkStateItems.find (callerPC);
36
- if (foundSameCallerPC != m_forkStateItems.end ()) {
37
- const auto &foundSameForkPC = foundSameCallerPC->second .find (forkPC);
38
- if (foundSameForkPC != foundSameCallerPC->second .end ()) {
39
- if (foundSameForkPC->second .size () >= 2 ) {
40
- return false ;
41
- }
42
- }
43
- }
44
- m_forkStateItems[callerPC][forkPC].push_back (state);
45
- m_idStateMap[state->getID ()] = {state, forkPC, 0 };
46
- return true ;
47
- }
48
-
49
- void ValidPathSearcher::onStateFork (S2EExecutionState *state, const std::vector<S2EExecutionState *> &newStates,
50
- const std::vector<klee::ref<klee::Expr>> &newConditions) {
51
- getDebugStream () << " onStateFork" << ' \n ' ;
52
-
53
- uint32_t forkPC = state->regs ()->getPc ();
54
- getDebugStream () << " [forkPC: " << hexval (forkPC) << " ] "
55
- << " [stateID: " << hexval (state->getID ()) << " ] "
56
- << " [new stateID: " << hexval (newStates[0 ]->getID ()) << " ] "
57
- << " [new stateID: " << hexval (newStates[1 ]->getID ()) << " ] "
58
- << " \n " ;
59
- insertToForkStates (m_callerPC, forkPC, newStates[0 ]);
60
- insertToForkStates (m_callerPC, forkPC, newStates[1 ]);
61
- m_searcherActive = true ;
62
- }
63
-
64
36
klee::ExecutionState &ValidPathSearcher::selectState () {
65
37
getDebugStream () << " selectState"
66
38
<< " \n " ;
67
39
68
40
if (m_selfSwitch) {
69
41
m_selfSwitch = false ;
70
- m_idStateMap[m_curState->getID ()].flag = 2 ;
42
+ m_idStateMap[m_curState->getID ()].flag = VALID ;
71
43
getDebugStream () << " [self switch, stateID: " << m_curState->getID () << " ] "
72
44
<< " \n " ;
73
45
return *m_curState;
74
46
}
75
47
76
48
// flag 0 firstly
77
49
for (auto it = m_idStateMap.rbegin (); it != m_idStateMap.rend (); ++it) {
78
- if (it->second .flag == 0 ) {
79
- it->second .flag = 2 ;
50
+ if (it->second .flag == UNVISITED ) {
51
+ it->second .flag = VALID ;
80
52
m_curState = it->second .state ;
81
- getDebugStream () << " [flag 0: selected stateID: " << m_curState->getID () << " ] "
53
+ getDebugStream () << " [selected unvisited stateID: " << m_curState->getID () << " ] "
82
54
<< " \n " ;
83
55
return *m_curState;
84
56
}
85
57
}
86
- // flag 2 secondly
87
- // for (auto it = m_idStateMap.rbegin(); it != m_idStateMap.rend(); ++it) {
88
- // if (it->second.flag == 2 ) {
89
- // m_curState = it->second.state;
90
- // getDebugStream() << "[flag 2: selected stateID: " << m_curState->getID() << "] "
91
- // << "\n";
92
- // return *m_curState;
93
- // }
94
- // }
58
+ // flag 2 secondly
59
+ for (auto it = m_idStateMap.rbegin (); it != m_idStateMap.rend (); ++it) {
60
+ if (it->second .flag == VALID ) {
61
+ m_curState = it->second .state ;
62
+ getDebugStream () << " [selected valid stateID: " << m_curState->getID () << " ] "
63
+ << " \n " ;
64
+ return *m_curState;
65
+ }
66
+ }
95
67
96
68
getDebugStream () << " [no option, stateID: " << m_curState->getID () << " ] "
97
69
<< " \n " ;
@@ -104,22 +76,62 @@ void ValidPathSearcher::update(klee::ExecutionState *current, const klee::StateS
104
76
S2EExecutionState *removedState = static_cast <S2EExecutionState *>(it);
105
77
auto found = m_idStateMap.find (removedState->getID ());
106
78
if (found != m_idStateMap.end ()) {
107
- found->second .flag = 1 ;
79
+ found->second .flag = INVALID ;
108
80
}
109
81
}
110
82
}
111
83
112
84
bool ValidPathSearcher::empty () {
113
- getDebugStream () << " empty"
114
- << " \n " ;
115
85
for (const auto &it : m_idStateMap) {
116
- if (it.second .flag == 0 || it.second .flag == 2 ) {
86
+ if (it.second .flag == UNVISITED || it.second .flag == VALID) {
87
+ getDebugStream () << " empty"
88
+ << " \n " ;
117
89
return false ;
118
90
}
119
91
}
120
92
return true ;
121
93
}
122
94
95
+ bool ValidPathSearcher::insertToForkStates (uint32_t callerPC, uint32_t forkPC, S2EExecutionState *state) {
96
+ const auto &foundSameCallerPC = m_forkStateItems.find (callerPC);
97
+ if (foundSameCallerPC != m_forkStateItems.end ()) {
98
+ const auto &foundSameForkPC = foundSameCallerPC->second .find (forkPC);
99
+ if (foundSameForkPC != foundSameCallerPC->second .end ()) {
100
+ if (foundSameForkPC->second .size () >= 2 ) {
101
+ return false ;
102
+ }
103
+ }
104
+ }
105
+ m_forkStateItems[callerPC][forkPC].push_back (state);
106
+ m_idStateMap[state->getID ()] = {state, forkPC, UNVISITED};
107
+ return true ;
108
+ }
109
+
110
+ void ValidPathSearcher::onStateFork (S2EExecutionState *state, const std::vector<S2EExecutionState *> &newStates,
111
+ const std::vector<klee::ref<klee::Expr>> &newConditions) {
112
+ getDebugStream () << " onStateFork" << ' \n ' ;
113
+
114
+ uint32_t forkPC = state->regs ()->getPc ();
115
+ getDebugStream () << " [forkPC: " << hexval (forkPC) << " ] "
116
+ << " [stateID: " << hexval (state->getID ()) << " ] "
117
+ << " [new stateID: " << hexval (newStates[0 ]->getID ()) << " ] "
118
+ << " [new stateID: " << hexval (newStates[1 ]->getID ()) << " ] "
119
+ << " \n " ;
120
+ insertToForkStates (m_callerPC, forkPC, newStates[0 ]);
121
+ insertToForkStates (m_callerPC, forkPC, newStates[1 ]);
122
+ m_idStateMap[state->getID ()].flag = VALID;
123
+ m_searcherActive = true ;
124
+ }
125
+
126
+ void ValidPathSearcher::onTranslateBlockEnd (ExecutionSignal *signal, S2EExecutionState *state, TranslationBlock *tb,
127
+ uint64_t pc, bool isStatic, uint64_t staticTargetPc) {
128
+ getDebugStream () << " onTranslateBlockEnd" << ' \n ' ;
129
+
130
+ m_tbNum++;
131
+ getDebugStream () << " [the number of blocks: " << m_tbNum << " ]"
132
+ << " \n " ;
133
+ }
134
+
123
135
void ValidPathSearcher::onARMFunctionCall (S2EExecutionState *state, uint32_t pcCaller, uint64_t pcCtxHashVal,
124
136
uint32_t pcReturn) {
125
137
getDebugStream () << " onARMFunctionCall"
@@ -147,9 +159,11 @@ void ValidPathSearcher::onARMFunctionReturn(S2EExecutionState *state, uint32_t p
147
159
uint32_t forkPC = m_idStateMap[state->getID ()].forkPC ;
148
160
149
161
for (auto &it : m_forkStateItems[callerPC][forkPC]) {
150
- if (m_idStateMap[it->getID ()].flag == 0 ) {
162
+ if (m_idStateMap[it->getID ()].flag == INVALID ) {
151
163
m_selfSwitch = true ;
152
164
m_curState = m_idStateMap[it->getID ()].state ;
165
+ getDebugStream () << " self switch"
166
+ << " \n " ;
153
167
void *cp = g_s2e->getPlugin (" CorePlugin" );
154
168
s2e ()->getExecutor ()->validPathSearcherStateSwitchCallback (cp);
155
169
s2e ()->getExecutor ()->setCpuExitRequest ();
0 commit comments