248 std::cout << std::flush;
250 Py_TYPE(self)->tp_free((PyObject*)self);
254 static PyObject* Instruction_getAddress(PyObject* self, PyObject* noarg) {
259 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
264 static PyObject* Instruction_getCodeCondition(PyObject* self, PyObject* noarg) {
269 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
274 static PyObject* Instruction_getDisassembly(PyObject* self, PyObject* noarg) {
282 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
287 static PyObject* Instruction_getLoadAccess(PyObject* self, PyObject* noarg) {
294 for (
auto it = loadAccess.cbegin(); it != loadAccess.cend(); it++) {
297 PyTuple_SetItem(item, 1,
PyAstNode(std::get<1>(*it)));
298 PyList_SetItem(ret, index++, item);
304 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
309 static PyObject* Instruction_getNextAddress(PyObject* self, PyObject* noarg) {
314 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
319 static PyObject* Instruction_getOpcode(PyObject* self, PyObject* noarg) {
323 return PyBytes_FromStringAndSize(
reinterpret_cast<const char*
>(opcode), size);
326 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
331 static PyObject* Instruction_getSize(PyObject* self, PyObject* noarg) {
336 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
341 static PyObject* Instruction_getStoreAccess(PyObject* self, PyObject* noarg) {
348 for (
auto it = storeAccess.cbegin(); it != storeAccess.cend(); it++) {
351 PyTuple_SetItem(item, 1,
PyAstNode(std::get<1>(*it)));
352 PyList_SetItem(ret, index++, item);
358 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
363 static PyObject* Instruction_getOperands(PyObject* self, PyObject* noarg) {
374 PyObject* obj =
nullptr;
391 PyList_SetItem(operands, index, obj);
397 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
402 static PyObject* Instruction_getPrefix(PyObject* self, PyObject* noarg) {
407 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
412 static PyObject* Instruction_getReadImmediates(PyObject* self, PyObject* noarg) {
419 for (
auto it = readImmediates.cbegin(); it != readImmediates.cend(); it++) {
421 PyTuple_SetItem(item, 0,
PyImmediate(std::get<0>(*it)));
422 PyTuple_SetItem(item, 1,
PyAstNode(std::get<1>(*it)));
423 PyList_SetItem(ret, index++, item);
429 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
434 static PyObject* Instruction_getReadRegisters(PyObject* self, PyObject* noarg) {
441 for (
auto it = readRegisters.cbegin(); it != readRegisters.cend(); it++) {
443 PyTuple_SetItem(item, 0,
PyRegister(std::get<0>(*it)));
444 PyTuple_SetItem(item, 1,
PyAstNode(std::get<1>(*it)));
445 PyList_SetItem(ret, index++, item);
451 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
456 static PyObject* Instruction_getSymbolicExpressions(PyObject* self, PyObject* noarg) {
468 PyList_SetItem(symExprs, index, obj);
474 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
479 static PyObject* Instruction_getThreadId(PyObject* self, PyObject* noarg) {
484 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
489 static PyObject* Instruction_getType(PyObject* self, PyObject* noarg) {
494 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
499 static PyObject* Instruction_getUndefinedRegisters(PyObject* self, PyObject* noarg) {
506 for (
auto it = undefinedRegisters.cbegin(); it != undefinedRegisters.cend(); it++) {
507 PyList_SetItem(ret, index++,
PyRegister(*it));
513 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
518 static PyObject* Instruction_getWrittenRegisters(PyObject* self, PyObject* noarg) {
525 for (
auto it = writtenRegisters.cbegin(); it != writtenRegisters.cend(); it++) {
527 PyTuple_SetItem(item, 0,
PyRegister(std::get<0>(*it)));
528 PyTuple_SetItem(item, 1,
PyAstNode(std::get<1>(*it)));
529 PyList_SetItem(ret, index++, item);
535 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
540 static PyObject* Instruction_isBranch(PyObject* self, PyObject* noarg) {
547 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
552 static PyObject* Instruction_isConditionTaken(PyObject* self, PyObject* noarg) {
559 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
564 static PyObject* Instruction_isControlFlow(PyObject* self, PyObject* noarg) {
571 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
576 static PyObject* Instruction_isMemoryRead(PyObject* self, PyObject* noarg) {
583 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
588 static PyObject* Instruction_isMemoryWrite(PyObject* self, PyObject* noarg) {
595 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
600 static PyObject* Instruction_isPrefixed(PyObject* self, PyObject* noarg) {
607 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
612 static PyObject* Instruction_isSymbolized(PyObject* self, PyObject* noarg) {
619 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
624 static PyObject* Instruction_isTainted(PyObject* self, PyObject* noarg) {
631 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
636 static PyObject* Instruction_isWriteBack(PyObject* self, PyObject* noarg) {
643 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
648 static PyObject* Instruction_isUpdateFlag(PyObject* self, PyObject* noarg) {
655 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
660 static PyObject* Instruction_isThumb(PyObject* self, PyObject* noarg) {
667 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
672 static PyObject* Instruction_setAddress(PyObject* self, PyObject* addr) {
674 if (!PyLong_Check(addr) && !PyInt_Check(addr))
675 return PyErr_Format(PyExc_TypeError,
"Instruction::setAddress(): Expected an integer as argument.");
681 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
686 static PyObject* Instruction_setOpcode(PyObject* self, PyObject* opc) {
688 if (!PyBytes_Check(opc))
689 return PyErr_Format(PyExc_TypeError,
"Instruction::setOpcode(): Expected bytes as argument.");
699 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
704 static PyObject* Instruction_setThreadId(PyObject* self, PyObject* tid) {
706 if (!PyLong_Check(tid) && !PyInt_Check(tid))
707 return PyErr_Format(PyExc_TypeError,
"Instruction::setThreadId(): Expected an integer as argument.");
714 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
719 #if !defined(IS_PY3_8) || !IS_PY3_8
720 static int Instruction_print(PyObject* self,
void* io,
int s) {
727 static PyObject* Instruction_str(PyObject* self) {
732 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
739 {
"getAddress", Instruction_getAddress, METH_NOARGS,
""},
740 {
"getCodeCondition", Instruction_getCodeCondition, METH_NOARGS,
""},
741 {
"getDisassembly", Instruction_getDisassembly, METH_NOARGS,
""},
742 {
"getLoadAccess", Instruction_getLoadAccess, METH_NOARGS,
""},
743 {
"getNextAddress", Instruction_getNextAddress, METH_NOARGS,
""},
744 {
"getOpcode", Instruction_getOpcode, METH_NOARGS,
""},
745 {
"getOperands", Instruction_getOperands, METH_NOARGS,
""},
746 {
"getPrefix", Instruction_getPrefix, METH_NOARGS,
""},
747 {
"getReadImmediates", Instruction_getReadImmediates, METH_NOARGS,
""},
748 {
"getReadRegisters", Instruction_getReadRegisters, METH_NOARGS,
""},
749 {
"getSize", Instruction_getSize, METH_NOARGS,
""},
750 {
"getStoreAccess", Instruction_getStoreAccess, METH_NOARGS,
""},
751 {
"getSymbolicExpressions", Instruction_getSymbolicExpressions, METH_NOARGS,
""},
752 {
"getThreadId", Instruction_getThreadId, METH_NOARGS,
""},
753 {
"getType", Instruction_getType, METH_NOARGS,
""},
754 {
"getUndefinedRegisters", Instruction_getUndefinedRegisters, METH_NOARGS,
""},
755 {
"getWrittenRegisters", Instruction_getWrittenRegisters, METH_NOARGS,
""},
756 {
"isBranch", Instruction_isBranch, METH_NOARGS,
""},
757 {
"isConditionTaken", Instruction_isConditionTaken, METH_NOARGS,
""},
758 {
"isControlFlow", Instruction_isControlFlow, METH_NOARGS,
""},
759 {
"isMemoryRead", Instruction_isMemoryRead, METH_NOARGS,
""},
760 {
"isMemoryWrite", Instruction_isMemoryWrite, METH_NOARGS,
""},
761 {
"isPrefixed", Instruction_isPrefixed, METH_NOARGS,
""},
762 {
"isSymbolized", Instruction_isSymbolized, METH_NOARGS,
""},
763 {
"isTainted", Instruction_isTainted, METH_NOARGS,
""},
764 {
"isWriteBack", Instruction_isWriteBack, METH_NOARGS,
""},
765 {
"isUpdateFlag", Instruction_isUpdateFlag, METH_NOARGS,
""},
766 {
"isThumb", Instruction_isThumb, METH_NOARGS,
""},
767 {
"setAddress", Instruction_setAddress, METH_O,
""},
768 {
"setOpcode", Instruction_setOpcode, METH_O,
""},
769 {
"setThreadId", Instruction_setThreadId, METH_O,
""},
770 {
nullptr,
nullptr, 0,
nullptr}
775 PyVarObject_HEAD_INIT(&PyType_Type, 0)
783 (printfunc)Instruction_print,
788 (reprfunc)Instruction_str,
794 (reprfunc)Instruction_str,
799 "Instruction objects",
848 return (PyObject*)object;
860 return (PyObject*)object;
872 return (PyObject*)object;
884 return (PyObject*)object;
This class is used to represent an instruction.
std::vector< triton::arch::OperandWrapper > operands
A list of operands.
std::vector< triton::engines::symbolic::SharedSymbolicExpression > symbolicExpressions
The semantics set of the instruction.
This class is used to represent a memory access.
This class is used when an instruction has a register operand.
The root class of all exceptions.
TRITON_EXPORT const char * what() const
Returns the exception message.
triton::uint64 PyLong_AsUint64(PyObject *vv)
Returns a triton::uint64 from a pyObject.
PyObject * PyImmediate(const triton::arch::Immediate &imm)
Creates the Immediate python class.
PyObject * xPyTuple_New(Py_ssize_t len)
Creates a PyTuple and raises an exception if it fails.
PyTypeObject Instruction_Type
pyInstruction type.
PyObject * PyInstruction(void)
Creates the Instruction python class.
PyObject * xPyList_New(Py_ssize_t len)
Creates a PyList and raises an exception if it fails.
PyObject * PyLong_FromUint64(triton::uint64 value)
Returns a pyObject from a triton::uint64.
PyObject * PyRegister(const triton::arch::Register ®)
Creates the Register python class.
triton::uint32 PyLong_AsUint32(PyObject *vv)
Returns a triton::uint32 from a pyObject.
PyObject * PySymbolicExpression(const triton::engines::symbolic::SharedSymbolicExpression &symExpr)
Creates the SymbolicExpression python class.
PyObject * PyMemoryAccess(const triton::arch::MemoryAccess &mem)
Creates the Memory python class.
PyObject * PyLong_FromUint32(triton::uint32 value)
Returns a pyObject from a triton::uint32.
PyObject * PyAstNode(const triton::ast::SharedAbstractNode &node)
Creates the AstNode python class.
std::size_t usize
unsigned MAX_INT 32 or 64 bits according to the CPU.
std::uint64_t uint64
unisgned 64-bits
std::uint32_t uint32
unisgned 32-bits
std::uint8_t uint8
unisgned 8-bits
std::string toString(const T &obj)
Converts an object to a string.
PyMethodDef Instruction_callbacks[]
Instruction methods.
void Instruction_dealloc(PyObject *self)
Instruction destructor.
#define PyInstruction_AsInstruction(v)