mirror of
https://github.com/angr/pyvex
synced 2026-06-21 13:47:01 +00:00
added support for Binder IRExpr
This commit is contained in:
@@ -37,3 +37,4 @@ Awesome stuff!
|
||||
- there is no memory management. VEX is kind of weird with this, so care will have to be taken...
|
||||
- converting from string to tag is currently very slow (a hastily written consecutive bunch of strcmps)
|
||||
- IRCallee assumes that addresses are 64-bytes long, and will corrupt memory otherwise. This can be fixed by writing a getter/setter instead of using the macroed ones.
|
||||
- deepCopying a binder IRExpr seems to crash VEX
|
||||
|
||||
@@ -54,6 +54,7 @@ initpyvex(void)
|
||||
|
||||
// expressions
|
||||
PYVEX_INITTYPE(IRExpr);
|
||||
PYVEX_INITTYPE(IRExprBinder);
|
||||
PYVEX_INITTYPE(IRExprRdTmp);
|
||||
PYVEX_INITTYPE(IRExprGet);
|
||||
PYVEX_INITTYPE(IRExprQop);
|
||||
|
||||
+32
-2
@@ -56,7 +56,7 @@ PyObject *wrap_IRExpr(IRExpr *i)
|
||||
|
||||
switch (i->tag)
|
||||
{
|
||||
//PYVEX_WRAPCASE(IRExpr, Iex_, Binder)
|
||||
PYVEX_WRAPCASE(IRExpr, Iex_, Binder)
|
||||
PYVEX_WRAPCASE(IRExpr, Iex_, Get)
|
||||
//PYVEX_WRAPCASE(IRExpr, Iex_, GetI)
|
||||
PYVEX_WRAPCASE(IRExpr, Iex_, RdTmp)
|
||||
@@ -80,6 +80,36 @@ PyObject *wrap_IRExpr(IRExpr *i)
|
||||
return (PyObject *)o;
|
||||
}
|
||||
|
||||
///////////////////
|
||||
// Binder IRExpr //
|
||||
///////////////////
|
||||
|
||||
static int
|
||||
pyIRExprBinder_init(pyIRExpr *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
PYVEX_WRAP_CONSTRUCTOR(IRExpr);
|
||||
|
||||
Int binder;
|
||||
static char *kwlist[] = {"binder", NULL};
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &binder)) return -1;
|
||||
|
||||
self->wrapped = IRExpr_Binder(binder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
PYVEX_ACCESSOR_BUILDVAL(IRExprBinder, IRExpr, wrapped->Iex.Binder.binder, binder, "i")
|
||||
|
||||
static PyGetSetDef pyIRExprBinder_getseters[] =
|
||||
{
|
||||
PYVEX_ACCESSOR_DEF(IRExprBinder, binder),
|
||||
{NULL}
|
||||
};
|
||||
|
||||
PyObject *pyIRExprBinder_deepCopy(PyObject *self) { PyErr_SetString(VexException, "binder does not support deepCopy()"); return NULL; }
|
||||
|
||||
static PyMethodDef pyIRExprBinder_methods[] = { {"deepCopy", (PyCFunction)pyIRExprBinder_deepCopy, METH_NOARGS, "not supported by binder"}, {NULL} };
|
||||
PYVEX_SUBTYPEOBJECT(IRExprBinder, IRExpr);
|
||||
|
||||
////////////////
|
||||
// Get IRExpr //
|
||||
////////////////
|
||||
@@ -123,7 +153,7 @@ pyIRExprRdTmp_init(pyIRExpr *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
PYVEX_WRAP_CONSTRUCTOR(IRExpr);
|
||||
|
||||
UInt tmp;
|
||||
IRTemp tmp;
|
||||
static char *kwlist[] = {"tmp", NULL};
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "I", kwlist, &tmp)) return -1;
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ extern PyTypeObject pyIRStmtExitType;
|
||||
|
||||
// expressions
|
||||
PYVEX_TYPEHEADER(IRExpr);
|
||||
extern PyTypeObject pyIRExprBinderType;
|
||||
extern PyTypeObject pyIRExprRdTmpType;
|
||||
extern PyTypeObject pyIRExprGetType;
|
||||
extern PyTypeObject pyIRExprQopType;
|
||||
|
||||
@@ -269,6 +269,11 @@ class PyVEXTest(unittest.TestCase):
|
||||
### Expressions ###
|
||||
###################
|
||||
|
||||
def test_irexpr_binder(self):
|
||||
m = pyvex.IRExprBinder(1534252)
|
||||
self.assertEqual(m.binder, 1534252)
|
||||
self.assertRaises(Exception, m.deepCopy, ())
|
||||
|
||||
def test_irexpr_rdtmp(self):
|
||||
irsb = pyvex.IRSB(bytes='\x90\x5d\xc3')
|
||||
self.assertEqual(irsb.next.tmp, irsb.next.deepCopy().tmp)
|
||||
|
||||
Reference in New Issue
Block a user