15
15
#include " callstack_instr/callstack_instr.h"
16
16
17
17
extern " C" {
18
+ #include < hypercaller/hypercaller.h>
18
19
19
20
#include " panda/rr/rr_log.h"
20
21
#include " panda/plog.h"
@@ -37,14 +38,15 @@ extern "C" {
37
38
bool init_plugin (void *);
38
39
void uninit_plugin (void *);
39
40
40
- int get_loglevel () ;
41
+ int get_loglevel ();
41
42
void set_loglevel (int new_loglevel);
42
43
}
43
44
45
+ #define LAVA_MAGIC 0xabcd
44
46
const char *global_src_filename = NULL ;
45
47
uint64_t global_src_linenum;
46
48
unsigned global_ast_loc_id;
47
- uint64_t global_funcaddr;
49
+ // uint64_t global_funcaddr;
48
50
bool debug = false ;
49
51
50
52
#define dprintf (...) if (debug) { printf (__VA_ARGS__); fflush (stdout); }
@@ -237,7 +239,7 @@ struct args {
237
239
const char *src_filename;
238
240
uint64_t src_linenum;
239
241
unsigned ast_loc_id;
240
- uint64_t funcaddr;
242
+ // uint64_t funcaddr;
241
243
};
242
244
243
245
#if defined(TARGET_I386)
@@ -264,7 +266,7 @@ void pfun(void *var_ty_void, const char *var_nm, LocType loc_t, target_ulong loc
264
266
global_src_filename = args->src_filename ;
265
267
global_src_linenum = args->src_linenum ;
266
268
global_ast_loc_id = args->ast_loc_id ;
267
- global_funcaddr = args->funcaddr ;
269
+ // global_funcaddr = args->funcaddr;
268
270
// target_ulong guest_dword;
269
271
// std::string ty_string = std::string(var_ty);
270
272
// size_t num_derefs = std::count(ty_string.begin(), ty_string.end(), '*');
@@ -289,8 +291,9 @@ void pfun(void *var_ty_void, const char *var_nm, LocType loc_t, target_ulong loc
289
291
default :
290
292
assert (1 ==0 );
291
293
}
292
- // free(si);
293
294
}
295
+ #endif
296
+
294
297
/*
295
298
void on_line_change(CPUState *cpu, target_ulong pc, const char *file_Name, const char *funct_name, unsigned long long lno){
296
299
if (taint2_enabled()){
@@ -319,7 +322,6 @@ void hypercall_log_trace(unsigned ast_loc_id) {
319
322
// Support all features of label and query program
320
323
void i386_hypercall_callback (CPUState *cpu) {
321
324
dprintf (" [pri_taint] Calling lava hypercall!\n " );
322
-
323
325
CPUArchState *env = (CPUArchState*) cpu->env_ptr ;
324
326
if (taint2_enabled ()) {
325
327
// LAVA Hypercall
@@ -335,17 +337,21 @@ void i386_hypercall_callback(CPUState *cpu) {
335
337
(uint32_t ) env->regs [R_EDI], (uint32_t ) addr);
336
338
#else
337
339
dprintf (" [pri_taint] panda hypercall with ptr to invalid PandaHypercallStruct: vaddr=0x%x paddr=0x%x\n " ,
338
- (uint32_t ) env->regs [R_EBX], (uint32_t ) addr);
340
+ (uint32_t ) env->regs [R_EBX], (uint32_t ) addr);
339
341
#endif
340
342
}
341
343
else if (pandalog) {
342
344
dprintf (" [pri_taint] Hypercall is OK and Panda Log is set\n " );
343
345
PandaHypercallStruct phs;
344
- panda_virtual_memory_read (cpu, env->regs [R_EAX], (uint8_t *) &phs, sizeof (phs));
346
+ #ifdef TARGET_X86_64
347
+ panda_virtual_memory_read (cpu, env->regs [R_EDI], (uint8_t *) &phs, sizeof (phs));
348
+ #else
349
+ panda_virtual_memory_read (cpu, env->regs [R_EBX], (uint8_t *) &phs, sizeof (phs));
350
+ #endif
345
351
346
352
// To be used for chaff bugs?
347
- uint64_t funcaddr = 0 ;
348
- panda_virtual_memory_read (cpu, phs.info , (uint8_t *)&funcaddr, sizeof (target_ulong));
353
+ // uint64_t funcaddr = 0;
354
+ // panda_virtual_memory_read(cpu, phs.info, (uint8_t*)&funcaddr, sizeof(target_ulong));
349
355
// if the phs action is a pri_query point, see
350
356
// lava/include/pirate_mark_lava.h
351
357
if (phs.action == 13 ) {
@@ -360,6 +366,7 @@ void i386_hypercall_callback(CPUState *cpu) {
360
366
" ln: %4ld, pc @ 0x" TARGET_FMT_lx " \n " ,
361
367
info.filename ,
362
368
info.line_number ,pc);
369
+
363
370
// Calls 'pri_funct_livevar_iter' in pri.c, which calls 'on_funct_livevar_iter'
364
371
// In Dwarf2, the function 'on_funct_livevar_iter' is mapped to 'dwarf_funct_livevar_iter'
365
372
// This is passing the function 'pfun' to 'pri_funct_livevar_iter', which is called at the end
@@ -368,6 +375,7 @@ void i386_hypercall_callback(CPUState *cpu) {
368
375
else {
369
376
dprintf (" [pri_taint] pri_get_pc_src_info has failed: %d != 0.\n " , rc);
370
377
}
378
+ // hypercall_log_trace(phs.src_filename);
371
379
}
372
380
else {
373
381
dprintf (" [pri_taint] Invalid action value in PHS struct: %d != 13.\n " , phs.action );
@@ -380,24 +388,9 @@ void i386_hypercall_callback(CPUState *cpu) {
380
388
else {
381
389
dprintf (" [pri_taint] taint2 is not enabled (hypercall)\n " );
382
390
}
383
- return ret;
384
391
}
385
392
#endif // TARGET_I386
386
393
387
-
388
- bool guest_hypercall_callback (CPUState *cpu) {
389
- #ifdef TARGET_I386
390
- return i386_hypercall_callback (cpu);
391
- #endif
392
-
393
- #ifdef TARGET_ARM
394
- // not implemented for now
395
- // arm_hypercall_callback(cpu);
396
- #endif
397
-
398
- return false ;
399
- }
400
- #endif
401
394
/*
402
395
void on_taint_change(Addr a, uint64_t size){
403
396
uint32_t num_tainted = 0;
@@ -425,26 +418,26 @@ bool init_plugin(void *self) {
425
418
panda_require (" taint2" );
426
419
assert (init_taint2_api ());
427
420
428
- panda_cb pcb;
429
- pcb.guest_hypercall = guest_hypercall_callback;
430
- panda_register_callback (self, PANDA_CB_GUEST_HYPERCALL, pcb);
431
- printf (" [pri_taint] This plugin is activated!\n " );
432
-
433
421
// If taint isn't already enabled, turn it on.
434
422
if (!taint2_enabled ()) {
435
423
printf (" [pri_taint] enabling taint now!\n " );
436
424
taint2_enable_taint ();
437
425
}
426
+
427
+ panda_require (" hypercaller" );
428
+ void * hypercaller = panda_get_plugin_by_name (" hypercaller" );
429
+ register_hypercall_t register_hypercall = (register_hypercall_t ) dlsym (hypercaller, " register_hypercall" );
430
+ register_hypercall (LAVA_MAGIC, i386_hypercall_callback);
431
+
432
+ printf (" [pri_taint] This plugin is activated!\n " );
438
433
return true ;
439
434
#else
440
435
printf (" [pri_taint] This plugin is only supported on x86\n " );
441
436
return false ;
442
- // taint2_track_taint_state();
443
437
#endif
444
438
}
445
439
446
-
447
-
448
440
void uninit_plugin (void *self) {
441
+ // You don't need to unregister the hypercall!
442
+ printf (" [pri_taint] Unloading plugin complete!\n " );
449
443
}
450
-
0 commit comments