libTriton version 1.0 build 1590
Loading...
Searching...
No Matches
pySymbolicExpression.cpp
Go to the documentation of this file.
1
2/*
3** Copyright (C) - Triton
4**
5** This program is under the terms of the Apache License 2.0.
6*/
7
11#include <triton/coreUtils.hpp>
12#include <triton/exceptions.hpp>
14
15#include <iostream>
16
17
18
136namespace triton {
137 namespace bindings {
138 namespace python {
139
141 void SymbolicExpression_dealloc(PyObject* self) {
142 std::cout << std::flush;
143 PySymbolicExpression_AsSymbolicExpression(self) = nullptr; // decref the shared_ptr
144 Py_TYPE(self)->tp_free((PyObject*)self);
145 }
146
147
148 static PyObject* SymbolicExpression_getAst(PyObject* self, PyObject* noarg) {
149 try {
151 }
152 catch (const triton::exceptions::Exception& e) {
153 return PyErr_Format(PyExc_TypeError, "%s", e.what());
154 }
155 }
156
157
158 static PyObject* SymbolicExpression_getComment(PyObject* self, PyObject* noarg) {
159 try {
160 return Py_BuildValue("s", PySymbolicExpression_AsSymbolicExpression(self)->getComment().c_str());
161 }
162 catch (const triton::exceptions::Exception& e) {
163 return PyErr_Format(PyExc_TypeError, "%s", e.what());
164 }
165 }
166
167
168 static PyObject* SymbolicExpression_getDisassembly(PyObject* self, PyObject* noarg) {
169 try {
170 return Py_BuildValue("s", PySymbolicExpression_AsSymbolicExpression(self)->getDisassembly().c_str());
171 }
172 catch (const triton::exceptions::Exception& e) {
173 return PyErr_Format(PyExc_TypeError, "%s", e.what());
174 }
175 }
176
177
178 static PyObject* SymbolicExpression_getId(PyObject* self, PyObject* noarg) {
179 try {
181 }
182 catch (const triton::exceptions::Exception& e) {
183 return PyErr_Format(PyExc_TypeError, "%s", e.what());
184 }
185 }
186
187
188 static PyObject* SymbolicExpression_getNewAst(PyObject* self, PyObject* noarg) {
189 try {
190 return PyAstNode(PySymbolicExpression_AsSymbolicExpression(self)->getNewAst());
191 }
192 catch (const triton::exceptions::Exception& e) {
193 return PyErr_Format(PyExc_TypeError, "%s", e.what());
194 }
195 }
196
197
198 static PyObject* SymbolicExpression_getOrigin(PyObject* self, PyObject* noarg) {
199 try {
200 if (PySymbolicExpression_AsSymbolicExpression(self)->isMemory())
201 return PyMemoryAccess(PySymbolicExpression_AsSymbolicExpression(self)->getOriginMemory());
202
203 else if (PySymbolicExpression_AsSymbolicExpression(self)->isRegister())
204 return PyRegister(PySymbolicExpression_AsSymbolicExpression(self)->getOriginRegister());
205
206 Py_INCREF(Py_None);
207 return Py_None;
208 }
209 catch (const triton::exceptions::Exception& e) {
210 return PyErr_Format(PyExc_TypeError, "%s", e.what());
211 }
212 }
213
214
215 static PyObject* SymbolicExpression_getType(PyObject* self, PyObject* noarg) {
216 try {
218 }
219 catch (const triton::exceptions::Exception& e) {
220 return PyErr_Format(PyExc_TypeError, "%s", e.what());
221 }
222 }
223
224
225 static PyObject* SymbolicExpression_isMemory(PyObject* self, PyObject* noarg) {
226 try {
227 if (PySymbolicExpression_AsSymbolicExpression(self)->isMemory() == true)
228 Py_RETURN_TRUE;
229 Py_RETURN_FALSE;
230 }
231 catch (const triton::exceptions::Exception& e) {
232 return PyErr_Format(PyExc_TypeError, "%s", e.what());
233 }
234 }
235
236
237 static PyObject* SymbolicExpression_isRegister(PyObject* self, PyObject* noarg) {
238 try {
239 if (PySymbolicExpression_AsSymbolicExpression(self)->isRegister() == true)
240 Py_RETURN_TRUE;
241 Py_RETURN_FALSE;
242 }
243 catch (const triton::exceptions::Exception& e) {
244 return PyErr_Format(PyExc_TypeError, "%s", e.what());
245 }
246 }
247
248
249 static PyObject* SymbolicExpression_isSymbolized(PyObject* self, PyObject* noarg) {
250 try {
251 if (PySymbolicExpression_AsSymbolicExpression(self)->isSymbolized() == true)
252 Py_RETURN_TRUE;
253 Py_RETURN_FALSE;
254 }
255 catch (const triton::exceptions::Exception& e) {
256 return PyErr_Format(PyExc_TypeError, "%s", e.what());
257 }
258 }
259
260
261 static PyObject* SymbolicExpression_isTainted(PyObject* self, PyObject* noarg) {
262 try {
263 if (PySymbolicExpression_AsSymbolicExpression(self)->isTainted == true)
264 Py_RETURN_TRUE;
265 Py_RETURN_FALSE;
266 }
267 catch (const triton::exceptions::Exception& e) {
268 return PyErr_Format(PyExc_TypeError, "%s", e.what());
269 }
270 }
271
272
273 static PyObject* SymbolicExpression_setAst(PyObject* self, PyObject* node) {
274 try {
275 if (!PyAstNode_Check(node))
276 return PyErr_Format(PyExc_TypeError, "SymbolicExpression::setAst(): Expected a AstNode as argument.");
278 Py_INCREF(Py_None);
279 return Py_None;
280 }
281 catch (const triton::exceptions::Exception& e) {
282 return PyErr_Format(PyExc_TypeError, "%s", e.what());
283 }
284 }
285
286
287 static PyObject* SymbolicExpression_setComment(PyObject* self, PyObject* comment) {
288 try {
289 if (!PyStr_Check(comment))
290 return PyErr_Format(PyExc_TypeError, "SymbolicExpression::setComment(): Expected a string as argument.");
291 PySymbolicExpression_AsSymbolicExpression(self)->setComment(PyStr_AsString(comment));
292 Py_INCREF(Py_None);
293 return Py_None;
294 }
295 catch (const triton::exceptions::Exception& e) {
296 return PyErr_Format(PyExc_TypeError, "%s", e.what());
297 }
298 }
299
300
301 #if !defined(IS_PY3_8) || !IS_PY3_8
302 static int SymbolicExpression_print(PyObject* self, void* io, int s) {
304 return 0;
305 }
306 #endif
307
308
309 static PyObject* SymbolicExpression_str(PyObject* self) {
310 try {
311 return PyStr_FromFormat("%s", triton::utils::toString(PySymbolicExpression_AsSymbolicExpression(self)).c_str());
312 }
313 catch (const triton::exceptions::Exception& e) {
314 return PyErr_Format(PyExc_TypeError, "%s", e.what());
315 }
316 }
317
318
319 static int SymbolicExpression_init(AstNode_Object *self, PyObject *args, PyObject *kwds) {
320 return 0;
321 }
322
323
324 static PyObject* SymbolicExpression_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
325 return type->tp_alloc(type, 0);
326 }
327
328
331 {"getAst", SymbolicExpression_getAst, METH_NOARGS, ""},
332 {"getComment", SymbolicExpression_getComment, METH_NOARGS, ""},
333 {"getDisassembly", SymbolicExpression_getDisassembly, METH_NOARGS, ""},
334 {"getId", SymbolicExpression_getId, METH_NOARGS, ""},
335 {"getNewAst", SymbolicExpression_getNewAst, METH_NOARGS, ""},
336 {"getOrigin", SymbolicExpression_getOrigin, METH_NOARGS, ""},
337 {"getType", SymbolicExpression_getType, METH_NOARGS, ""},
338 {"isMemory", SymbolicExpression_isMemory, METH_NOARGS, ""},
339 {"isRegister", SymbolicExpression_isRegister, METH_NOARGS, ""},
340 {"isSymbolized", SymbolicExpression_isSymbolized, METH_NOARGS, ""},
341 {"isTainted", SymbolicExpression_isTainted, METH_NOARGS, ""},
342 {"setAst", SymbolicExpression_setAst, METH_O, ""},
343 {"setComment", SymbolicExpression_setComment, METH_O, ""},
344 {nullptr, nullptr, 0, nullptr}
345 };
346
347
348 PyTypeObject SymbolicExpression_Type = {
349 PyVarObject_HEAD_INIT(&PyType_Type, 0)
350 "SymbolicExpression", /* tp_name */
351 sizeof(SymbolicExpression_Object), /* tp_basicsize */
352 0, /* tp_itemsize */
353 (destructor)SymbolicExpression_dealloc, /* tp_dealloc */
354 #if IS_PY3_8
355 0, /* tp_vectorcall_offset */
356 #else
357 (printfunc)SymbolicExpression_print, /* tp_print */
358 #endif
359 0, /* tp_getattr */
360 0, /* tp_setattr */
361 0, /* tp_compare */
362 (reprfunc)SymbolicExpression_str, /* tp_repr */
363 0, /* tp_as_number */
364 0, /* tp_as_sequence */
365 0, /* tp_as_mapping */
366 0, /* tp_hash */
367 0, /* tp_call */
368 (reprfunc)SymbolicExpression_str, /* tp_str */
369 0, /* tp_getattro */
370 0, /* tp_setattro */
371 0, /* tp_as_buffer */
372 Py_TPFLAGS_DEFAULT, /* tp_flags */
373 "SymbolicExpression objects", /* tp_doc */
374 0, /* tp_traverse */
375 0, /* tp_clear */
376 0, /* tp_richcompare */
377 0, /* tp_weaklistoffset */
378 0, /* tp_iter */
379 0, /* tp_iternext */
380 SymbolicExpression_callbacks, /* tp_methods */
381 0, /* tp_members */
382 0, /* tp_getset */
383 0, /* tp_base */
384 0, /* tp_dict */
385 0, /* tp_descr_get */
386 0, /* tp_descr_set */
387 0, /* tp_dictoffset */
388 (initproc)SymbolicExpression_init, /* tp_init */
389 0, /* tp_alloc */
390 (newfunc)SymbolicExpression_new, /* tp_new */
391 0, /* tp_free */
392 0, /* tp_is_gc */
393 0, /* tp_bases */
394 0, /* tp_mro */
395 0, /* tp_cache */
396 0, /* tp_subclasses */
397 0, /* tp_weaklist */
398 0, /* tp_del */
399 #if IS_PY3
400 0, /* tp_version_tag */
401 0, /* tp_finalize */
402 #if IS_PY3_8
403 0, /* tp_vectorcall */
404 #if !IS_PY3_9
405 0, /* bpo-37250: kept for backwards compatibility in CPython 3.8 only */
406 #endif
407 #endif
408 #else
409 0 /* tp_version_tag */
410 #endif
411 };
412
413
415 if (symExpr == nullptr) {
416 Py_INCREF(Py_None);
417 return Py_None;
418 }
419
420 PyType_Ready(&SymbolicExpression_Type);
421 auto* object = (triton::bindings::python::SymbolicExpression_Object*)PyObject_CallObject((PyObject*)&SymbolicExpression_Type, nullptr);
422 if (object != NULL) {
423 object->symExpr = symExpr;
424 }
425
426 return (PyObject*)object;
427 }
428
429 }; /* python namespace */
430 }; /* bindings namespace */
431}; /* triton namespace */
The root class of all exceptions.
TRITON_EXPORT const char * what() const
Returns the exception message.
PyObject * PyLong_FromUsize(triton::usize value)
Returns a pyObject from a triton::usize.
Definition utils.cpp:268
PyTypeObject SymbolicExpression_Type
pySymbolicExpression type.
PyObject * PyRegister(const triton::arch::Register &reg)
Creates the Register python class.
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.
Definition utils.cpp:305
PyObject * PyAstNode(const triton::ast::SharedAbstractNode &node)
Creates the AstNode python class.
std::shared_ptr< triton::engines::symbolic::SymbolicExpression > SharedSymbolicExpression
Shared Symbolic Expression.
Definition ast.hpp:40
std::string toString(const T &obj)
Converts an object to a string.
Definition coreUtils.hpp:38
PyMethodDef SymbolicExpression_callbacks[]
SymbolicExpression methods.
void SymbolicExpression_dealloc(PyObject *self)
SymbolicExpression destructor.
The Triton namespace.
#define PyAstNode_Check(v)
#define PyAstNode_AsAstNode(v)
#define PySymbolicExpression_AsSymbolicExpression(v)