diff options
| author | William Bruneau <william.bruneau@epfedu.fr> | 2019-05-15 11:29:37 +0200 |
|---|---|---|
| committer | William Bruneau <william.bruneau@epfedu.fr> | 2019-05-15 12:32:32 +0200 |
| commit | df7fc844a15de590331fbc13408ff89506b9efa2 (patch) | |
| tree | 78ff1287dd22422d3d1082d1c4a029a0b7e4f636 /miasm/jitter/vm_mngr_py.c | |
| parent | bba990f43b73cbae980c70f6dc3a82511fcac3be (diff) | |
| download | focaccia-miasm-df7fc844a15de590331fbc13408ff89506b9efa2.tar.gz focaccia-miasm-df7fc844a15de590331fbc13408ff89506b9efa2.zip | |
bn_to_PyLong
Diffstat (limited to 'miasm/jitter/vm_mngr_py.c')
| -rw-r--r-- | miasm/jitter/vm_mngr_py.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/miasm/jitter/vm_mngr_py.c b/miasm/jitter/vm_mngr_py.c index 4684f8f8..69e62fef 100644 --- a/miasm/jitter/vm_mngr_py.c +++ b/miasm/jitter/vm_mngr_py.c @@ -1041,3 +1041,30 @@ bn_t PyLong_to_bn(PyObject* py_long) return bn; } + +PyObject* bn_to_PyLong(bn_t bn) +{ + int j; + PyObject* py_long; + PyObject* py_long_new; + PyObject* py_tmp; + PyObject* cst_32; + uint64_t tmp; + + py_long = PyLong_FromLong(0); + cst_32 = PyLong_FromLong(32); + + for (j = BN_BYTE_SIZE - 4; j >= 0 ; j -= 4) { + tmp = bignum_to_uint64(bignum_mask(bignum_rshift(bn, 8 * j), 32)); + py_tmp = PyLong_FromUnsignedLong((unsigned long)tmp); + py_long_new = PyObject_CallMethod(py_long, "__lshift__", "O", cst_32); + Py_DECREF(py_long); + py_long = PyObject_CallMethod(py_long_new, "__add__", "O", py_tmp); + Py_DECREF(py_long_new); + Py_DECREF(py_tmp); + } + + Py_DECREF(cst_32); + + return py_long; +} |