26
26
27
27
#include " taint_parser.h"
28
28
29
- class taint_analysist : public messaget
29
+ class taint_analysist
30
30
{
31
31
public:
32
- taint_analysist ()
32
+ explicit taint_analysist (message_handlert &message_handler)
33
+ : log(message_handler)
33
34
{
34
35
}
35
36
@@ -41,6 +42,7 @@ class taint_analysist:public messaget
41
42
const std::string &json_file_name);
42
43
43
44
protected:
45
+ messaget log;
44
46
taint_parse_treet taint;
45
47
class_hierarchyt class_hierarchy;
46
48
@@ -117,7 +119,8 @@ void taint_analysist::instrument(
117
119
118
120
if (match)
119
121
{
120
- debug () << " MATCH " << rule.id << " on " << identifier << eom;
122
+ log .debug () << " MATCH " << rule.id << " on " << identifier
123
+ << messaget::eom;
121
124
122
125
exprt where=nil_exprt ();
123
126
@@ -236,22 +239,24 @@ bool taint_analysist::operator()(
236
239
json_arrayt json_result;
237
240
bool use_json=!json_file_name.empty ();
238
241
239
- status () << " Reading taint file `" << taint_file_name
240
- << " ' " << eom;
242
+ log . status () << " Reading taint file `" << taint_file_name << " ' "
243
+ << messaget:: eom;
241
244
242
- if (taint_parser (taint_file_name, taint, get_message_handler ()))
245
+ if (taint_parser (taint_file_name, taint, log . get_message_handler ()))
243
246
{
244
- error () << " Failed to read taint definition file" << eom;
247
+ log . error () << " Failed to read taint definition file" << messaget:: eom;
245
248
return true ;
246
249
}
247
250
248
- status () << " Got " << taint.rules .size ()
249
- << " taint definitions " << eom;
251
+ log . status () << " Got " << taint.rules .size () << " taint definitions "
252
+ << messaget:: eom;
250
253
251
- taint.output (debug ());
252
- debug () << eom;
254
+ log .conditional_output (log .debug (), [this ](messaget::mstreamt &mstream) {
255
+ taint.output (mstream);
256
+ mstream << messaget::eom;
257
+ });
253
258
254
- status () << " Instrumenting taint" << eom;
259
+ log . status () << " Instrumenting taint" << messaget:: eom;
255
260
256
261
class_hierarchy (symbol_table);
257
262
@@ -266,13 +271,13 @@ bool taint_analysist::operator()(
266
271
// do we have an entry point?
267
272
if (have_entry_point)
268
273
{
269
- status () << " Working from entry point" << eom;
274
+ log . status () << " Working from entry point" << messaget:: eom;
270
275
}
271
276
else
272
277
{
273
- status () << " No entry point found; "
274
- << " we will consider the heads of all functions as reachable"
275
- << eom;
278
+ log . status () << " No entry point found; "
279
+ << " we will consider the heads of all functions as reachable"
280
+ << messaget:: eom;
276
281
277
282
goto_programt end, gotos, calls;
278
283
@@ -304,7 +309,7 @@ bool taint_analysist::operator()(
304
309
goto_functions.update ();
305
310
}
306
311
307
- status () << " Data-flow analysis" << eom;
312
+ log . status () << " Data-flow analysis" << messaget:: eom;
308
313
309
314
custom_bitvector_analysist custom_bitvector_analysis;
310
315
custom_bitvector_analysis (goto_functions, ns);
@@ -385,13 +390,13 @@ bool taint_analysist::operator()(
385
390
386
391
if (!json_out)
387
392
{
388
- error () << " Failed to open json output `"
389
- << json_file_name << " ' " << eom;
393
+ log . error () << " Failed to open json output `" << json_file_name << " ' "
394
+ << messaget:: eom;
390
395
return true ;
391
396
}
392
397
393
- status () << " Analysis result is written to `"
394
- << json_file_name << " ' " << eom;
398
+ log . status () << " Analysis result is written to `" << json_file_name << " ' "
399
+ << messaget:: eom;
395
400
396
401
json_out << json_result << ' \n ' ;
397
402
}
@@ -400,17 +405,18 @@ bool taint_analysist::operator()(
400
405
}
401
406
catch (const char *error_msg)
402
407
{
403
- error () << error_msg << eom;
408
+ log . error () << error_msg << messaget:: eom;
404
409
return true ;
405
410
}
406
411
catch (const std::string &error_msg)
407
412
{
408
- error () << error_msg << eom;
413
+ log . error () << error_msg << messaget:: eom;
409
414
return true ;
410
415
}
411
416
catch (...)
412
417
{
413
- error () << " Caught unexpected error in taint_analysist::operator()" << eom;
418
+ log .error () << " Caught unexpected error in taint_analysist::operator()"
419
+ << messaget::eom;
414
420
return true ;
415
421
}
416
422
}
@@ -422,8 +428,7 @@ bool taint_analysis(
422
428
bool show_full,
423
429
const std::string &json_file_name)
424
430
{
425
- taint_analysist taint_analysis;
426
- taint_analysis.set_message_handler (message_handler);
431
+ taint_analysist taint_analysis (message_handler);
427
432
return taint_analysis (
428
433
taint_file_name,
429
434
goto_model.symbol_table ,
0 commit comments