2010-06-28 14:36:40 +02:00
|
|
|
// SWIG chokes on the original declaration so it is replicated here
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
ulonglong ival; // 8: integer value
|
|
|
|
ushort fval[6]; // 12: floating point value in the internal representation (see ieee.h)
|
|
|
|
} regval_t;
|
|
|
|
|
|
|
|
%ignore dbg;
|
2011-06-10 16:54:03 +02:00
|
|
|
%ignore register_srcinfo_provider;
|
|
|
|
%ignore unregister_srcinfo_provider;
|
|
|
|
%ignore appcall_info_t;
|
2010-06-28 14:36:40 +02:00
|
|
|
%ignore get_manual_regions;
|
2011-06-10 16:54:03 +02:00
|
|
|
%ignore internal_appcall;
|
|
|
|
%ignore internal_cleanup_appcall;
|
|
|
|
|
2010-06-28 14:36:40 +02:00
|
|
|
%ignore source_file_t;
|
|
|
|
%ignore source_item_t;
|
|
|
|
%ignore srcinfo_provider_t;
|
2011-04-18 18:07:00 +02:00
|
|
|
%ignore bpt_location_t::print;
|
|
|
|
%ignore bpt_t::set_cond;
|
|
|
|
%ignore bpt_t::eval_cond;
|
|
|
|
%ignore bpt_t::write;
|
|
|
|
%ignore bpt_t::erase;
|
2011-06-10 16:54:03 +02:00
|
|
|
%ignore bpt_t::cndbody;
|
2014-07-05 00:02:42 +02:00
|
|
|
%ignore bpt_t::get_cnd_elang;
|
|
|
|
%ignore bpt_t::set_cnd_elang;
|
2010-06-28 14:36:40 +02:00
|
|
|
%rename (get_manual_regions) py_get_manual_regions;
|
|
|
|
%ignore set_manual_regions;
|
2011-04-18 18:07:00 +02:00
|
|
|
%ignore inform_idc_about_debthread;
|
2013-12-30 02:34:23 +01:00
|
|
|
%ignore is_dbgmem_valid;
|
|
|
|
// We want ALL wrappers around what is declared in dbg.hpp
|
|
|
|
// to release the GIL when calling into the IDA api: those
|
|
|
|
// might be very long operations, that even require some
|
|
|
|
// network traffic.
|
|
|
|
%thread;
|
2010-06-28 14:36:40 +02:00
|
|
|
%include "dbg.hpp"
|
2013-12-30 02:34:23 +01:00
|
|
|
%nothread;
|
2010-06-28 14:36:40 +02:00
|
|
|
%ignore DBG_Callback;
|
|
|
|
%feature("director") DBG_Hooks;
|
|
|
|
|
|
|
|
%{
|
|
|
|
//<code(py_dbg)>
|
|
|
|
static PyObject *meminfo_vec_t_to_py(meminfo_vec_t &areas);
|
|
|
|
//</code(py_dbg)>
|
|
|
|
%}
|
|
|
|
|
2011-06-10 16:54:03 +02:00
|
|
|
%extend bpt_t
|
|
|
|
{
|
|
|
|
PyObject *condition;
|
2014-07-05 00:02:42 +02:00
|
|
|
PyObject *elang;
|
2011-06-10 16:54:03 +02:00
|
|
|
}
|
|
|
|
%{
|
|
|
|
PyObject *bpt_t_condition_get(bpt_t *bpt)
|
|
|
|
{
|
|
|
|
return PyString_FromString(bpt->cndbody.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
void bpt_t_condition_set(bpt_t *bpt, PyObject *val)
|
|
|
|
{
|
|
|
|
if ( PyString_Check(val) )
|
|
|
|
bpt->cndbody = PyString_AsString(val);
|
2014-07-05 00:02:42 +02:00
|
|
|
else
|
|
|
|
PyErr_SetString(PyExc_ValueError, "expected a string");
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *bpt_t_elang_get(bpt_t *bpt)
|
|
|
|
{
|
|
|
|
return PyString_FromString(bpt->get_cnd_elang());
|
|
|
|
}
|
|
|
|
|
|
|
|
void bpt_t_elang_set(bpt_t *bpt, PyObject *val)
|
|
|
|
{
|
|
|
|
if ( PyString_Check(val) )
|
|
|
|
{
|
|
|
|
char *cval = PyString_AsString(val);
|
|
|
|
if ( !bpt->set_cnd_elang(cval) )
|
|
|
|
PyErr_SetString(PyExc_ValueError, "too many extlangs");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_ValueError, "expected a string");
|
|
|
|
}
|
2011-06-10 16:54:03 +02:00
|
|
|
}
|
|
|
|
%}
|
2010-06-28 14:36:40 +02:00
|
|
|
%inline %{
|
|
|
|
|
|
|
|
//<inline(py_dbg)>
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
#<pydoc>
|
|
|
|
def get_manual_regions():
|
|
|
|
"""
|
|
|
|
Returns the manual memory regions
|
|
|
|
@return: list(startEA, endEA, name, sclass, sbase, bitness, perm)
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
#</pydoc>
|
|
|
|
*/
|
|
|
|
static PyObject *py_get_manual_regions()
|
|
|
|
{
|
|
|
|
meminfo_vec_t areas;
|
|
|
|
get_manual_regions(&areas);
|
|
|
|
return meminfo_vec_t_to_py(areas);
|
|
|
|
}
|
|
|
|
|
2010-06-29 12:49:28 +02:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
#<pydoc>
|
|
|
|
def dbg_is_loaded():
|
|
|
|
"""
|
|
|
|
Checks if a debugger is loaded
|
|
|
|
@return: Boolean
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
#</pydoc>
|
|
|
|
*/
|
|
|
|
static bool dbg_is_loaded()
|
|
|
|
{
|
|
|
|
return dbg != NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-28 14:36:40 +02:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
#<pydoc>
|
|
|
|
def refresh_debugger_memory():
|
|
|
|
"""
|
|
|
|
Refreshes the debugger memory
|
|
|
|
@return: Nothing
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
#</pydoc>
|
|
|
|
*/
|
|
|
|
static PyObject *refresh_debugger_memory()
|
|
|
|
{
|
|
|
|
invalidate_dbgmem_config();
|
|
|
|
invalidate_dbgmem_contents(BADADDR, 0);
|
2011-04-18 18:07:00 +02:00
|
|
|
|
|
|
|
// Ask the debugger to populate debug names
|
2010-06-28 14:36:40 +02:00
|
|
|
if ( dbg != NULL && dbg->stopped_at_debug_event != NULL )
|
|
|
|
dbg->stopped_at_debug_event(true);
|
2011-04-18 18:07:00 +02:00
|
|
|
|
|
|
|
// Invalidate the cache
|
2010-06-28 14:36:40 +02:00
|
|
|
isEnabled(0);
|
|
|
|
|
2013-12-30 02:34:23 +01:00
|
|
|
PYW_GIL_CHECK_LOCKED_SCOPE();
|
2010-06-28 14:36:40 +02:00
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int idaapi DBG_Callback(void *ud, int notification_code, va_list va);
|
|
|
|
class DBG_Hooks
|
|
|
|
{
|
|
|
|
public:
|
2013-12-30 02:34:23 +01:00
|
|
|
virtual ~DBG_Hooks() { unhook(); }
|
2011-10-14 16:24:38 +02:00
|
|
|
|
2013-12-30 02:34:23 +01:00
|
|
|
bool hook() { return hook_to_notification_point(HT_DBG, DBG_Callback, this); }
|
|
|
|
bool unhook() { return unhook_from_notification_point(HT_DBG, DBG_Callback, this); }
|
2011-10-14 16:24:38 +02:00
|
|
|
/* Hook functions to be overridden in Python */
|
|
|
|
virtual void dbg_process_start(pid_t pid,
|
|
|
|
thid_t tid,
|
|
|
|
ea_t ea,
|
|
|
|
char *name,
|
|
|
|
ea_t base,
|
2013-12-30 02:34:23 +01:00
|
|
|
asize_t size) {}
|
2011-10-14 16:24:38 +02:00
|
|
|
virtual void dbg_process_exit(pid_t pid,
|
|
|
|
thid_t tid,
|
|
|
|
ea_t ea,
|
2013-12-30 02:34:23 +01:00
|
|
|
int exit_code) {}
|
2011-10-14 16:24:38 +02:00
|
|
|
virtual void dbg_process_attach(pid_t pid,
|
|
|
|
thid_t tid,
|
|
|
|
ea_t ea,
|
|
|
|
char *name,
|
|
|
|
ea_t base,
|
2013-12-30 02:34:23 +01:00
|
|
|
asize_t size) {}
|
2011-10-14 16:24:38 +02:00
|
|
|
virtual void dbg_process_detach(pid_t pid,
|
|
|
|
thid_t tid,
|
2013-12-30 02:34:23 +01:00
|
|
|
ea_t ea) {}
|
2011-10-14 16:24:38 +02:00
|
|
|
virtual void dbg_thread_start(pid_t pid,
|
|
|
|
thid_t tid,
|
2013-12-30 02:34:23 +01:00
|
|
|
ea_t ea) {}
|
2011-10-14 16:24:38 +02:00
|
|
|
virtual void dbg_thread_exit(pid_t pid,
|
|
|
|
thid_t tid,
|
|
|
|
ea_t ea,
|
2013-12-30 02:34:23 +01:00
|
|
|
int exit_code) {}
|
2011-10-14 16:24:38 +02:00
|
|
|
virtual void dbg_library_load(pid_t pid,
|
|
|
|
thid_t tid,
|
|
|
|
ea_t ea,
|
|
|
|
char *name,
|
|
|
|
ea_t base,
|
2013-12-30 02:34:23 +01:00
|
|
|
asize_t size) {}
|
2011-10-14 16:24:38 +02:00
|
|
|
virtual void dbg_library_unload(pid_t pid,
|
|
|
|
thid_t tid,
|
|
|
|
ea_t ea,
|
2013-12-30 02:34:23 +01:00
|
|
|
char *libname) {}
|
2011-10-14 16:24:38 +02:00
|
|
|
virtual void dbg_information(pid_t pid,
|
|
|
|
thid_t tid,
|
|
|
|
ea_t ea,
|
2013-12-30 02:34:23 +01:00
|
|
|
char *info) {}
|
2011-10-14 16:24:38 +02:00
|
|
|
virtual int dbg_exception(pid_t pid,
|
|
|
|
thid_t tid,
|
|
|
|
ea_t ea,
|
|
|
|
int code,
|
|
|
|
bool can_cont,
|
|
|
|
ea_t exc_ea,
|
2013-12-30 02:34:23 +01:00
|
|
|
char *info) { return 0; }
|
|
|
|
virtual void dbg_suspend_process(void) {}
|
|
|
|
virtual int dbg_bpt(thid_t tid, ea_t breakpoint_ea) { return 0; }
|
|
|
|
virtual int dbg_trace(thid_t tid, ea_t ip) { return 0; }
|
2011-10-14 16:24:38 +02:00
|
|
|
virtual void dbg_request_error(int failed_command,
|
2013-12-30 02:34:23 +01:00
|
|
|
int failed_dbg_notification) {}
|
|
|
|
virtual void dbg_step_into(void) {}
|
|
|
|
virtual void dbg_step_over(void) {}
|
|
|
|
virtual void dbg_run_to(pid_t pid, thid_t tid, ea_t ea) {}
|
|
|
|
virtual void dbg_step_until_ret(void) {}
|
2010-06-28 14:36:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
int idaapi DBG_Callback(void *ud, int notification_code, va_list va)
|
|
|
|
{
|
2013-12-30 02:34:23 +01:00
|
|
|
// This hook gets called from the kernel. Ensure we hold the GIL.
|
|
|
|
PYW_GIL_GET;
|
|
|
|
|
2010-06-28 14:36:40 +02:00
|
|
|
class DBG_Hooks *proxy = (class DBG_Hooks *)ud;
|
|
|
|
debug_event_t *event;
|
2011-10-14 16:24:38 +02:00
|
|
|
int code = 0;
|
2013-12-30 02:34:23 +01:00
|
|
|
|
2011-10-14 16:24:38 +02:00
|
|
|
try
|
|
|
|
{
|
2010-06-28 14:36:40 +02:00
|
|
|
switch (notification_code)
|
|
|
|
{
|
|
|
|
case dbg_process_start:
|
|
|
|
event = va_arg(va, debug_event_t *);
|
|
|
|
proxy->dbg_process_start(event->pid,
|
|
|
|
event->tid,
|
|
|
|
event->ea,
|
|
|
|
event->modinfo.name,
|
|
|
|
event->modinfo.base,
|
|
|
|
event->modinfo.size);
|
2011-10-14 16:24:38 +02:00
|
|
|
break;
|
|
|
|
|
2010-06-28 14:36:40 +02:00
|
|
|
case dbg_process_exit:
|
|
|
|
event = va_arg(va, debug_event_t *);
|
2011-10-14 16:24:38 +02:00
|
|
|
proxy->dbg_process_exit(
|
|
|
|
event->pid,
|
2010-06-28 14:36:40 +02:00
|
|
|
event->tid,
|
|
|
|
event->ea,
|
|
|
|
event->exit_code);
|
2011-10-14 16:24:38 +02:00
|
|
|
break;
|
2010-06-28 14:36:40 +02:00
|
|
|
|
|
|
|
case dbg_process_attach:
|
|
|
|
event = va_arg(va, debug_event_t *);
|
2011-10-14 16:24:38 +02:00
|
|
|
proxy->dbg_process_attach(
|
|
|
|
event->pid,
|
2010-06-28 14:36:40 +02:00
|
|
|
event->tid,
|
|
|
|
event->ea,
|
|
|
|
event->modinfo.name,
|
|
|
|
event->modinfo.base,
|
|
|
|
event->modinfo.size);
|
2011-10-14 16:24:38 +02:00
|
|
|
break;
|
2010-06-28 14:36:40 +02:00
|
|
|
|
|
|
|
case dbg_process_detach:
|
|
|
|
event = va_arg(va, debug_event_t *);
|
2011-10-14 16:24:38 +02:00
|
|
|
proxy->dbg_process_detach(
|
|
|
|
event->pid,
|
2010-06-28 14:36:40 +02:00
|
|
|
event->tid,
|
|
|
|
event->ea);
|
2011-10-14 16:24:38 +02:00
|
|
|
break;
|
2010-06-28 14:36:40 +02:00
|
|
|
|
|
|
|
case dbg_thread_start:
|
|
|
|
event = va_arg(va, debug_event_t *);
|
2011-10-14 16:24:38 +02:00
|
|
|
proxy->dbg_thread_start(
|
|
|
|
event->pid,
|
2010-06-28 14:36:40 +02:00
|
|
|
event->tid,
|
|
|
|
event->ea);
|
2011-10-14 16:24:38 +02:00
|
|
|
break;
|
2010-06-28 14:36:40 +02:00
|
|
|
|
|
|
|
case dbg_thread_exit:
|
|
|
|
event = va_arg(va, debug_event_t *);
|
2011-10-14 16:24:38 +02:00
|
|
|
proxy->dbg_thread_exit(
|
|
|
|
event->pid,
|
2010-06-28 14:36:40 +02:00
|
|
|
event->tid,
|
|
|
|
event->ea,
|
|
|
|
event->exit_code);
|
2011-10-14 16:24:38 +02:00
|
|
|
break;
|
2010-06-28 14:36:40 +02:00
|
|
|
|
|
|
|
case dbg_library_load:
|
|
|
|
event = va_arg(va, debug_event_t *);
|
2011-10-14 16:24:38 +02:00
|
|
|
proxy->dbg_library_load(
|
|
|
|
event->pid,
|
2010-06-28 14:36:40 +02:00
|
|
|
event->tid,
|
|
|
|
event->ea,
|
|
|
|
event->modinfo.name,
|
|
|
|
event->modinfo.base,
|
|
|
|
event->modinfo.size);
|
2011-10-14 16:24:38 +02:00
|
|
|
break;
|
2010-06-28 14:36:40 +02:00
|
|
|
|
|
|
|
case dbg_library_unload:
|
|
|
|
event = va_arg(va, debug_event_t *);
|
2011-10-14 16:24:38 +02:00
|
|
|
proxy->dbg_library_unload(
|
|
|
|
event->pid,
|
2010-06-28 14:36:40 +02:00
|
|
|
event->tid,
|
|
|
|
event->ea,
|
|
|
|
event->info);
|
2011-10-14 16:24:38 +02:00
|
|
|
break;
|
2010-06-28 14:36:40 +02:00
|
|
|
|
|
|
|
case dbg_information:
|
|
|
|
event = va_arg(va, debug_event_t *);
|
2011-10-14 16:24:38 +02:00
|
|
|
proxy->dbg_information(
|
|
|
|
event->pid,
|
2010-06-28 14:36:40 +02:00
|
|
|
event->tid,
|
|
|
|
event->ea,
|
|
|
|
event->info);
|
2011-10-14 16:24:38 +02:00
|
|
|
break;
|
2010-06-28 14:36:40 +02:00
|
|
|
|
|
|
|
case dbg_exception:
|
2011-10-14 16:24:38 +02:00
|
|
|
{
|
2010-06-28 14:36:40 +02:00
|
|
|
event = va_arg(va, debug_event_t *);
|
2011-10-14 16:24:38 +02:00
|
|
|
int *warn = va_arg(va, int *);
|
|
|
|
*warn = proxy->dbg_exception(
|
|
|
|
event->pid,
|
2010-06-28 14:36:40 +02:00
|
|
|
event->tid,
|
|
|
|
event->ea,
|
|
|
|
event->exc.code,
|
|
|
|
event->exc.can_cont,
|
|
|
|
event->exc.ea,
|
|
|
|
event->exc.info);
|
2011-10-14 16:24:38 +02:00
|
|
|
break;
|
|
|
|
}
|
2010-06-28 14:36:40 +02:00
|
|
|
|
|
|
|
case dbg_suspend_process:
|
|
|
|
proxy->dbg_suspend_process();
|
2011-10-14 16:24:38 +02:00
|
|
|
break;
|
2010-06-28 14:36:40 +02:00
|
|
|
|
|
|
|
case dbg_bpt:
|
2011-10-14 16:24:38 +02:00
|
|
|
{
|
|
|
|
thid_t tid = va_arg(va, thid_t);
|
|
|
|
ea_t breakpoint_ea = va_arg(va, ea_t);
|
|
|
|
int *warn = va_arg(va, int *);
|
2010-06-28 14:36:40 +02:00
|
|
|
*warn = proxy->dbg_bpt(tid, breakpoint_ea);
|
2011-10-14 16:24:38 +02:00
|
|
|
break;
|
|
|
|
}
|
2010-06-28 14:36:40 +02:00
|
|
|
|
|
|
|
case dbg_trace:
|
2011-10-14 16:24:38 +02:00
|
|
|
{
|
|
|
|
thid_t tid = va_arg(va, thid_t);
|
|
|
|
ea_t ip = va_arg(va, ea_t);
|
|
|
|
code = proxy->dbg_trace(tid, ip);
|
|
|
|
break;
|
|
|
|
}
|
2010-06-28 14:36:40 +02:00
|
|
|
|
|
|
|
case dbg_request_error:
|
|
|
|
{
|
|
|
|
int failed_command = (int)va_argi(va, ui_notification_t);
|
|
|
|
int failed_dbg_notification = (int)va_argi(va, dbg_notification_t);
|
|
|
|
proxy->dbg_request_error(failed_command, failed_dbg_notification);
|
2011-10-14 16:24:38 +02:00
|
|
|
break;
|
2010-06-28 14:36:40 +02:00
|
|
|
}
|
2011-10-14 16:24:38 +02:00
|
|
|
|
2010-06-28 14:36:40 +02:00
|
|
|
case dbg_step_into:
|
|
|
|
proxy->dbg_step_into();
|
2011-10-14 16:24:38 +02:00
|
|
|
break;
|
2010-06-28 14:36:40 +02:00
|
|
|
|
|
|
|
case dbg_step_over:
|
|
|
|
proxy->dbg_step_over();
|
2011-10-14 16:24:38 +02:00
|
|
|
break;
|
2010-06-28 14:36:40 +02:00
|
|
|
|
|
|
|
case dbg_run_to:
|
2011-10-14 16:24:38 +02:00
|
|
|
event = va_arg(va, debug_event_t *);
|
|
|
|
proxy->dbg_run_to(
|
|
|
|
event->pid,
|
|
|
|
event->tid,
|
|
|
|
event->ea);
|
|
|
|
break;
|
2010-06-28 14:36:40 +02:00
|
|
|
|
|
|
|
case dbg_step_until_ret:
|
|
|
|
proxy->dbg_step_until_ret();
|
2011-10-14 16:24:38 +02:00
|
|
|
break;
|
2010-06-28 14:36:40 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-14 16:24:38 +02:00
|
|
|
catch (Swig::DirectorException &e)
|
2010-06-28 14:36:40 +02:00
|
|
|
{
|
2011-10-14 16:24:38 +02:00
|
|
|
msg("Exception in DBG Hook function: %s\n", e.getMessage());
|
2010-06-28 14:36:40 +02:00
|
|
|
if (PyErr_Occurred())
|
|
|
|
PyErr_Print();
|
|
|
|
}
|
2011-10-14 16:24:38 +02:00
|
|
|
return code;
|
2010-06-28 14:36:40 +02:00
|
|
|
}
|
2011-10-14 16:24:38 +02:00
|
|
|
//</inline(py_dbg)>
|
2010-06-28 14:36:40 +02:00
|
|
|
|
|
|
|
%}
|