79 static PyObject* triton_BasicBlock(PyObject* self, PyObject* args) {
80 PyObject* obj =
nullptr;
83 if (PyArg_ParseTuple(args,
"|O", &obj) ==
false) {
84 return PyErr_Format(PyExc_TypeError,
"BasicBlock(): Invalid constructor.");
93 else if (obj !=
nullptr && PyList_Check(obj)) {
96 for (Py_ssize_t i = 0; i < PyList_Size(obj); i++) {
97 PyObject* item = PyList_GetItem(obj, i);
100 return PyErr_Format(PyExc_TypeError,
"BasicBlock(): All items must be an Instruction objet.");
110 return PyErr_Format(PyExc_TypeError,
"BasicBlock(): Invalid constructor.");
114 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
118 static PyObject* triton_Immediate(PyObject* self, PyObject* args) {
119 PyObject* value =
nullptr;
120 PyObject* size =
nullptr;
123 if (PyArg_ParseTuple(args,
"|OO", &value, &size) ==
false) {
124 return PyErr_Format(PyExc_TypeError,
"Immediate(): Invalid constructor.");
128 if (value ==
nullptr || (!PyLong_Check(value) && !PyInt_Check(value)))
129 return PyErr_Format(PyExc_TypeError,
"Immediate(): Expects an integer as first argument.");
132 if (size ==
nullptr || (!PyLong_Check(size) && !PyInt_Check(size)))
133 return PyErr_Format(PyExc_TypeError,
"Immediate(): Expects an integer as second argument.");
140 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
145 static PyObject* triton_Instruction(PyObject* self, PyObject* args) {
146 PyObject* arg1 =
nullptr;
147 PyObject* arg2 =
nullptr;
150 if (PyArg_ParseTuple(args,
"|OO", &arg1, &arg2) ==
false) {
151 return PyErr_Format(PyExc_TypeError,
"Instruction(): Invalid constructor.");
160 else if (arg1 && PyBytes_Check(arg1) && arg2 ==
nullptr) {
167 else if (arg1 && arg2 && (PyLong_Check(arg1) || PyInt_Check(arg1)) && PyBytes_Check(arg2)) {
175 return PyErr_Format(PyExc_TypeError,
"Instruction(): Expects bytes as first argument or an integer as first and bytes as second argument.");
179 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
184 static PyObject* triton_MemoryAccess(PyObject* self, PyObject* args) {
185 PyObject* address =
nullptr;
186 PyObject* size =
nullptr;
189 if (PyArg_ParseTuple(args,
"|OO", &address, &size) ==
false) {
190 return PyErr_Format(PyExc_TypeError,
"MemoryAccess(): Invalid constructor.");
194 if (address ==
nullptr || (!PyLong_Check(address) && !PyInt_Check(address)))
195 return PyErr_Format(PyExc_TypeError,
"MemoryAccess(): Expects an integer as first argument.");
198 if (size ==
nullptr || (!PyLong_Check(size) && !PyInt_Check(size)))
199 return PyErr_Format(PyExc_TypeError,
"MemoryAccess(): Expects an integer as second argument.");
206 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
211 static PyObject* triton_TritonContext(PyObject* self, PyObject* args) {
212 PyObject* arch =
nullptr;
215 if (PyArg_ParseTuple(args,
"|O", &arch) ==
false) {
216 return PyErr_Format(PyExc_TypeError,
"TritonContext(): Invalid constructor.");
220 if (arch ==
nullptr) {
223 if (arch ==
nullptr && (!PyLong_Check(arch) && !PyInt_Check(arch))) {
224 return PyErr_Format(PyExc_TypeError,
"TritonContext(): Invalid type of argument.");
229 return PyErr_Format(PyExc_TypeError,
"%s", e.
what());
235 {
"BasicBlock", (PyCFunction)triton_BasicBlock, METH_VARARGS,
""},
236 {
"Immediate", (PyCFunction)triton_Immediate, METH_VARARGS,
""},
237 {
"Instruction", (PyCFunction)triton_Instruction, METH_VARARGS,
""},
238 {
"MemoryAccess", (PyCFunction)triton_MemoryAccess, METH_VARARGS,
""},
239 {
"TritonContext", (PyCFunction)triton_TritonContext, METH_VARARGS,
""},
240 {
nullptr,
nullptr, 0,
nullptr}
This class is used to represent a basic block.
TRITON_EXPORT void add(const Instruction &instruction)
Add an instruction to the block.
This class is used to represent a memory access.
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.
PyMethodDef tritonCallbacks[]
triton python methods.
PyObject * PyBasicBlock(void)
Creates the BasicBlock python class.
PyObject * PyInstruction(void)
Creates the Instruction python class.
PyObject * PyTritonContext(void)
Creates the new TritonContext python class.
triton::uint32 PyLong_AsUint32(PyObject *vv)
Returns a triton::uint32 from a pyObject.
PyObject * PyMemoryAccess(const triton::arch::MemoryAccess &mem)
Creates the Memory python class.
std::uint64_t uint64
unisgned 64-bits
std::uint32_t uint32
unisgned 32-bits
std::uint8_t uint8
unisgned 8-bits
#define PyInstruction_AsInstruction(v)
#define PyInstruction_Check(v)