From c29e1ef2da64ca86bc8df374ce90d9d01e762e48 Mon Sep 17 00:00:00 2001 From: "elias.bachaalany" Date: Mon, 23 May 2011 15:54:27 +0000 Subject: [PATCH] - added ph_get_operand_info() --- swig/bytes.i | 2 +- swig/idp.i | 92 +++++++++++++++++++++++++++++++++++++++++++++----- swig/kernwin.i | 9 ++--- swig/netnode.i | 3 +- 4 files changed, 91 insertions(+), 15 deletions(-) diff --git a/swig/bytes.i b/swig/bytes.i index 3e71db8..544d58c 100644 --- a/swig/bytes.i +++ b/swig/bytes.i @@ -668,7 +668,7 @@ static PyObject *py_get_many_bytes(ea_t ea, unsigned int size) { if ( size <= 0 ) break; - + // Allocate memory via Python PyObject *py_buf = PyString_FromStringAndSize(NULL, Py_ssize_t(size)); if ( py_buf == NULL ) diff --git a/swig/idp.i b/swig/idp.i index cf1462f..f88b046 100644 --- a/swig/idp.i +++ b/swig/idp.i @@ -32,7 +32,7 @@ %ignore ph; %ignore IDB_Callback; %ignore IDP_Callback; - +%ignore _py_getreg; %ignore free_processor_module; %ignore read_config_file; @@ -66,10 +66,10 @@ def AssembleLine(ea, cs, ip, use32, line): # */ static PyObject *AssembleLine( - ea_t ea, - ea_t cs, - ea_t ip, - bool use32, + ea_t ea, + ea_t cs, + ea_t ip, + bool use32, const char *line) { int inslen; @@ -99,10 +99,10 @@ def assemble(ea, cs, ip, use32, line): # */ bool assemble( - ea_t ea, - ea_t cs, - ea_t ip, - bool use32, + ea_t ea, + ea_t cs, + ea_t ip, + bool use32, const char *line) { int inslen; @@ -389,6 +389,66 @@ static PyObject *ph_get_regnames() return py_result; } +//--------------------------------------------------------------------------- +static const regval_t *idaapi _py_getreg( + const char *name, + const regval_t *regvals); + +/* +# +def ph_get_operand_info(): + """ + Returns the operand information given an ea and operand number. + + @param ea: address + @param n: operand number + + @return: Returns an idd_opinfo_t as a tuple: (modified, ea, reg_ival, regidx, value_size). + Please refer to idd_opinfo_t structure in the SDK. + """ + pass +# +*/ +static PyObject *ph_get_operand_info( + ea_t ea, + int n) +{ + do + { + if ( dbg == NULL || n == - 1 ) + break; + + // Allocate register space + thid_t tid = get_current_thread(); + regvals_t regvalues; + regvalues.reserve(dbg->registers_size); + + // Read registers + if ( dbg->read_registers(tid, -1, regvalues.begin()) != 1 ) + break; + + // Call the processor module + idd_opinfo_t opinf; + if ( ph.notify(ph.get_operand_info, + ea, + n, + tid, + _py_getreg, + regvalues.begin(), + &opinf) != 0 ) + { + break; + } + return Py_BuildValue("(i" PY_FMT64 "Kii)", + opinf.modified, + opinf.ea, + opinf.value.ival, + opinf.debregidx, + opinf.value_size); + } while (false); + Py_RETURN_NONE; +} + //------------------------------------------------------------------------- /* # @@ -1200,6 +1260,20 @@ int idaapi IDB_Callback(void *ud, int notification_code, va_list va) return 0; } +//------------------------------------------------------------------------- +static const regval_t *idaapi _py_getreg( + const char *name, + const regval_t *regvals) +{ + for ( int i=dbg->registers_size - 1; i >= 0; i-- ) + { + if ( stricmp(name, dbg->registers[i].name) == 0 ) + return ®vals[i]; + } + static regval_t rv; + return &rv; +} + //------------------------------------------------------------------------- // %} \ No newline at end of file diff --git a/swig/kernwin.i b/swig/kernwin.i index ebb7a15..0f8beca 100644 --- a/swig/kernwin.i +++ b/swig/kernwin.i @@ -408,6 +408,7 @@ class UI_Hooks(object): (these names can be looked up in ida[tg]ui.cfg) @return: 0-ok, nonzero - a plugin has handled the command """ + pass def postprocess(self): """ @@ -727,15 +728,15 @@ int idaapi UI_Callback(void *ud, int notification_code, va_list va) { switch (notification_code) { - case ui_preprocess: + case ui_preprocess: { const char *name = va_arg(va, const char *); return proxy->preprocess(name); } - case ui_postprocess: - proxy->postprocess(); - break; + case ui_postprocess: + proxy->postprocess(); + break; } } catch (Swig::DirectorException &) diff --git a/swig/netnode.i b/swig/netnode.i index 62d1215..d5bb599 100644 --- a/swig/netnode.i +++ b/swig/netnode.i @@ -111,4 +111,5 @@ return py_str; } -} \ No newline at end of file +} +