Added get_many_bytes(ea, size) -> String | None

This commit is contained in:
elias.bachaalany 2010-03-05 10:20:42 +00:00
parent 42a2f7f630
commit 7d32ff30f0

View File

@ -76,15 +76,16 @@
%rename (nextthat) py_nextthat;
%rename (prevthat) py_prevthat;
%rename (get_many_bytes) py_get_many_bytes;
%{
//<code(py_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);
}
//</code(py_bytes)>
@ -105,14 +104,47 @@ ea_t py_npthat(ea_t ea, ea_t bound, PyObject *py_callable, bool next)
%inline %{
//<inline(py_bytes)>
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;
}
//</inline(py_bytes)>
%}