Hi, I'm a university student and I'm new to DBI. This will kinda look like a newbie question.
I have this simple piece of code here:
for (int i = 0: i < 10: i++) {
Sleep(1000);
}
I just want to make the tool understand if it encounters a loop where there is a Sleep.
My idea is to get the address of the instruction where is called the sleep and check if it is called more than one time. For now, I've written an event_instruction that finds a call to a Sleep inside the main code of the client:
static dr_emit_flags_t
event_app_instruction(void* drcontext, void* tag, instrlist_t* bb, instr_t* instr,
bool for_trace, bool translating, void* user_data)
{
app_pc pc = instr_get_app_pc(instr);
dr_mcontext_t mc;
mc.size = sizeof(mc);
mc.flags = DR_MC_ALL;
dr_get_mcontext(drcontext, &mc);
app_pc API_address = (app_pc)0x74e16490; // sleep addr
if (instr_is_call(instr)) {
int num_srcs = instr_num_srcs(instr);
int* iat_addr;
int true_addr;
if (num_srcs > 0) {
opnd_t src = instr_get_src(instr, 0);
if (opnd_is_memory_reference(src)) {
iat_addr = (int*)opnd_compute_address(src, &mc);
true_addr = *iat_addr;
if (true_addr == (int)API_address) {
dr_fprintf(STDERR, "\nFOUND SLEEP: 0x%x -> 0x%x\n", iat_addr, true_addr);
disassemble(drcontext, pc, STDERR);
}
}
}
}
return DR_EMIT_DEFAULT;
}
For some reason I get only one print, and I don't understand why. The tool should print "FOUND SLEEP .. " exactly 10 times.
Hope someone can help me, thanks in advance!