diff --git a/BUILDING.txt b/BUILDING.txt index 9a55369..f3aca99 100644 --- a/BUILDING.txt +++ b/BUILDING.txt @@ -38,7 +38,7 @@ Make sure all the needed tools (compiler, swig) are on the PATH. 1, Unpack the IDAPython source and IDA Pro SDK into the following directory structure: - swigsdk-versions/5.6/ - version 5.4 of the IDA Pro SDK + swigsdk-versions/5.6/ - version 5.6 of the IDA Pro SDK idapython/ - IDAPython source code 2, On Mac OS X copy libida.dylib from the IDA install directory to diff --git a/build.py b/build.py index 2a6e2a4..97f250f 100644 --- a/build.py +++ b/build.py @@ -79,7 +79,8 @@ BINDIST_MANIFEST = [ "examples/ex_choose2.py", "examples/ex_debug_names.py", "examples/ex_graph.py", - "examples/ex_dbg.py" + "examples/ex_dbg.py", + "examples/ex_imports.py" ] # List files for the source distribution (appended to binary list) diff --git a/examples/ex_imports.py b/examples/ex_imports.py new file mode 100644 index 0000000..642a0f0 --- /dev/null +++ b/examples/ex_imports.py @@ -0,0 +1,26 @@ +# ----------------------------------------------------------------------- +# This is an example illustrating how to enumerate imports +# (c) Hex-Rays +# +import idaapi + +def imp_cb(ea, name, ord): + print "%08x: %s (ord#%d)" % (ea, name, ord) + # True -> Continue enumeration + # False -> Stop enumeration + return True + +nimps = idaapi.get_import_module_qty() + +print "Found %d import(s)..." % nimps + +for i in xrange(0, nimps): + name = idaapi.get_import_module_name(i) + if not name: + print "Failed to get import module name for #%d" % i + continue + + print "Walking-> %s" % name + idaapi.enum_import_names(i, imp_cb) + +print "All done..." \ No newline at end of file diff --git a/swig/nalt.i b/swig/nalt.i index 7039b47..344464a 100644 --- a/swig/nalt.i +++ b/swig/nalt.i @@ -1,7 +1,63 @@ %ignore nmSerEA; %ignore nmSerN; %ignore maxSerialName; - +%ignore get_import_module_name; +%rename (get_import_module_name) py_get_import_module_name; %ignore NALT_EA; +%ignore enum_import_names; +%rename (enum_import_names) py_enum_import_names; -%include "nalt.hpp" \ No newline at end of file +%include "nalt.hpp" + +%{ +// + +//------------------------------------------------------------------------- +// callback for enumerating imports +// ea: import address +// name: import name (NULL if imported by ordinal) +// ord: import ordinal (0 for imports by name) +// param: user parameter passed to enum_import_names() +// return: 1-ok, 0-stop enumeration +static int idaapi py_import_enum_cb( + ea_t ea, + const char *name, + uval_t ord, + void *param) +{ + PyObject *py_ea = Py_BuildValue(PY_FMT64, pyul_t(ea)); + PyObject *py_name = PyString_FromString(name); + PyObject *py_ord = Py_BuildValue(PY_FMT64, pyul_t(ord)); + PyObject *py_result = PyObject_CallFunctionObjArgs((PyObject *)param, py_ea, py_name, py_ord, NULL); + int r = py_result != NULL && PyObject_IsTrue(py_result) ? 1 : 0; + Py_DECREF(py_ea); + Py_DECREF(py_name); + Py_DECREF(py_ord); + return r; +} +// +%} + +%inline %{ +// +//------------------------------------------------------------------------- +PyObject *py_get_import_module_name(int mod_index) +{ + char buf[MAXSTR]; + if ( !get_import_module_name(mod_index, buf, sizeof(buf)) ) + Py_RETURN_NONE; + return PyString_FromString(buf); +} + +//------------------------------------------------------------------------- +// enumerate imports from specific module +// return: 1-finished ok, -1 on error, otherwise callback return value (<=0) +int py_enum_import_names(int mod_index, PyObject *py_cb) +{ + if ( !PyCallable_Check(py_cb) ) + return -1; + return enum_import_names(mod_index, py_import_enum_cb, py_cb); +} + +// +%} \ No newline at end of file