41
41
42
42
#include < sstream>
43
43
44
- #include " PollingLoopDetector .h"
44
+ #include " EdgeKiller .h"
45
45
46
46
namespace s2e {
47
47
namespace plugins {
48
48
49
- S2E_DEFINE_PLUGIN (PollingLoopDetector , " Kills states stuck in a polling loop " , " PollingLoopDetector " ,
49
+ S2E_DEFINE_PLUGIN (EdgeKiller , " Kills states when a specified sequence of instructions has been executed " , " EdgeKiller " ,
50
50
" ModuleExecutionDetector" , " Interceptor" );
51
51
52
- void PollingLoopDetector ::initialize ()
52
+ void EdgeKiller ::initialize ()
53
53
{
54
54
m_detector = (ModuleExecutionDetector*)s2e ()->getPlugin (" ModuleExecutionDetector" );
55
55
m_monitor = (OSMonitor*)s2e ()->getPlugin (" Interceptor" );
56
56
57
57
m_monitor->onModuleLoad .connect (
58
58
sigc::mem_fun (*this ,
59
- &PollingLoopDetector ::onModuleLoad)
59
+ &EdgeKiller ::onModuleLoad)
60
60
);
61
61
62
62
m_monitor->onModuleUnload .connect (
63
63
sigc::mem_fun (*this ,
64
- &PollingLoopDetector ::onModuleUnload)
64
+ &EdgeKiller ::onModuleUnload)
65
65
);
66
66
67
67
@@ -71,18 +71,18 @@ void PollingLoopDetector::initialize()
71
71
/* *
72
72
* Read the config section of the module
73
73
*/
74
- void PollingLoopDetector ::onModuleLoad (
74
+ void EdgeKiller ::onModuleLoad (
75
75
S2EExecutionState* state,
76
76
const ModuleDescriptor &module
77
77
)
78
78
{
79
- DECLARE_PLUGINSTATE (PollingLoopDetectorState , state);
79
+ DECLARE_PLUGINSTATE (EdgeKillerState , state);
80
80
81
81
ConfigFile *cfg = s2e ()->getConfig ();
82
82
const std::string *id = m_detector->getModuleId (module);
83
83
84
84
if (!id) {
85
- s2e ()->getDebugStream () << " PollingLoopDetector could not figure out which "
85
+ s2e ()->getDebugStream () << " EdgeKiller could not figure out which "
86
86
" module id was passed to onModuleLoad!" << std::endl;
87
87
module.Print (s2e ()->getDebugStream ());
88
88
return ;
@@ -95,7 +95,7 @@ void PollingLoopDetector::onModuleLoad(
95
95
ConfigFile::string_list pollingEntries = cfg->getListKeys (ss.str ());
96
96
97
97
if (pollingEntries.size () == 0 ) {
98
- s2e ()->getWarningsStream () << " PollingLoopDetector did not find any configured entry for "
98
+ s2e ()->getWarningsStream () << " EdgeKiller did not find any configured entry for "
99
99
" the module " << *id << " (" << ss.str () << " )" << std::endl;
100
100
return ;
101
101
}
@@ -105,21 +105,21 @@ void PollingLoopDetector::onModuleLoad(
105
105
ss1 << ss.str () << " ." << *it;
106
106
ConfigFile::integer_list il = cfg->getIntegerList (ss1.str ());
107
107
if (il.size () != 2 ) {
108
- s2e ()->getWarningsStream () << " PollingLoopDetector entry " << ss1.str () <<
108
+ s2e ()->getWarningsStream () << " EdgeKiller entry " << ss1.str () <<
109
109
" must be of the form {sourcePc, destPc} format" << *id << std::endl;
110
110
continue ;
111
111
}
112
112
113
113
bool ok = false ;
114
114
uint64_t source = cfg->getInt (ss1.str () + " [1]" , 0 , &ok);
115
115
if (!ok) {
116
- s2e ()->getWarningsStream () << " PollingLoopDetector could not read " << ss1.str () << " [0]" << std::endl;
116
+ s2e ()->getWarningsStream () << " EdgeKiller could not read " << ss1.str () << " [0]" << std::endl;
117
117
continue ;
118
118
}
119
119
120
120
uint64_t dest = cfg->getInt (ss1.str () + " [2]" , 0 , &ok);
121
121
if (!ok) {
122
- s2e ()->getWarningsStream () << " PollingLoopDetector could not read " << ss1.str () << " [1]" << std::endl;
122
+ s2e ()->getWarningsStream () << " EdgeKiller could not read " << ss1.str () << " [1]" << std::endl;
123
123
continue ;
124
124
}
125
125
@@ -128,35 +128,35 @@ void PollingLoopDetector::onModuleLoad(
128
128
dest = module.ToRuntime (dest);
129
129
130
130
// Insert in the state
131
- plgState->addEntry (source, dest);
131
+ plgState->addEdge (source, dest);
132
132
}
133
133
134
134
if (!m_connection.connected ()) {
135
135
m_connection = m_detector->onModuleTranslateBlockEnd .connect (
136
136
sigc::mem_fun (*this ,
137
- &PollingLoopDetector ::onModuleTranslateBlockEnd)
137
+ &EdgeKiller ::onModuleTranslateBlockEnd)
138
138
);
139
139
}
140
140
141
141
142
142
}
143
143
144
- void PollingLoopDetector ::onModuleUnload (
144
+ void EdgeKiller ::onModuleUnload (
145
145
S2EExecutionState* state,
146
146
const ModuleDescriptor &module
147
147
)
148
148
{
149
- DECLARE_PLUGINSTATE (PollingLoopDetectorState , state);
149
+ DECLARE_PLUGINSTATE (EdgeKillerState , state);
150
150
151
151
// Remove all the polling entries that belong to the module
152
- PollingLoopDetectorState::PollingEntries &entries =
152
+ EdgeKillerState::EdgeEntries &entries =
153
153
plgState->getEntries ();
154
154
155
- PollingLoopDetectorState::PollingEntries ::iterator it1, it2;
155
+ EdgeKillerState::EdgeEntries ::iterator it1, it2;
156
156
157
157
it1 = entries.begin ();
158
158
while (it1 != entries.end ()) {
159
- const PollingLoopDetectorState::PollingEntry &e = *it1;
159
+ const EdgeKillerState::Edge &e = *it1;
160
160
if (module.Contains (e.source )) {
161
161
it2 = it1;
162
162
++it2;
@@ -173,7 +173,7 @@ void PollingLoopDetector::onModuleUnload(
173
173
/* *
174
174
* Instrument only the blocks where we want to kill the state.
175
175
*/
176
- void PollingLoopDetector ::onModuleTranslateBlockEnd (
176
+ void EdgeKiller ::onModuleTranslateBlockEnd (
177
177
ExecutionSignal *signal,
178
178
S2EExecutionState* state,
179
179
const ModuleDescriptor &module,
@@ -182,23 +182,23 @@ void PollingLoopDetector::onModuleTranslateBlockEnd(
182
182
bool staticTarget,
183
183
uint64_t targetPc)
184
184
{
185
- DECLARE_PLUGINSTATE (PollingLoopDetectorState , state);
185
+ DECLARE_PLUGINSTATE (EdgeKillerState , state);
186
186
187
187
// If the target instruction is a kill point, connect the killer.
188
- if (plgState->isPolling (endPc)) {
188
+ if (plgState->isEdge (endPc)) {
189
189
signal ->connect (
190
- sigc::mem_fun (*this , &PollingLoopDetector::onPollingInstruction )
190
+ sigc::mem_fun (*this , &EdgeKiller::onEdge )
191
191
);
192
192
}
193
193
}
194
194
195
195
196
- void PollingLoopDetector::onPollingInstruction (S2EExecutionState* state, uint64_t sourcePc)
196
+ void EdgeKiller::onEdge (S2EExecutionState* state, uint64_t sourcePc)
197
197
{
198
- DECLARE_PLUGINSTATE (PollingLoopDetectorState , state);
199
- if (plgState->isPolling (sourcePc, state->getPc ())) {
198
+ DECLARE_PLUGINSTATE (EdgeKillerState , state);
199
+ if (plgState->isEdge (sourcePc, state->getPc ())) {
200
200
std::ostringstream ss;
201
- ss << " Polling loop from 0x" <<std::hex << sourcePc << " to 0x"
201
+ ss << " Edge from 0x" <<std::hex << sourcePc << " to 0x"
202
202
<< state->getPc ();
203
203
204
204
s2e ()->getMessagesStream (state) << ss.str () << std::endl;
@@ -209,60 +209,60 @@ void PollingLoopDetector::onPollingInstruction(S2EExecutionState* state, uint64_
209
209
210
210
// /////////////////////////////////////////////////////////////////////////
211
211
212
- PollingLoopDetectorState::PollingLoopDetectorState ()
212
+ EdgeKillerState::EdgeKillerState ()
213
213
{
214
214
215
215
}
216
216
217
- PollingLoopDetectorState::PollingLoopDetectorState (S2EExecutionState *s, Plugin *p)
217
+ EdgeKillerState::EdgeKillerState (S2EExecutionState *s, Plugin *p)
218
218
{
219
219
220
220
}
221
221
222
- PollingLoopDetectorState ::~PollingLoopDetectorState ()
222
+ EdgeKillerState ::~EdgeKillerState ()
223
223
{
224
224
225
225
}
226
226
227
- PluginState *PollingLoopDetectorState ::clone () const
227
+ PluginState *EdgeKillerState ::clone () const
228
228
{
229
- return new PollingLoopDetectorState (*this );
229
+ return new EdgeKillerState (*this );
230
230
}
231
231
232
- PluginState *PollingLoopDetectorState ::factory (Plugin *p, S2EExecutionState *s)
232
+ PluginState *EdgeKillerState ::factory (Plugin *p, S2EExecutionState *s)
233
233
{
234
- return new PollingLoopDetectorState ();
234
+ return new EdgeKillerState ();
235
235
}
236
236
237
- PollingLoopDetectorState::PollingEntries & PollingLoopDetectorState ::getEntries ()
237
+ EdgeKillerState::EdgeEntries & EdgeKillerState ::getEntries ()
238
238
{
239
- return m_pollingEntries ;
239
+ return m_edges ;
240
240
}
241
241
242
- void PollingLoopDetectorState::addEntry (uint64_t source, uint64_t dest)
242
+ void EdgeKillerState::addEdge (uint64_t source, uint64_t dest)
243
243
{
244
- PollingEntry pe;
244
+ Edge pe;
245
245
pe.source = source;
246
246
pe.dest = dest;
247
- m_pollingEntries .insert (pe);
247
+ m_edges .insert (pe);
248
248
}
249
249
250
- bool PollingLoopDetectorState::isPolling (uint64_t source) const
250
+ bool EdgeKillerState::isEdge (uint64_t source) const
251
251
{
252
- PollingEntry pe;
252
+ Edge pe;
253
253
pe.source = source;
254
- return m_pollingEntries .find (pe) != m_pollingEntries .end ();
254
+ return m_edges .find (pe) != m_edges .end ();
255
255
}
256
256
257
- bool PollingLoopDetectorState::isPolling (uint64_t source, uint64_t dest) const
257
+ bool EdgeKillerState::isEdge (uint64_t source, uint64_t dest) const
258
258
{
259
- PollingEntry pe;
259
+ Edge pe;
260
260
pe.source = source;
261
261
pe.dest = dest;
262
262
263
263
// For now we assume unique source in the list
264
- PollingEntries ::const_iterator it = m_pollingEntries .find (pe);
265
- if (it != m_pollingEntries .end ()) {
264
+ EdgeEntries ::const_iterator it = m_edges .find (pe);
265
+ if (it != m_edges .end ()) {
266
266
return pe == *it;
267
267
}
268
268
return false ;
0 commit comments