From ab81000187de2366e28367e2577e5462b7fdfd28 Mon Sep 17 00:00:00 2001 From: "elias.bachaalany" Date: Mon, 22 Mar 2010 14:21:43 +0000 Subject: [PATCH] - added GetInstructionList() and GetRegisterList() to idautils.py - ignored processor_t and ph global variable --- python/idautils.py | 7 ++++ python/idc.py | 8 ++-- swig/idp.i | 91 ++++++++++++++++++++++++++-------------------- 3 files changed, 62 insertions(+), 44 deletions(-) diff --git a/python/idautils.py b/python/idautils.py index 00e2087..a1cc034 100644 --- a/python/idautils.py +++ b/python/idautils.py @@ -451,6 +451,13 @@ class Strings(object): return Strings.StringItem(self._si) return None +def GetRegisterList(): + """Returns the register list""" + return idaapi.ph_get_regnames() + +def GetInstructionList(): + """Returns the instruction list of the current processor module""" + return [i[0] for i in idaapi.ph_get_instruc() if i[0]] def _Assemble(ea, line): """ diff --git a/python/idc.py b/python/idc.py index 733b6fb..c9f87e5 100644 --- a/python/idc.py +++ b/python/idc.py @@ -805,7 +805,7 @@ def MakePackReal(ea): @return: 1-ok, 0-failure """ - return idaapi.doPackReal(ea, idaapi.cvar.ph.tbyte_size) + return idaapi.doPackReal(ea, idaapi.ph_get_tbyte_size()) def MakeTbyte(ea): @@ -816,7 +816,7 @@ def MakeTbyte(ea): @return: 1-ok, 0-failure """ - return idaapi.doTbyt(ea, idaapi.cvar.ph.tbyte_size) + return idaapi.doTbyt(ea, idaapi.ph_get_tbyte_size()) def MakeStructEx(ea, size, strname): @@ -2352,13 +2352,13 @@ def ChangeConfig(directive): @note: If the directives are erroneous, a fatal error will be generated. The changes will be effective only for the current session. """ - return Eval('ChangeConfig("%s")'%directive) + return Eval('ChangeConfig("%s")' % directive) # The following functions allow you to set/get common parameters. # Please note that not all parameters can be set directly. -def GetLongPrm (offset): +def GetLongPrm(offset): """ """ val = _IDC_GetAttr(idaapi.cvar.inf, _INFMAP, offset) diff --git a/swig/idp.i b/swig/idp.i index 23f24a0..540367f 100644 --- a/swig/idp.i +++ b/swig/idp.i @@ -2,6 +2,9 @@ %ignore WorkReg; %ignore AbstractRegister; %ignore rginfo; +%ignore insn_t::get_canon_mnem; +%ignore insn_t::get_canon_feature; +%ignore insn_t::is_canon_insn; %ignore bytes_t; %ignore IDPOPT_STR; %ignore IDPOPT_NUM; @@ -14,7 +17,6 @@ %ignore IDPOPT_BADVALUE; %ignore set_options_t; %ignore read_user_config_file; -%ignore instruc_t; %ignore s_preline; %ignore ca_operation_t; @@ -25,43 +27,16 @@ %ignore asm_t::func_header; %ignore asm_t::func_footer; %ignore asm_t::get_type_name; -%ignore processor_t::notify; -%ignore processor_t::header; -%ignore processor_t::footer; -%ignore processor_t::segstart; -%ignore processor_t::segend; -%ignore processor_t::assumes; -%ignore processor_t::u_ana; -%ignore processor_t::u_emu; -%ignore processor_t::u_out; -%ignore processor_t::u_outop; -%ignore processor_t::d_out; -%ignore processor_t::cmp_opnd; -%ignore processor_t::can_have_type; -%ignore processor_t::getreg; -%ignore processor_t::is_far_jump; -%ignore processor_t::translate; -%ignore processor_t::realcvt; -%ignore processor_t::is_switch; -%ignore processor_t::gen_map_file; -%ignore processor_t::extract_address; -%ignore processor_t::is_sp_based; -%ignore processor_t::create_func_frame; -%ignore processor_t::get_frame_retsize; -%ignore processor_t::gen_stkvar_def; -%ignore processor_t::u_outspec; -%ignore processor_t::is_align_insn; +%ignore instruc_t; +%ignore processor_t; +%ignore ph; %ignore IDB_Callback; -%ignore processor_t::idp_notify; -%ignore processor_t::notify; -%ignore processor_t::set_idp_options; %ignore free_processor_module; %ignore read_config_file; %ignore gen_idb_event; - %include "idp.hpp" %feature("director") IDB_Hooks; @@ -306,6 +281,10 @@ inline const int assemble(ea_t ea, ea_t cs, ea_t ip, bool use32, const char *lin return 0; } +// +//------------------------------------------------------------------------- + +//------------------------------------------------------------------------- // Assemble an instruction to a buffer (display a warning if an error is found) // args: // ea_t ea - linear address of instruction @@ -314,15 +293,47 @@ inline const int assemble(ea_t ea, ea_t cs, ea_t ip, bool use32, const char *lin // bool use32 - is 32bit segment? // const char *line - line to assemble // returns: 1: success, 0: failure -inline const PyObject *AssembleLine(ea_t ea, ea_t cs, ea_t ip, bool use32, const char *line) +static PyObject *AssembleLine(ea_t ea, ea_t cs, ea_t ip, bool use32, const char *line) { - int inslen; - char buf[MAXSTR]; - if (ph.notify != NULL && - (inslen = ph.notify(ph.assemble, ea, cs, ip, use32, line, buf)) > 0) - { - return PyString_FromStringAndSize(buf, inslen); - } - Py_RETURN_NONE; + int inslen; + char buf[MAXSTR]; + if (ph.notify != NULL && + (inslen = ph.notify(ph.assemble, ea, cs, ip, use32, line, buf)) > 0) + { + return PyString_FromStringAndSize(buf, inslen); + } + Py_RETURN_NONE; } + +//------------------------------------------------------------------------- +static size_t ph_get_tbyte_size() +{ + return ph.tbyte_size; +} + +//------------------------------------------------------------------------- +static PyObject *ph_get_instruc() +{ + Py_ssize_t i = 0; + PyObject *py_result = PyTuple_New(ph.instruc_end - ph.instruc_start); + for ( instruc_t *p = ph.instruc + ph.instruc_start, *end = ph.instruc + ph.instruc_end; + p != end; + ++p ) + { + PyTuple_SetItem(py_result, i++, Py_BuildValue("(sI)", p->name, p->feature)); + } + return py_result; +} + +//------------------------------------------------------------------------- +static PyObject *ph_get_regnames() +{ + Py_ssize_t i = 0; + PyObject *py_result = PyList_New(ph.regsNum); + for ( Py_ssize_t i=0; i %}