From 7d32ff30f0ce2780bfb717c799e537599acc7193 Mon Sep 17 00:00:00 2001 From: "elias.bachaalany" Date: Fri, 5 Mar 2010 10:20:42 +0000 Subject: [PATCH] Added get_many_bytes(ea, size) -> String | None --- swig/bytes.i | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/swig/bytes.i b/swig/bytes.i index 0044bb1..2ebe7fc 100644 --- a/swig/bytes.i +++ b/swig/bytes.i @@ -76,15 +76,16 @@ %rename (nextthat) py_nextthat; %rename (prevthat) py_prevthat; +%rename (get_many_bytes) py_get_many_bytes; %{ // //------------------------------------------------------------------------ static bool idaapi py_testf_cb(flags_t flags, void *ud) { - PyObject *py_flags = PyLong_FromLong(flags); + PyObject *py_flags = PyLong_FromUnsignedLong(flags); PyObject *result = PyObject_CallFunctionObjArgs((PyObject *) ud, py_flags, NULL); - bool ret = result != NULL && result == Py_True; + bool ret = result != NULL && PyObject_IsTrue(result); Py_XDECREF(result); Py_XDECREF(py_flags); return ret; @@ -92,12 +93,10 @@ static bool idaapi py_testf_cb(flags_t flags, void *ud) //------------------------------------------------------------------------ // Wraps the (next|prev)that() -ea_t py_npthat(ea_t ea, ea_t bound, PyObject *py_callable, bool next) +static ea_t py_npthat(ea_t ea, ea_t bound, PyObject *py_callable, bool next) { if (!PyCallable_Check(py_callable)) return BADADDR; -// ea_t (ida_export *np_that_t)(ea_t, ea_t, testf_t *, void *ud); -// np_that_t = ; return (next ? nextthat : prevthat)(ea, bound, py_testf_cb, py_callable); } // @@ -105,14 +104,47 @@ ea_t py_npthat(ea_t ea, ea_t bound, PyObject *py_callable, bool next) %inline %{ // -ea_t py_nextthat(ea_t ea, ea_t maxea, PyObject *callable) + +//------------------------------------------------------------------------ +static ea_t py_nextthat(ea_t ea, ea_t maxea, PyObject *callable) { return py_npthat(ea, maxea, callable, true); } -ea_t py_prevthat(ea_t ea, ea_t minea, PyObject *callable) +static ea_t py_prevthat(ea_t ea, ea_t minea, PyObject *callable) { return py_npthat(ea, minea, callable, false); } + +//------------------------------------------------------------------------ +// Get the specified number of bytes of the program into the buffer. +static PyObject *py_get_many_bytes(ea_t ea, int size) +{ + do + { + if (size <= 0) + break; + // Allocate memory + char *buf = (char *) qalloc(size); + if (buf == NULL) + break; + + // Read bytes + bool ok = get_many_bytes(ea, buf, size); + + // If ok, create a python string + PyObject *py_buf; + if (ok) + py_buf = PyString_FromStringAndSize(buf, size); + + // Free buffer + qfree(buf); + + // Return buffer to Python + if (ok) + return py_buf; + } while (false); + Py_RETURN_NONE; +} // %}