Skip to content

Commit

Permalink
Merge pull request #1307 from mvanotti/getSourceAddress
Browse files Browse the repository at this point in the history
Add getSourceAddress to PathConstraint
  • Loading branch information
JonathanSalwan authored Feb 29, 2024
2 parents a03142d + 2b835cb commit 06610ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/libtriton/bindings/python/objects/pyPathConstraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ instruction address.
- <b>string getComment(void)</b><br>
Returns the comment (if exists) of the path constraint.
- <b>integer getSourceAddress(void)</b><br>
Returns the source address of the branch.
- <b>integer getTakenAddress(void)</b><br>
Returns the address of the taken branch.
Expand Down Expand Up @@ -147,6 +150,16 @@ namespace triton {
}


static PyObject* PathConstraint_getSourceAddress(PyObject* self, PyObject* noarg) {
try {
return PyLong_FromUint64(PyPathConstraint_AsPathConstraint(self)->getSourceAddress());
}
catch (const triton::exceptions::Exception& e) {
return PyErr_Format(PyExc_TypeError, "%s", e.what());
}
}


static PyObject* PathConstraint_getTakenAddress(PyObject* self, PyObject* noarg) {
try {
return PyLong_FromUint64(PyPathConstraint_AsPathConstraint(self)->getTakenAddress());
Expand Down Expand Up @@ -207,6 +220,7 @@ namespace triton {
PyMethodDef PathConstraint_callbacks[] = {
{"getBranchConstraints", PathConstraint_getBranchConstraints, METH_NOARGS, ""},
{"getComment", PathConstraint_getComment, METH_NOARGS, ""},
{"getSourceAddress", PathConstraint_getSourceAddress, METH_NOARGS, ""},
{"getTakenAddress", PathConstraint_getTakenAddress, METH_NOARGS, ""},
{"getTakenPredicate", PathConstraint_getTakenPredicate, METH_NOARGS, ""},
{"getThreadId", PathConstraint_getThreadId, METH_NOARGS, ""},
Expand Down
4 changes: 4 additions & 0 deletions src/testers/unittests/test_path_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def test_getTakenPredicate(self):
pc = self.ctx.getPathConstraints()[0]
self.assertEqual(pc.getTakenPredicate().evaluate(), 1)

def test_getSourceAddress(self):
pc = self.ctx.getPathConstraints()[0]
self.assertEqual(pc.getSourceAddress(), 17)

def test_getTakenAddress(self):
pc = self.ctx.getPathConstraints()[0]
self.assertEqual(pc.getTakenAddress(), 108)
Expand Down

0 comments on commit 06610ca

Please sign in to comment.