Пишу плагин, который добаляет ссылки к динамическим вызовам. Проблема в том, что Ида падает после запуска отладчика, но до вызова callback, не могу понять в чем проблема. Если закомментировать hook_to_notification_point, то отладчик работает нормально. Код (C++): #include <ida.hpp> #include <idp.hpp> #include <dbg.hpp> #include <loader.hpp> #include <kernwin.hpp> #include <bytes.hpp> #include <ua.hpp> #include <vector> using namespace std; void set_bpts(); void del_bpts(); void find_jumps(); void idaapi term(); bool contains(ea_t el); bool has_cref(ea_t from, ea_t to); vector<ea_t> bpts; bool jumps_found = false; bool contains(ea_t el) { for (unsigned int i = 0; i < bpts.size(); i++) { if (bpts.at(i) == el) return true; } return false; } bool has_cref(ea_t from, ea_t to) { ea_t ref = get_first_cref_from(from); while (ref != BADADDR) { if(from==to) return true; ref = get_next_cref_from(from, ref); } return false; } //-------------------------------------------------------------------------- static ssize_t idaapi callback(void * /*user_data*/, int notification_code, va_list va) { ea_t addr; switch (notification_code) { /*case dbg_process_start: break;*/ case dbg_bpt: addr = va_arg(va, ea_t); if (contains(addr)) { insn_t ins; decode_insn(&ins, addr); if (!has_cref(addr, ins.ops[0].addr)) { if (ins.flags&CF_CALL) add_cref(addr, ins.ops[0].addr, fl_CN); else add_cref(addr, ins.ops[0].addr, fl_JN); } } request_continue_process(); run_requests(); break; case dbg_process_exit: term(); break; } return 0; } int idaapi init() { if (ph.id != PLFM_386 || inf.filetype != f_PE) return PLUGIN_SKIP; return PLUGIN_OK; } bool idaapi run(size_t) { if (!jumps_found) find_jumps(); jumps_found = true; set_bpts(); if (!hook_to_notification_point(HT_DBG, callback)) { warning("Could not hook to notification point"); return true; } if (dbg == NULL) load_debugger("win32", false); start_process(); return true; } void find_jumps() { for (ea_t i = inf.min_ea; i < inf.max_ea; i++) { flags_t f = get_flags(i); if (is_code(f) && is_head(f)) { insn_t ins; int sz = decode_insn(&ins, i); if (ins.flags & CF_JUMP && ins.ops[0].is_reg(0)) { bpts.push_back(i); } i += sz - 1; } } } void set_bpts() { for (unsigned int i = 0; i < bpts.size(); i++) { add_bpt(bpts.at(i)); } } void del_bpts() { for (unsigned int i = 0; i < bpts.size(); i++) { del_bpt(bpts.at(i)); } } void idaapi term() { // just to be safe unhook_from_notification_point(HT_DBG, callback); del_bpts(); } plugin_t PLUGIN = { IDP_INTERFACE_VERSION, PLUGIN_UNL, // plugin flags init, // initialize NULL, // terminate. this pointer may be NULL. run, // invoke plugin NULL, // long comment about the plugin NULL, // multiline help about the plugin "ReffeR", // the preferred short name of the plugin NULL // the preferred hotkey to run the plugin };
Пишешь плагин для отладчика, а формулировка "ида где-то падает". Код (Text): hook_to_notification_point(HT_DBG, callback) Код (Text): idaman bool ida_export hook_to_notification_point (hook_type_t hook_type, hook_cb_t *cb, void *user_data=NULL)