I'm looking for a way to found out how many times instruction at specified address was executed before break point hit.
Is there some standard way? I cannot found this in its interface.
Reverse Engineering Stack Exchange is a question and answer site for researchers and developers who explore the principles of a system through analysis of its structure, function, and operation. It only takes a minute to sign up.Sign up to join this community
Disclaimer: I don't have IDA available to try it out right now, so a detail might be wrong.
Just add some code to the breakpoint condition. For example
extern bpcount; bpcount++; Message(form("%d. hit\n"), bpcount); return (bpcount>500);
This will increment the count each time the breakpoint is it, but only break the program after more than 500 hits. Replace the return instruction with
return 0 if you never want to break, or
return 1 if you always want to break.
I have added
Python script on a breakpoint.
f = open('C:\\Users\\T3\\Desktop\\Count.txt', 'r+') strData = f.readline() n = int(strData) n = n + 1 f.seek(0) f.write(str(n)) f.close() return 0
Count file at the beginning contained
0 but after execution it contains hit count.
This way has one drawback. File IO is slow, so registry counters may be used because it is stored in memory (that is only for Windows).
Apparently IDA 7.0 (and earlier?) supports a "pass count" for a breakpoint, you can even see a column for that in the breakpoint list window, but I found no way to configure it via the UI.
You can use the following Python commands to create a breakpoint with a pass count though, where
0x12345678 is the address at which you want to set it, and
42 the hit count:
add_bpt(0x12345678, 1, BPT_DEFAULT) set_bpt_attr(0x12345678, BPTATTR_COUNT, 42)