panda-re / panda

Platform for Architecture-Neutral Dynamic Analysis
https://panda.re
Other
2.49k stars 479 forks source link

How to get the number of instructions in a replay file in Python Panda? #1299

Open tylzh97 opened 1 year ago

tylzh97 commented 1 year ago

I found in Python Pandas that the function panda.rr_get_guest_instr_count() can get the number of instructions currently executed, and I also found in rr_log.h that the total number of instructions in the current replay file can be obtained through rr_nondet_log->last_prog_point.guest_instr_count. So how can I get this value in Python?

lacraig2 commented 1 year ago

That's not currently something that's exposed to python.

There's a few ways to get at that value. The easiest of which would likely be adding a PANDA API function in the same way that panda.rr_guest_get_instr_count has:

You would need to add a function near here: https://github.com/panda-re/panda/blob/35339e878c00e7dd15bdd023d64191ca1b343fe5/panda/src/panda_api.c#L132-L134

add the definition to the header file and also add a method in panda.py: https://github.com/panda-re/panda/blob/35339e878c00e7dd15bdd023d64191ca1b343fe5/panda/python/core/pandare/panda.py#L1342-L1344