static PyObject *Triton_getRegs(PyObject *self, PyObject *noargs) { PyObject *regs = xPyDict_New(); /* Build all Registers */ for (uint64 regId = ID_RAX; regId < ID_RFLAGS; regId++){ PyObject *reg = xPyDict_New(); RegisterOperand ro = createTmpReg(regId); if (regId >= ID_XMM0 && regId <= ID_XMM15) PyDict_SetItemString(reg, "concreteValue", uint128ToPyLongObject(ap.getSSERegisterValue(ro))); else PyDict_SetItemString(reg, "concreteValue", Py_BuildValue("k", ap.getRegisterValue(ro))); PyDict_SetItemString(reg, "symbolicExpr", Py_BuildValue("k", ap.getRegSymbolicID(ro))); PyDict_SetItem(regs, Py_BuildValue("k", regId), reg); } /* Build all Flags */ for (uint64 flagId = ID_AF; flagId <= ID_ZF; flagId++){ PyObject *flag = xPyDict_New(); RegisterOperand fo = createTmpFlag(flagId); PyDict_SetItemString(flag, "concreteValue", Py_BuildValue("k", ap.getFlagValue(fo))); PyDict_SetItemString(flag, "symbolicExpr", Py_BuildValue("k", ap.getRegSymbolicID(fo))); PyDict_SetItem(regs, Py_BuildValue("k", flagId), flag); } return regs; }
static PyObject *Triton_convertRegToSymVar(PyObject *self, PyObject *args) { PyObject *regId, *symVarSize, *varComment = nullptr; uint64 vs; std::string vc; /* Extract arguments */ PyArg_ParseTuple(args, "O|O|O", ®Id, &symVarSize, &varComment); if (varComment == nullptr) varComment = PyString_FromString(""); if (!PyLong_Check(regId) && !PyInt_Check(regId)) return PyErr_Format(PyExc_TypeError, "convertRegToSymVar(): expected a IDREF.REG as first argument"); if (!PyLong_Check(symVarSize) && !PyInt_Check(symVarSize)) return PyErr_Format(PyExc_TypeError, "convertRegToSymVar(): expected a size as second argument"); if (!PyString_Check(varComment)) return PyErr_Format(PyExc_TypeError, "convertRegToSymVar(): expected a comment (string) as third argument"); vs = PyLong_AsLong(symVarSize); vc = PyString_AsString(varComment); RegisterOperand ro = createTmpReg(PyLong_AsLong(regId)); return PySymbolicVariable(ap.convertRegToSymVar(ro, vs, vc)); }
static PyObject *Triton_setRegValue(PyObject *self, PyObject *args) { PyObject *reg; PyObject *value; uint128 va; uint64 tr; /* Extract arguments */ PyArg_ParseTuple(args, "O|O", ®, &value); if (!PyLong_Check(reg) && !PyInt_Check(reg)) return PyErr_Format(PyExc_TypeError, "setRegValue(): expected an IDREF.REG as first argument"); if (!PyLong_Check(value) && !PyInt_Check(value)) return PyErr_Format(PyExc_TypeError, "setRegValue(): expected an integer as second argument"); va = PyLongObjectToUint128(value); tr = PyLong_AsLong(reg); RegisterOperand ro = createTmpReg(tr); if (tr >= ID_XMM0 && tr <= ID_XMM15) ap.setSSERegisterValue(ro, va); else ap.setRegisterValue(ro, boost::numeric_cast<uint64>(va)); Py_INCREF(Py_None); return Py_None; }
static PyObject *Triton_taintReg(PyObject *self, PyObject *reg) { if (!PyLong_Check(reg) && !PyInt_Check(reg)) return PyErr_Format(PyExc_TypeError, "taintReg(): expected a register id (integer) as argument"); RegisterOperand ro = createTmpReg(PyInt_AsLong(reg)); ap.taintReg(ro); Py_INCREF(Py_None); return Py_None; }
static PyObject *Triton_concretizeReg(PyObject *self, PyObject *regId) { if (!PyLong_Check(regId) && !PyInt_Check(regId)) return PyErr_Format(PyExc_TypeError, "concretizeReg(): expected a IDREF.REG as argument"); RegisterOperand reg = createTmpReg(PyLong_AsLong(regId)); ap.concretizeReg(reg); Py_INCREF(Py_None); return Py_None; }
static PyObject *Triton_isRegTainted(PyObject *self, PyObject *reg) { if (!PyLong_Check(reg) && !PyInt_Check(reg)) return PyErr_Format(PyExc_TypeError, "isRegTainted(): expected a register id (integer) as argument"); RegisterOperand ro = createTmpReg(PyInt_AsLong(reg)); if (ap.isRegTainted(ro) == true) Py_RETURN_TRUE; Py_RETURN_FALSE; }
static PyObject *Triton_getRegSymbolicID(PyObject *self, PyObject *reg) { RegisterOperand ro; uint64 regId = 0; if (!PyLong_Check(reg) && !PyInt_Check(reg)) return PyErr_Format(PyExc_TypeError, "getRegSymbolicID(): expected a register id (integer) as argument"); regId = PyLong_AsLongLong(reg); ro = createTmpReg(regId); return Py_BuildValue("k", ap.getRegSymbolicID(ro)); }
void ProcessingPyConf::untaintRegFromAddr(uint64 addr) { // Apply this bindings only if the analysis is enable if (!this->analysisTrigger->getState()) return; // Check if there is registers untainted via the python bindings std::list<uint64> regsUntainted = PyTritonOptions::untaintRegFromAddr[addr]; std::list<uint64>::iterator it = regsUntainted.begin(); for ( ; it != regsUntainted.end(); it++) { RegisterOperand reg = createTmpReg(*it); this->ap->untaintReg(reg); } }
static PyObject *Triton_getRegValue(PyObject *self, PyObject *regId) { RegisterOperand reg; uint64 tritonReg; if (!PyLong_Check(regId) && !PyInt_Check(regId)) return PyErr_Format(PyExc_TypeError, "getRegValue(): expected a register id (IDREF.REG) as argument"); if (!ap.getCurrentCtxH()) return PyErr_Format(PyExc_TypeError, "getRegValue(): Can't call getRegValue() right now. You must run the program before."); tritonReg = PyLong_AsLong(regId); reg = createTmpReg(tritonReg); if (tritonReg >= ID_XMM0 && tritonReg <= ID_XMM15){ uint128 value = ap.getSSERegisterValue(reg); return uint128ToPyLongObject(value); } return Py_BuildValue("k", ap.getRegisterValue(reg)); }