libTriton version 1.0 build 1592
Loading...
Searching...
No Matches
pyTritonContext.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/arm32Cpu.hpp>
12#include <triton/context.hpp>
13#include <triton/exceptions.hpp>
14#include <triton/register.hpp>
15
16
17
461namespace triton {
462 namespace bindings {
463 namespace python {
464
465 static void TritonContext_dealloc(PyObject* self) {
466 if (((TritonContext_Object*)self)->ref == false)
468 Py_XDECREF(((TritonContext_Object*)self)->regAttr);
469 Py_TYPE(self)->tp_free((PyObject*)self);
470 }
471
472
473 static void TritonContext_fillRegistersAttribute(PyObject* self) {
474 /* Fill self->regAttr */
475 auto& regs = PyTritonContext_AsTritonContext(self)->getAllRegisters();
476
477 PyObject* registersDict = xPyDict_New();
478 for (auto& reg : regs)
479 xPyDict_SetItem(registersDict, xPyString_FromString(reg.second.getName().c_str()), PyRegister(reg.second));
480
481 Py_XDECREF(((TritonContext_Object*)(self))->regAttr);
482 ((TritonContext_Object*)(self))->regAttr = xPyClass_New(nullptr, registersDict, xPyString_FromString("registers"));
483 }
484
485
486 static PyObject* TritonContext_addCallback(PyObject* self, PyObject* args) {
487 PyObject* function = nullptr;
488 PyObject* mode = nullptr;
489 PyObject* cb = nullptr;
490 PyObject* cb_self = nullptr;
491
492 /* Extract arguments */
493 if (PyArg_ParseTuple(args, "|OO", &mode, &function) == false) {
494 return PyErr_Format(PyExc_TypeError, "TritonContext::addCallback(): Invalid number of arguments");
495 }
496
497 if (mode == nullptr || (!PyLong_Check(mode) && !PyInt_Check(mode)))
498 return PyErr_Format(PyExc_TypeError, "TritonContext::addCallback(): Expects a CALLBACK as first argument.");
499
500 if (function == nullptr || !PyCallable_Check(function))
501 return PyErr_Format(PyExc_TypeError, "TritonContext::addCallback(): Expects a function as second argument.");
502
503 if (PyMethod_Check(function)) {
504 cb_self = PyMethod_GET_SELF(function);
505 cb = PyMethod_GET_FUNCTION(function);
506 }
507 else {
508 cb = function;
509 }
510
511 try {
512 switch (static_cast<triton::callbacks::callback_e>(PyLong_AsUint32(mode))) {
513
516 /********* Lambda *********/
517 PyObject* args = nullptr;
518
519 /* Create function args */
520 if (cb_self) {
522 PyTuple_SetItem(args, 0, cb_self);
523 PyTuple_SetItem(args, 1, triton::bindings::python::PyTritonContextRef(ctx));
524 PyTuple_SetItem(args, 2, triton::bindings::python::PyMemoryAccess(mem));
525 Py_INCREF(cb_self);
526 }
527 else {
529 PyTuple_SetItem(args, 0, triton::bindings::python::PyTritonContextRef(ctx));
530 PyTuple_SetItem(args, 1, triton::bindings::python::PyMemoryAccess(mem));
531 }
532
533 /* Call the callback */
534 PyObject* ret = PyObject_CallObject(cb, args);
535
536 /* Release args */
537 Py_DECREF(args);
538
539 /* Check the call */
540 if (ret == nullptr) {
542 }
543 /********* End of lambda *********/
544 }, cb));
545 break;
546
549 /********* Lambda *********/
550 PyObject* args = nullptr;
551
552 /* Create function args */
553 if (cb_self) {
555 PyTuple_SetItem(args, 0, cb_self);
556 PyTuple_SetItem(args, 1, triton::bindings::python::PyTritonContextRef(ctx));
557 PyTuple_SetItem(args, 2, triton::bindings::python::PyRegister(reg));
558 Py_INCREF(cb_self);
559 }
560 else {
562 PyTuple_SetItem(args, 0, triton::bindings::python::PyTritonContextRef(ctx));
563 PyTuple_SetItem(args, 1, triton::bindings::python::PyRegister(reg));
564 }
565
566 /* Call the callback */
567 PyObject* ret = PyObject_CallObject(cb, args);
568
569 /* Release args */
570 Py_DECREF(args);
571
572 /* Check the call */
573 if (ret == nullptr) {
575 }
576 /********* End of lambda *********/
577 }, cb));
578 break;
579
582 /********* Lambda *********/
583 PyObject* args = nullptr;
584
585 /* Create function args */
586 if (cb_self) {
588 PyTuple_SetItem(args, 0, cb_self);
589 PyTuple_SetItem(args, 1, triton::bindings::python::PyTritonContextRef(ctx));
590 PyTuple_SetItem(args, 2, triton::bindings::python::PyMemoryAccess(mem));
591 PyTuple_SetItem(args, 3, triton::bindings::python::PyLong_FromUint512(value));
592 Py_INCREF(cb_self);
593 }
594 else {
596 PyTuple_SetItem(args, 0, triton::bindings::python::PyTritonContextRef(ctx));
597 PyTuple_SetItem(args, 1, triton::bindings::python::PyMemoryAccess(mem));
598 PyTuple_SetItem(args, 2, triton::bindings::python::PyLong_FromUint512(value));
599 }
600
601 /* Call the callback */
602 PyObject* ret = PyObject_CallObject(cb, args);
603
604 /* Release args */
605 Py_DECREF(args);
606
607 /* Check the call */
608 if (ret == nullptr) {
610 }
611 /********* End of lambda *********/
612 }, cb));
613 break;
614
617 /********* Lambda *********/
618 PyObject* args = nullptr;
619
620 /* Create function args */
621 if (cb_self) {
623 PyTuple_SetItem(args, 0, cb_self);
624 PyTuple_SetItem(args, 1, triton::bindings::python::PyTritonContextRef(ctx));
625 PyTuple_SetItem(args, 2, triton::bindings::python::PyRegister(reg));
626 PyTuple_SetItem(args, 3, triton::bindings::python::PyLong_FromUint512(value));
627 Py_INCREF(cb_self);
628 }
629 else {
631 PyTuple_SetItem(args, 0, triton::bindings::python::PyTritonContextRef(ctx));
632 PyTuple_SetItem(args, 1, triton::bindings::python::PyRegister(reg));
633 PyTuple_SetItem(args, 2, triton::bindings::python::PyLong_FromUint512(value));
634 }
635
636 /* Call the callback */
637 PyObject* ret = PyObject_CallObject(cb, args);
638
639 /* Release args */
640 Py_DECREF(args);
641
642 /* Check the call */
643 if (ret == nullptr) {
645 }
646 /********* End of lambda *********/
647 }, cb));
648 break;
649
652 /********* Lambda *********/
653 PyObject* args = nullptr;
654
655 /* Create function args */
656 if (cb_self) {
658 PyTuple_SetItem(args, 0, cb_self);
659 PyTuple_SetItem(args, 1, triton::bindings::python::PyTritonContextRef(ctx));
660 PyTuple_SetItem(args, 2, triton::bindings::python::PyAstNode(node));
661 Py_INCREF(cb_self);
662 }
663 else {
665 PyTuple_SetItem(args, 0, triton::bindings::python::PyTritonContextRef(ctx));
666 PyTuple_SetItem(args, 1, triton::bindings::python::PyAstNode(node));
667 }
668
669 /* Call the callback */
670 PyObject* ret = PyObject_CallObject(cb, args);
671
672 /* Release args */
673 Py_DECREF(args);
674
675 /* Check the call */
676 if (ret == nullptr) {
678 }
679
680 /* Check if the callback has returned a AbstractNode */
681 if (!PyAstNode_Check(ret))
682 throw triton::exceptions::Callbacks("Callbacks::processCallbacks(SYMBOLIC_SIMPLIFICATION): You must return a AstNode object.");
683
684 /* Update node */
685 node = PyAstNode_AsAstNode(ret);
686 return node;
687 /********* End of lambda *********/
688 }, cb));
689 break;
690
691 default:
692 return PyErr_Format(PyExc_TypeError, "Callbacks::addCallback(): Invalid kind of callback.");
693 }
694 }
695 catch (const triton::exceptions::PyCallbacks&) {
696 return nullptr;
697 }
698 catch (const triton::exceptions::Exception& e) {
699 return PyErr_Format(PyExc_TypeError, "%s", e.what());
700 }
701
702 Py_INCREF(Py_None);
703 return Py_None;
704 }
705
706
707 static PyObject* TritonContext_assignSymbolicExpressionToMemory(PyObject* self, PyObject* args) {
708 PyObject* se = nullptr;
709 PyObject* mem = nullptr;
710
711 /* Extract arguments */
712 if (PyArg_ParseTuple(args, "|OO", &se, &mem) == false) {
713 return PyErr_Format(PyExc_TypeError, "TritonContext::assignSymbolicExpressionToMemory(): Invalid number of arguments");
714 }
715
716 if (se == nullptr || (!PySymbolicExpression_Check(se)))
717 return PyErr_Format(PyExc_TypeError, "TritonContext::assignSymbolicExpressionToMemory(): Expects a SymbolicExpression as first argument.");
718
719 if (mem == nullptr || (!PyMemoryAccess_Check(mem)))
720 return PyErr_Format(PyExc_TypeError, "TritonContext::assignSymbolicExpressionToMemory(): Expects a MemoryAccess as second argument.");
721
724
725 try {
726 PyTritonContext_AsTritonContext(self)->assignSymbolicExpressionToMemory(arg1, arg2);
727 }
728 catch (const triton::exceptions::PyCallbacks&) {
729 return nullptr;
730 }
731 catch (const triton::exceptions::Exception& e) {
732 return PyErr_Format(PyExc_TypeError, "%s", e.what());
733 }
734
735 Py_INCREF(Py_None);
736 return Py_None;
737 }
738
739
740 static PyObject* TritonContext_assignSymbolicExpressionToRegister(PyObject* self, PyObject* args) {
741 PyObject* se = nullptr;
742 PyObject* reg = nullptr;
743
744 /* Extract arguments */
745 if (PyArg_ParseTuple(args, "|OO", &se, &reg) == false) {
746 return PyErr_Format(PyExc_TypeError, "TritonContext::assignSymbolicExpressionToRegister(): Invalid number of arguments");
747 }
748
749 if (se == nullptr || (!PySymbolicExpression_Check(se)))
750 return PyErr_Format(PyExc_TypeError, "TritonContext::assignSymbolicExpressionToRegister(): Expects a SymbolicExpression as first argument.");
751
752 if (reg == nullptr || (!PyRegister_Check(reg)))
753 return PyErr_Format(PyExc_TypeError, "TritonContext::assignSymbolicExpressionToRegister(): Expects a Register as second argument.");
754
757
758 try {
759 PyTritonContext_AsTritonContext(self)->assignSymbolicExpressionToRegister(arg1, arg2);
760 }
761 catch (const triton::exceptions::PyCallbacks&) {
762 return nullptr;
763 }
764 catch (const triton::exceptions::Exception& e) {
765 return PyErr_Format(PyExc_TypeError, "%s", e.what());
766 }
767
768 Py_INCREF(Py_None);
769 return Py_None;
770 }
771
772
773 static PyObject* TritonContext_buildSemantics(PyObject* self, PyObject* inst) {
774 if (!PyInstruction_Check(inst))
775 return PyErr_Format(PyExc_TypeError, "TritonContext::buildSemantics(): Expects an Instruction as argument.");
776
777 try {
779 }
780 catch (const triton::exceptions::PyCallbacks&) {
781 return nullptr;
782 }
783 catch (const triton::exceptions::Exception& e) {
784 return PyErr_Format(PyExc_TypeError, "%s", e.what());
785 }
786 }
787
788
789 static PyObject* TritonContext_clearCallbacks(PyObject* self, PyObject* noarg) {
790 try {
791 PyTritonContext_AsTritonContext(self)->clearCallbacks();
792 }
793 catch (const triton::exceptions::PyCallbacks&) {
794 return nullptr;
795 }
796 catch (const triton::exceptions::Exception& e) {
797 return PyErr_Format(PyExc_TypeError, "%s", e.what());
798 }
799
800 Py_INCREF(Py_None);
801 return Py_None;
802 }
803
804
805 static PyObject* TritonContext_clearModes(PyObject* self, PyObject* noarg) {
806 try {
807 PyTritonContext_AsTritonContext(self)->clearModes();
808 }
809 catch (const triton::exceptions::PyCallbacks&) {
810 return nullptr;
811 }
812 catch (const triton::exceptions::Exception& e) {
813 return PyErr_Format(PyExc_TypeError, "%s", e.what());
814 }
815
816 Py_INCREF(Py_None);
817 return Py_None;
818 }
819
820
821 static PyObject* TritonContext_clearConcreteMemoryValue(PyObject* self, PyObject* args) {
822 PyObject* baseAddr = nullptr;
823 PyObject* size = nullptr;
824
825 /* Extract arguments */
826 if (PyArg_ParseTuple(args, "|OO", &baseAddr, &size) == false) {
827 return PyErr_Format(PyExc_TypeError, "TritonContext::clearConcreteMemoryValue(): Invalid number of arguments");
828 }
829
830 try {
831 if (baseAddr && PyMemoryAccess_Check(baseAddr)) {
832 PyTritonContext_AsTritonContext(self)->clearConcreteMemoryValue(*PyMemoryAccess_AsMemoryAccess(baseAddr));
833 }
834 else if (baseAddr && (PyLong_Check(baseAddr) || PyInt_Check(baseAddr))) {
835 if (size && (PyLong_Check(size) || PyInt_Check(size))) {
836 PyTritonContext_AsTritonContext(self)->clearConcreteMemoryValue(PyLong_AsUint64(baseAddr), PyLong_AsUsize(size));
837 }
838 else {
839 return PyErr_Format(PyExc_TypeError, "TritonContext::clearConcreteMemoryValue(): Expects a size (integer) as second argument.");
840 }
841 }
842 else {
843 return PyErr_Format(PyExc_TypeError, "TritonContext::clearConcreteMemoryValue(): Expects a base address (integer) as arguments or a memory cells.");
844 }
845 }
846 catch (const triton::exceptions::PyCallbacks&) {
847 return nullptr;
848 }
849 catch (const triton::exceptions::Exception& e) {
850 return PyErr_Format(PyExc_TypeError, "%s", e.what());
851 }
852
853 Py_INCREF(Py_None);
854 return Py_None;
855 }
856
857
858 static PyObject* TritonContext_clearPathConstraints(PyObject* self, PyObject* noarg) {
859 try {
860 PyTritonContext_AsTritonContext(self)->clearPathConstraints();
861 }
862 catch (const triton::exceptions::Exception& e) {
863 return PyErr_Format(PyExc_TypeError, "%s", e.what());
864 }
865
866 Py_INCREF(Py_None);
867 return Py_None;
868 }
869
870
871 static PyObject* TritonContext_concretizeAllMemory(PyObject* self, PyObject* noarg) {
872 try {
873 PyTritonContext_AsTritonContext(self)->concretizeAllMemory();
874 }
875 catch (const triton::exceptions::PyCallbacks&) {
876 return nullptr;
877 }
878 catch (const triton::exceptions::Exception& e) {
879 return PyErr_Format(PyExc_TypeError, "%s", e.what());
880 }
881
882 Py_INCREF(Py_None);
883 return Py_None;
884 }
885
886
887 static PyObject* TritonContext_concretizeAllRegister(PyObject* self, PyObject* noarg) {
888 try {
889 PyTritonContext_AsTritonContext(self)->concretizeAllRegister();
890 }
891 catch (const triton::exceptions::PyCallbacks&) {
892 return nullptr;
893 }
894 catch (const triton::exceptions::Exception& e) {
895 return PyErr_Format(PyExc_TypeError, "%s", e.what());
896 }
897
898 Py_INCREF(Py_None);
899 return Py_None;
900 }
901
902
903 static PyObject* TritonContext_concretizeMemory(PyObject* self, PyObject* mem) {
904 /* If mem is an address */
905 if (PyLong_Check(mem) || PyInt_Check(mem)) {
906 try {
907 PyTritonContext_AsTritonContext(self)->concretizeMemory(PyLong_AsUint64(mem));
908 }
909 catch (const triton::exceptions::PyCallbacks&) {
910 return nullptr;
911 }
912 catch (const triton::exceptions::Exception& e) {
913 return PyErr_Format(PyExc_TypeError, "%s", e.what());
914 }
915 }
916
917 /* If mem is a MemoryAccess */
918 else if (PyMemoryAccess_Check(mem)) {
919 try {
921 }
922 catch (const triton::exceptions::PyCallbacks&) {
923 return nullptr;
924 }
925 catch (const triton::exceptions::Exception& e) {
926 return PyErr_Format(PyExc_TypeError, "%s", e.what());
927 }
928 }
929
930 /* Invalid parameter */
931 else
932 return PyErr_Format(PyExc_TypeError, "TritonContext::concretizeMemory(): Expects an integer or MemoryAccess as argument.");
933
934 Py_INCREF(Py_None);
935 return Py_None;
936 }
937
938
939 static PyObject* TritonContext_concretizeRegister(PyObject* self, PyObject* reg) {
940 if (!PyRegister_Check(reg))
941 return PyErr_Format(PyExc_TypeError, "TritonContext::concretizeRegister(): Expects a Register as argument.");
942
943 try {
944 PyTritonContext_AsTritonContext(self)->concretizeRegister(*PyRegister_AsRegister(reg));
945 }
946 catch (const triton::exceptions::PyCallbacks&) {
947 return nullptr;
948 }
949 catch (const triton::exceptions::Exception& e) {
950 return PyErr_Format(PyExc_TypeError, "%s", e.what());
951 }
952
953 Py_INCREF(Py_None);
954 return Py_None;
955 }
956
957
958 static PyObject* TritonContext_createSymbolicMemoryExpression(PyObject* self, PyObject* args) {
959 PyObject* inst = nullptr;
960 PyObject* node = nullptr;
961 PyObject* mem = nullptr;
962 PyObject* comment = nullptr;
963 std::string ccomment = "";
964
965 /* Extract arguments */
966 if (PyArg_ParseTuple(args, "|OOOO", &inst, &node, &mem, &comment) == false) {
967 return PyErr_Format(PyExc_TypeError, "TritonContext::createSymbolicMemoryExpression(): Invalid number of arguments");
968 }
969
970 if (inst == nullptr || (!PyInstruction_Check(inst)))
971 return PyErr_Format(PyExc_TypeError, "TritonContext::createSymbolicMemoryExpression(): Expects an Instruction as first argument.");
972
973 if (node == nullptr || (!PyAstNode_Check(node)))
974 return PyErr_Format(PyExc_TypeError, "TritonContext::createSymbolicMemoryExpression(): Expects a AstNode as second argument.");
975
976 if (mem == nullptr || (!PyMemoryAccess_Check(mem)))
977 return PyErr_Format(PyExc_TypeError, "TritonContext::createSymbolicMemoryExpression(): Expects a MemoryAccess as third argument.");
978
979 if (comment != nullptr && !PyStr_Check(comment))
980 return PyErr_Format(PyExc_TypeError, "TritonContext::createSymbolicMemoryExpression(): Expects a sting as fourth argument.");
981
982 if (comment != nullptr)
983 ccomment = PyStr_AsString(comment);
984
988
989 try {
990 return PySymbolicExpression(PyTritonContext_AsTritonContext(self)->createSymbolicMemoryExpression(arg1, arg2, arg3, ccomment));
991 }
992 catch (const triton::exceptions::PyCallbacks&) {
993 return nullptr;
994 }
995 catch (const triton::exceptions::Exception& e) {
996 return PyErr_Format(PyExc_TypeError, "%s", e.what());
997 }
998 }
999
1000
1001 static PyObject* TritonContext_createSymbolicRegisterExpression(PyObject* self, PyObject* args) {
1002 PyObject* inst = nullptr;
1003 PyObject* node = nullptr;
1004 PyObject* reg = nullptr;
1005 PyObject* comment = nullptr;
1006 std::string ccomment = "";
1007
1008 /* Extract arguments */
1009 if (PyArg_ParseTuple(args, "|OOOO", &inst, &node, &reg, &comment) == false) {
1010 return PyErr_Format(PyExc_TypeError, "TritonContext::createSymbolicRegisterExpression(): Invalid number of arguments");
1011 }
1012
1013 if (inst == nullptr || (!PyInstruction_Check(inst)))
1014 return PyErr_Format(PyExc_TypeError, "TritonContext::createSymbolicRegisterExpression(): Expects an Instruction as first argument.");
1015
1016 if (node == nullptr || (!PyAstNode_Check(node)))
1017 return PyErr_Format(PyExc_TypeError, "TritonContext::createSymbolicRegisterExpression(): Expects a AstNode as second argument.");
1018
1019 if (reg == nullptr || (!PyRegister_Check(reg)))
1020 return PyErr_Format(PyExc_TypeError, "TritonContext::createSymbolicRegisterExpression(): Expects a Register as third argument.");
1021
1022 if (comment != nullptr && !PyStr_Check(comment))
1023 return PyErr_Format(PyExc_TypeError, "TritonContext::createSymbolicRegisterExpression(): Expects a sting as fourth argument.");
1024
1025 if (comment != nullptr)
1026 ccomment = PyStr_AsString(comment);
1027
1031
1032 try {
1033 return PySymbolicExpression(PyTritonContext_AsTritonContext(self)->createSymbolicRegisterExpression(arg1, arg2, arg3, ccomment));
1034 }
1035 catch (const triton::exceptions::PyCallbacks&) {
1036 return nullptr;
1037 }
1038 catch (const triton::exceptions::Exception& e) {
1039 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1040 }
1041 }
1042
1043
1044 static PyObject* TritonContext_createSymbolicVolatileExpression(PyObject* self, PyObject* args) {
1045 PyObject* inst = nullptr;
1046 PyObject* node = nullptr;
1047 PyObject* comment = nullptr;
1048 std::string ccomment = "";
1049
1050 /* Extract arguments */
1051 if (PyArg_ParseTuple(args, "|OOO", &inst, &node, &comment) == false) {
1052 return PyErr_Format(PyExc_TypeError, "TritonContext::createSymbolicVolatileExpression(): Invalid number of arguments");
1053 }
1054
1055 if (inst == nullptr || (!PyInstruction_Check(inst)))
1056 return PyErr_Format(PyExc_TypeError, "TritonContext::createSymbolicVolatileExpression(): Expects an Instruction as first argument.");
1057
1058 if (node == nullptr || (!PyAstNode_Check(node)))
1059 return PyErr_Format(PyExc_TypeError, "TritonContext::createSymbolicVolatileExpression(): Expects a AstNode as second argument.");
1060
1061 if (comment != nullptr && !PyStr_Check(comment))
1062 return PyErr_Format(PyExc_TypeError, "TritonContext::createSymbolicVolatileExpression(): Expects a sting as third argument.");
1063
1064 if (comment != nullptr)
1065 ccomment = PyStr_AsString(comment);
1066
1069
1070 try {
1071 return PySymbolicExpression(PyTritonContext_AsTritonContext(self)->createSymbolicVolatileExpression(arg1, arg2, ccomment));
1072 }
1073 catch (const triton::exceptions::PyCallbacks&) {
1074 return nullptr;
1075 }
1076 catch (const triton::exceptions::Exception& e) {
1077 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1078 }
1079 }
1080
1081
1082 static PyObject* TritonContext_disassembly(PyObject* self, PyObject* args) {
1083 PyObject* arg0 = nullptr;
1084 PyObject* arg1 = nullptr;
1085 PyObject* ret = nullptr;
1086 triton::usize index = 0;
1087
1088 /* Extract arguments */
1089 if (PyArg_ParseTuple(args, "|OO", &arg0, &arg1) == false) {
1090 return PyErr_Format(PyExc_TypeError, "TritonContext::disassembly(): Invalid number of arguments.");
1091 }
1092
1093 try {
1094 if (arg0 != nullptr && PyInstruction_Check(arg0)) {
1096 Py_INCREF(Py_None);
1097 return Py_None;
1098 }
1099 if (arg0 != nullptr && PyBasicBlock_Check(arg0)) {
1100 triton::uint64 base = 0;
1101 if (arg1 != nullptr && (PyLong_Check(arg1) || PyInt_Check(arg1))) {
1102 base = PyLong_AsUint64(arg1);
1103 }
1104 PyTritonContext_AsTritonContext(self)->disassembly(*PyBasicBlock_AsBasicBlock(arg0), base);
1105 Py_INCREF(Py_None);
1106 return Py_None;
1107 }
1108 if ((arg0 != nullptr && (PyLong_Check(arg0) || PyInt_Check(arg0))) &&
1109 (arg1 == nullptr || PyLong_Check(arg1) || PyInt_Check(arg1))) {
1110
1111 std::vector<triton::arch::Instruction> insts;
1112 if (arg1) {
1113 insts = PyTritonContext_AsTritonContext(self)->disassembly(PyLong_AsUint64(arg0), PyLong_AsUsize(arg1));
1114 ret = xPyList_New(insts.size());
1115 for (auto& inst : insts)
1116 PyList_SetItem(ret, index++, PyInstruction(inst));
1117 }
1118 else {
1119 ret = PyBasicBlock(PyTritonContext_AsTritonContext(self)->disassembly(PyLong_AsUint64(arg0)));
1120 }
1121 return ret;
1122 }
1123 else {
1124 return PyErr_Format(PyExc_TypeError, "TritonContext::disassembly(): Expects an Instruction or two integers as arguments.");
1125 }
1126 }
1127 catch (const triton::exceptions::PyCallbacks&) {
1128 return nullptr;
1129 }
1130 catch (const triton::exceptions::Exception& e) {
1131 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1132 }
1133 }
1134
1135
1136 static PyObject* TritonContext_evaluateAstViaSolver(PyObject* self, PyObject* node) {
1137 if (!PyAstNode_Check(node))
1138 return PyErr_Format(PyExc_TypeError, "TritonContext::evaluateAstViaSolver(): Expects a AstNode as argument.");
1139
1140 try {
1141 return PyLong_FromUint512(PyTritonContext_AsTritonContext(self)->evaluateAstViaSolver(PyAstNode_AsAstNode(node)));
1142 }
1143 catch (const triton::exceptions::PyCallbacks&) {
1144 return nullptr;
1145 }
1146 catch (const triton::exceptions::Exception& e) {
1147 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1148 }
1149
1150 Py_INCREF(Py_None);
1151 return Py_None;
1152 }
1153
1154
1155 static PyObject* TritonContext_getAllRegisters(PyObject* self, PyObject* noarg) {
1156 PyObject* ret = nullptr;
1157
1158 try {
1159 triton::uint32 index = 0;
1160 auto& regs = PyTritonContext_AsTritonContext(self)->getAllRegisters();
1161
1162 ret = xPyList_New(regs.size());
1163 for (auto& reg: regs)
1164 PyList_SetItem(ret, index++, PyRegister(reg.second));
1165 }
1166 catch (const triton::exceptions::PyCallbacks&) {
1167 return nullptr;
1168 }
1169 catch (const triton::exceptions::Exception& e) {
1170 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1171 }
1172
1173 return ret;
1174 }
1175
1176
1177 static PyObject* TritonContext_getArchitecture(PyObject* self, PyObject* noarg) {
1178 try {
1179 return PyLong_FromUint32(PyTritonContext_AsTritonContext(self)->getArchitecture());
1180 }
1181 catch (const triton::exceptions::PyCallbacks&) {
1182 return nullptr;
1183 }
1184 catch (const triton::exceptions::Exception& e) {
1185 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1186 }
1187 }
1188
1189
1190 static PyObject* TritonContext_getAstContext(PyObject* self, PyObject* noarg) {
1191 try {
1192 return PyAstContext(PyTritonContext_AsTritonContext(self)->getAstContext());
1193 }
1194 catch (const triton::exceptions::PyCallbacks&) {
1195 return nullptr;
1196 }
1197 catch (const triton::exceptions::Exception& e) {
1198 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1199 }
1200 }
1201
1202
1203 static PyObject* TritonContext_getAstRepresentationMode(PyObject* self, PyObject* noarg) {
1204 try {
1205 return PyLong_FromUint32(PyTritonContext_AsTritonContext(self)->getAstRepresentationMode());
1206 }
1207 catch (const triton::exceptions::PyCallbacks&) {
1208 return nullptr;
1209 }
1210 catch (const triton::exceptions::Exception& e) {
1211 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1212 }
1213 }
1214
1215
1216 static PyObject* TritonContext_getConcreteMemoryAreaValue(PyObject* self, PyObject* args, PyObject* kwargs) {
1217 triton::uint8* area = nullptr;
1218 PyObject* ret = nullptr;
1219 PyObject* addr = nullptr;
1220 PyObject* size = nullptr;
1221 PyObject* execCallbacks = nullptr;
1222
1223 static char* keywords[] = {
1224 (char*)"addr",
1225 (char*)"size",
1226 (char*)"callbacks",
1227 nullptr
1228 };
1229
1230 /* Extract keywords */
1231 if (PyArg_ParseTupleAndKeywords(args, kwargs, "OO|O", keywords, &addr, &size, &execCallbacks) == false) {
1232 return PyErr_Format(PyExc_TypeError, "TritonContext::getConcreteMemoryAreaValue(): Invalid keyword argument");
1233 }
1234
1235 if (addr == nullptr || (!PyLong_Check(addr) && !PyInt_Check(addr))) {
1236 return PyErr_Format(PyExc_TypeError, "TritonContext::getConcreteMemoryAreaValue(): Expects an integer as addr keyword.");
1237 }
1238
1239 if (size == nullptr || (!PyLong_Check(size) && !PyInt_Check(size))) {
1240 return PyErr_Format(PyExc_TypeError, "TritonContext::getConcreteMemoryAreaValue(): Expects an integer as size keyword.");
1241 }
1242
1243 if (execCallbacks != nullptr && !PyBool_Check(execCallbacks)) {
1244 return PyErr_Format(PyExc_TypeError, "TritonContext::getConcreteMemoryAreaValue(): Expects a boolean as execCallbacks keyword.");
1245 }
1246
1247 if (execCallbacks == nullptr) {
1248 execCallbacks = PyLong_FromUint32(true);
1249 }
1250
1251 try {
1252 std::vector<triton::uint8> vv = PyTritonContext_AsTritonContext(self)->getConcreteMemoryAreaValue(PyLong_AsUint64(addr), PyLong_AsUsize(size), PyLong_AsBool(execCallbacks));
1253 area = new triton::uint8[vv.size()];
1254
1255 for (triton::usize index = 0; index < vv.size(); index++)
1256 area[index] = vv[index];
1257
1258 ret = PyBytes_FromStringAndSize(reinterpret_cast<const char*>(area), vv.size());
1259 delete[] area;
1260 return ret;
1261
1262 }
1263 catch (const triton::exceptions::PyCallbacks&) {
1264 return nullptr;
1265 }
1266 catch (const triton::exceptions::Exception& e) {
1267 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1268 }
1269
1270 return ret;
1271 }
1272
1273
1274 static PyObject* TritonContext_getConcreteMemoryValue(PyObject* self, PyObject* args, PyObject* kwargs) {
1275 PyObject* mem = nullptr;
1276 PyObject* execCallbacks = nullptr;
1277
1278 static char* keywords[] = {
1279 (char*)"mem",
1280 (char*)"callbacks",
1281 nullptr
1282 };
1283
1284 /* Extract keywords */
1285 if (PyArg_ParseTupleAndKeywords(args, kwargs, "O|O", keywords, &mem, &execCallbacks) == false) {
1286 return PyErr_Format(PyExc_TypeError, "TritonContext::getConcreteMemoryValue(): Invalid keyword argument");
1287 }
1288
1289 if (mem == nullptr || (!PyLong_Check(mem) && !PyInt_Check(mem) && !PyMemoryAccess_Check(mem))) {
1290 return PyErr_Format(PyExc_TypeError, "TritonContext::getConcreteMemoryValue(): Expects a MemoryAccess or an integer as mem keyword.");
1291 }
1292
1293 if (execCallbacks != nullptr && !PyBool_Check(execCallbacks)) {
1294 return PyErr_Format(PyExc_TypeError, "TritonContext::getConcreteMemoryValue(): Expects a boolean as execCallbacks keyword.");
1295 }
1296
1297 if (execCallbacks == nullptr) {
1298 execCallbacks = PyLong_FromUint32(true);
1299 }
1300
1301 try {
1302 if (PyLong_Check(mem) || PyInt_Check(mem))
1303 return PyLong_FromUint512(PyTritonContext_AsTritonContext(self)->getConcreteMemoryValue(PyLong_AsUint64(mem), PyLong_AsBool(execCallbacks)));
1304 else if (PyMemoryAccess_Check(mem))
1305 return PyLong_FromUint512(PyTritonContext_AsTritonContext(self)->getConcreteMemoryValue(*PyMemoryAccess_AsMemoryAccess(mem), PyLong_AsBool(execCallbacks)));
1306 else
1307 return PyErr_Format(PyExc_TypeError, "TritonContext::getConcreteMemoryValue(): Something wrong.");
1308 }
1309 catch (const triton::exceptions::PyCallbacks&) {
1310 return nullptr;
1311 }
1312 catch (const triton::exceptions::Exception& e) {
1313 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1314 }
1315 }
1316
1317
1318 static PyObject* TritonContext_getConcreteRegisterValue(PyObject* self, PyObject* args, PyObject* kwargs) {
1319 PyObject* reg = nullptr;
1320 PyObject* execCallbacks = nullptr;
1321
1322 static char* keywords[] = {
1323 (char*)"reg",
1324 (char*)"callbacks",
1325 nullptr
1326 };
1327
1328 /* Extract keywords */
1329 if (PyArg_ParseTupleAndKeywords(args, kwargs, "O|O", keywords, &reg, &execCallbacks) == false) {
1330 return PyErr_Format(PyExc_TypeError, "TritonContext::getConcreteRegisterValue(): Invalid keyword argument");
1331 }
1332
1333 if (reg == nullptr || !PyRegister_Check(reg)) {
1334 return PyErr_Format(PyExc_TypeError, "TritonContext::getConcreteRegisterValue(): Expects a Register as reg keyword.");
1335 }
1336
1337 if (execCallbacks != nullptr && !PyBool_Check(execCallbacks)) {
1338 return PyErr_Format(PyExc_TypeError, "TritonContext::getConcreteRegisterValue(): Expects a boolean as execCallbacks keyword.");
1339 }
1340
1341 if (execCallbacks == nullptr) {
1342 execCallbacks = PyLong_FromUint32(true);
1343 }
1344
1345 try {
1346 return PyLong_FromUint512(PyTritonContext_AsTritonContext(self)->getConcreteRegisterValue(*PyRegister_AsRegister(reg), PyLong_AsBool(execCallbacks)));
1347 }
1348 catch (const triton::exceptions::PyCallbacks&) {
1349 return nullptr;
1350 }
1351 catch (const triton::exceptions::Exception& e) {
1352 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1353 }
1354 }
1355
1356
1357 static PyObject* TritonContext_getConcreteVariableValue(PyObject* self, PyObject* symVar) {
1358 if (!PySymbolicVariable_Check(symVar))
1359 return PyErr_Format(PyExc_TypeError, "TritonContext::getConcreteVariableValue(): Expects a SymbolicVariable as argument.");
1360
1361 try {
1362 return PyLong_FromUint512(PyTritonContext_AsTritonContext(self)->getConcreteVariableValue(PySymbolicVariable_AsSymbolicVariable(symVar)));
1363 }
1364 catch (const triton::exceptions::PyCallbacks&) {
1365 return nullptr;
1366 }
1367 catch (const triton::exceptions::Exception& e) {
1368 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1369 }
1370 }
1371
1372
1373 static PyObject* TritonContext_getGprBitSize(PyObject* self, PyObject* noarg) {
1374 try {
1375 return PyLong_FromUint32(PyTritonContext_AsTritonContext(self)->getGprBitSize());
1376 }
1377 catch (const triton::exceptions::PyCallbacks&) {
1378 return nullptr;
1379 }
1380 catch (const triton::exceptions::Exception& e) {
1381 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1382 }
1383 }
1384
1385
1386 static PyObject* TritonContext_getGprSize(PyObject* self, PyObject* noarg) {
1387 try {
1388 return PyLong_FromUint32(PyTritonContext_AsTritonContext(self)->getGprSize());
1389 }
1390 catch (const triton::exceptions::PyCallbacks&) {
1391 return nullptr;
1392 }
1393 catch (const triton::exceptions::Exception& e) {
1394 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1395 }
1396 }
1397
1398
1399 static PyObject* TritonContext_getImmediateAst(PyObject* self, PyObject* imm) {
1400 if (!PyImmediate_Check(imm))
1401 return PyErr_Format(PyExc_TypeError, "TritonContext::getImmediateAst(): Expects an Immediate as argument.");
1402
1403 try {
1404 return PyAstNode(PyTritonContext_AsTritonContext(self)->getImmediateAst(*PyImmediate_AsImmediate(imm)));
1405 }
1406 catch (const triton::exceptions::PyCallbacks&) {
1407 return nullptr;
1408 }
1409 catch (const triton::exceptions::Exception& e) {
1410 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1411 }
1412 }
1413
1414
1415 static PyObject* TritonContext_getMemoryAst(PyObject* self, PyObject* mem) {
1416 if (!PyMemoryAccess_Check(mem))
1417 return PyErr_Format(PyExc_TypeError, "TritonContext::getMemoryAst(): Expects an MemoryAccess as argument.");
1418
1419 try {
1421 }
1422 catch (const triton::exceptions::PyCallbacks&) {
1423 return nullptr;
1424 }
1425 catch (const triton::exceptions::Exception& e) {
1426 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1427 }
1428 }
1429
1430
1431 static PyObject* TritonContext_getModel(PyObject* self, PyObject* args, PyObject* kwargs) {
1433 triton::uint32 solvingTime = 0;
1434 triton::uint32 timeout_c = 0;
1435
1436 PyObject* dict = nullptr;
1437 PyObject* node = nullptr;
1438 PyObject* wb = nullptr;
1439 PyObject* timeout = nullptr;
1440
1441 static char* keywords[] = {
1442 (char*)"node",
1443 (char*)"status",
1444 (char*)"timeout",
1445 nullptr
1446 };
1447
1448 /* Extract Keywords */
1449 if (PyArg_ParseTupleAndKeywords(args, kwargs, "|OOO", keywords, &node, &wb, &timeout) == false) {
1450 return PyErr_Format(PyExc_TypeError, "TritonContext::getModel(): Invalid keyword argument.");
1451 }
1452
1453 if (node == nullptr || !PyAstNode_Check(node)) {
1454 return PyErr_Format(PyExc_TypeError, "TritonContext::getModel(): Expects a AstNode as node argument.");
1455 }
1456
1457 if (wb != nullptr && !PyBool_Check(wb)) {
1458 return PyErr_Format(PyExc_TypeError, "TritonContext::getModel(): Expects a boolean as status keyword.");
1459 }
1460
1461 if (timeout != nullptr && (!PyLong_Check(timeout) && !PyInt_Check(timeout))) {
1462 return PyErr_Format(PyExc_TypeError, "TritonContext::getModel(): Expects a integer as timeout keyword.");
1463 }
1464
1465 if (timeout != nullptr) {
1466 timeout_c = PyLong_AsUint32(timeout);
1467 }
1468
1469 try {
1471 auto model = PyTritonContext_AsTritonContext(self)->getModel(PyAstNode_AsAstNode(node), &status, timeout_c, &solvingTime);
1472 for (auto it = model.begin(); it != model.end(); it++) {
1473 xPyDict_SetItem(dict, PyLong_FromUsize(it->first), PySolverModel(it->second));
1474 }
1475 }
1476 catch (const triton::exceptions::PyCallbacks&) {
1477 return nullptr;
1478 }
1479 catch (const triton::exceptions::Exception& e) {
1480 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1481 }
1482
1483 if (wb != nullptr && PyLong_AsBool(wb) == true) {
1484 PyObject* tuple = triton::bindings::python::xPyTuple_New(3);
1485 PyTuple_SetItem(tuple, 0, dict);
1486 PyTuple_SetItem(tuple, 1, PyLong_FromUint32(status));
1487 PyTuple_SetItem(tuple, 2, PyLong_FromUint32(solvingTime));
1488 return tuple;
1489 }
1490
1491 return dict;
1492 }
1493
1494
1495 static PyObject* TritonContext_getModels(PyObject* self, PyObject* args, PyObject* kwargs) {
1497 triton::uint32 solvingTime = 0;
1498 triton::uint32 timeout_c = 0;
1499
1500 PyObject* ret = nullptr;
1501 PyObject* node = nullptr;
1502 PyObject* limit = nullptr;
1503 PyObject* wb = nullptr;
1504 PyObject* timeout = nullptr;
1505
1506 static char* keywords[] = {
1507 (char*)"node",
1508 (char*)"limit",
1509 (char*)"status",
1510 (char*)"timeout",
1511 nullptr
1512 };
1513
1514 /* Extract Keywords */
1515 if (PyArg_ParseTupleAndKeywords(args, kwargs, "|OOOO", keywords, &node, &limit, &wb, &timeout) == false) {
1516 return PyErr_Format(PyExc_TypeError, "TritonContext::getModels(): Invalid keyword argument.");
1517 }
1518
1519 if (node == nullptr || !PyAstNode_Check(node)) {
1520 return PyErr_Format(PyExc_TypeError, "TritonContext::getModels(): Expects a AstNode as node argument.");
1521 }
1522
1523 if (limit == nullptr || (!PyLong_Check(limit) && !PyInt_Check(limit))) {
1524 return PyErr_Format(PyExc_TypeError, "TritonContext::getModels(): Expects an integer as limit argument.");
1525 }
1526
1527 if (wb != nullptr && !PyBool_Check(wb)) {
1528 return PyErr_Format(PyExc_TypeError, "TritonContext::getModels(): Expects a boolean as status keyword.");
1529 }
1530
1531 if (timeout != nullptr && (!PyLong_Check(timeout) && !PyInt_Check(timeout))) {
1532 return PyErr_Format(PyExc_TypeError, "TritonContext::getModels(): Expects a integer as timeout keyword.");
1533 }
1534
1535 if (timeout != nullptr) {
1536 timeout_c = PyLong_AsUint32(timeout);
1537 }
1538
1539 try {
1540 auto models = PyTritonContext_AsTritonContext(self)->getModels(PyAstNode_AsAstNode(node), PyLong_AsUint32(limit), &status, timeout_c, &solvingTime);
1541 triton::uint32 index = 0;
1542
1543 ret = xPyList_New(models.size());
1544 for (auto it = models.begin(); it != models.end(); it++) {
1545 PyObject* mdict = xPyDict_New();
1546 auto model = *it;
1547
1548 for (auto it2 = model.begin(); it2 != model.end(); it2++) {
1549 xPyDict_SetItem(mdict, PyLong_FromUsize(it2->first), PySolverModel(it2->second));
1550 }
1551 if (model.size() > 0)
1552 PyList_SetItem(ret, index++, mdict);
1553 }
1554 }
1555 catch (const triton::exceptions::PyCallbacks&) {
1556 return nullptr;
1557 }
1558 catch (const triton::exceptions::Exception& e) {
1559 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1560 }
1561
1562 if (wb != nullptr && PyLong_AsBool(wb) == true) {
1563 PyObject* tuple = triton::bindings::python::xPyTuple_New(3);
1564 PyTuple_SetItem(tuple, 0, ret);
1565 PyTuple_SetItem(tuple, 1, PyLong_FromUint32(status));
1566 PyTuple_SetItem(tuple, 2, PyLong_FromUint32(solvingTime));
1567 return tuple;
1568 }
1569
1570 return ret;
1571 }
1572
1573
1574 static PyObject* TritonContext_getParentRegisters(PyObject* self, PyObject* noarg) {
1575 PyObject* ret = nullptr;
1576
1577 try {
1578 triton::uint32 index = 0;
1579 auto regs = PyTritonContext_AsTritonContext(self)->getParentRegisters();
1580
1581 ret = xPyList_New(regs.size());
1582 for (const auto* reg: regs) {
1583 PyList_SetItem(ret, index++, PyRegister(*reg));
1584 }
1585 }
1586 catch (const triton::exceptions::PyCallbacks&) {
1587 return nullptr;
1588 }
1589 catch (const triton::exceptions::Exception& e) {
1590 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1591 }
1592
1593 return ret;
1594 }
1595
1596
1597 static PyObject* TritonContext_getPathConstraints(PyObject* self, PyObject* noarg) {
1598 PyObject* ret = nullptr;
1599
1600 try {
1601 triton::uint32 index = 0;
1602 const auto& pc = PyTritonContext_AsTritonContext(self)->getPathConstraints();
1603
1604 ret = xPyList_New(pc.size());
1605 for (auto it = pc.begin(); it != pc.end(); it++) {
1606 PyList_SetItem(ret, index++, PyPathConstraint(*it));
1607 }
1608 }
1609 catch (const triton::exceptions::PyCallbacks&) {
1610 return nullptr;
1611 }
1612 catch (const triton::exceptions::Exception& e) {
1613 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1614 }
1615
1616 return ret;
1617 }
1618
1619
1620 static PyObject* TritonContext_getPathPredicate(PyObject* self, PyObject* noarg) {
1621 try {
1622 return PyAstNode(PyTritonContext_AsTritonContext(self)->getPathPredicate());
1623 }
1624 catch (const triton::exceptions::PyCallbacks&) {
1625 return nullptr;
1626 }
1627 catch (const triton::exceptions::Exception& e) {
1628 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1629 }
1630 }
1631
1632
1633 static PyObject* TritonContext_getPathPredicateSize(PyObject* self, PyObject* noarg) {
1634 try {
1635 const auto& pc = PyTritonContext_AsTritonContext(self)->getPathConstraints();
1636 return PyLong_FromUsize(pc.size());
1637 }
1638 catch (const triton::exceptions::PyCallbacks&) {
1639 return nullptr;
1640 }
1641 catch (const triton::exceptions::Exception& e) {
1642 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1643 }
1644 }
1645
1646
1647 static PyObject* TritonContext_getPredicatesToReachAddress(PyObject* self, PyObject* addr) {
1648 PyObject* ret = nullptr;
1649
1650 if (addr == nullptr || (!PyLong_Check(addr) && !PyInt_Check(addr)))
1651 return PyErr_Format(PyExc_TypeError, "TritonContext::getPredicatesToReachAddress(): Expects an address as argument.");
1652
1653 try {
1654 triton::uint32 index = 0;
1655 auto preds = PyTritonContext_AsTritonContext(self)->getPredicatesToReachAddress(PyLong_AsUint64(addr));
1656
1657 ret = xPyList_New(preds.size());
1658 for (auto it = preds.begin(); it != preds.end(); it++) {
1659 PyList_SetItem(ret, index++, PyAstNode(*it));
1660 }
1661 }
1662 catch (const triton::exceptions::PyCallbacks&) {
1663 return nullptr;
1664 }
1665 catch (const triton::exceptions::Exception& e) {
1666 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1667 }
1668
1669 return ret;
1670 }
1671
1672
1673 static PyObject* TritonContext_getRegister(PyObject* self, PyObject* regIn) {
1674 try {
1675 if (regIn != nullptr && (PyLong_Check(regIn) || PyInt_Check(regIn))) {
1677 triton::arch::Register regOut(PyTritonContext_AsTritonContext(self)->getRegister(rid));
1678 return PyRegister(regOut);
1679 }
1680
1681 else if (regIn != nullptr && (PyStr_Check(regIn))) {
1682 std::string name = std::string(PyStr_AsString(regIn));
1683 triton::arch::Register regOut(PyTritonContext_AsTritonContext(self)->getRegister(name));
1684 return PyRegister(regOut);
1685 }
1686
1687 else {
1688 return PyErr_Format(PyExc_TypeError, "TritonContext::getRegister(): Expects an integer or a string as argument.");
1689 }
1690 }
1691 catch (const triton::exceptions::PyCallbacks&) {
1692 return nullptr;
1693 }
1694 catch (const triton::exceptions::Exception& e) {
1695 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1696 }
1697 }
1698
1699
1700 static PyObject* TritonContext_getRegisterAst(PyObject* self, PyObject* reg) {
1701 if (!PyRegister_Check(reg))
1702 return PyErr_Format(PyExc_TypeError, "TritonContext::getRegisterAst(): Expects an Register as argument.");
1703
1704 try {
1705 return PyAstNode(PyTritonContext_AsTritonContext(self)->getRegisterAst(*PyRegister_AsRegister(reg)));
1706 }
1707 catch (const triton::exceptions::PyCallbacks&) {
1708 return nullptr;
1709 }
1710 catch (const triton::exceptions::Exception& e) {
1711 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1712 }
1713 }
1714
1715
1716 static PyObject* TritonContext_getSolver(PyObject* self, PyObject* noarg) {
1717 try {
1718 return PyLong_FromUint32(PyTritonContext_AsTritonContext(self)->getSolver());
1719 }
1720 catch (const triton::exceptions::PyCallbacks&) {
1721 return nullptr;
1722 }
1723 catch (const triton::exceptions::Exception& e) {
1724 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1725 }
1726 }
1727
1728
1729 static PyObject* TritonContext_getSymbolicExpression(PyObject* self, PyObject* symExprId) {
1730 if (!PyLong_Check(symExprId) && !PyInt_Check(symExprId))
1731 return PyErr_Format(PyExc_TypeError, "TritonContext::getSymbolicExpression(): Expects an integer as argument.");
1732
1733 try {
1734 return PySymbolicExpression(PyTritonContext_AsTritonContext(self)->getSymbolicExpression(PyLong_AsUsize(symExprId)));
1735 }
1736 catch (const triton::exceptions::PyCallbacks&) {
1737 return nullptr;
1738 }
1739 catch (const triton::exceptions::Exception& e) {
1740 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1741 }
1742 }
1743
1744
1745 static PyObject* TritonContext_getSymbolicExpressions(PyObject* self, PyObject* noarg) {
1746 PyObject* ret = nullptr;
1747
1748 try {
1749 const auto& expressions = PyTritonContext_AsTritonContext(self)->getSymbolicExpressions();
1750
1751 ret = xPyDict_New();
1752 for (auto it = expressions.begin(); it != expressions.end(); it++)
1753 xPyDict_SetItem(ret, PyLong_FromUsize(it->first), PySymbolicExpression(it->second));
1754 }
1755 catch (const triton::exceptions::PyCallbacks&) {
1756 return nullptr;
1757 }
1758 catch (const triton::exceptions::Exception& e) {
1759 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1760 }
1761
1762 return ret;
1763 }
1764
1765
1766 static PyObject* TritonContext_getSymbolicMemory(PyObject* self, PyObject* args) {
1767 PyObject* ret = nullptr;
1768 PyObject* addr = nullptr;
1769
1770 /* Extract arguments */
1771 if (PyArg_ParseTuple(args, "|O", &addr) == false) {
1772 return PyErr_Format(PyExc_TypeError, "TritonContext::getSymbolicMemory(): Invalid number of arguments");
1773 }
1774
1775 try {
1776 if (addr == nullptr) {
1777 auto regs = PyTritonContext_AsTritonContext(self)->getSymbolicMemory();
1778
1779 ret = xPyDict_New();
1780 for (auto it = regs.begin(); it != regs.end(); it++) {
1781 xPyDict_SetItem(ret, PyLong_FromUint64(it->first), PySymbolicExpression(it->second));
1782 }
1783 }
1784 else if (addr != nullptr && (PyLong_Check(addr) || PyInt_Check(addr))) {
1785 ret = PySymbolicExpression(PyTritonContext_AsTritonContext(self)->getSymbolicMemory(PyLong_AsUint64(addr)));
1786 }
1787 else
1788 return PyErr_Format(PyExc_TypeError, "TritonContext::getSymbolicMemory(): Expects an integer or nothing as argument.");
1789 }
1790 catch (const triton::exceptions::PyCallbacks&) {
1791 return nullptr;
1792 }
1793 catch (const triton::exceptions::Exception& e) {
1794 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1795 }
1796
1797 return ret;
1798 }
1799
1800
1801 static PyObject* TritonContext_getSymbolicMemoryValue(PyObject* self, PyObject* mem) {
1802 if (!PyLong_Check(mem) && !PyInt_Check(mem) && !PyMemoryAccess_Check(mem))
1803 return PyErr_Format(PyExc_TypeError, "TritonContext::getSymbolicMemoryValue(): Expects an integer or a MemoryAccess as argument.");
1804
1805 try {
1806 if (PyLong_Check(mem) || PyInt_Check(mem))
1807 return PyLong_FromUint512(PyTritonContext_AsTritonContext(self)->getSymbolicMemoryValue(PyLong_AsUint64(mem)));
1808 return PyLong_FromUint512(PyTritonContext_AsTritonContext(self)->getSymbolicMemoryValue(*PyMemoryAccess_AsMemoryAccess(mem)));
1809 }
1810 catch (const triton::exceptions::PyCallbacks&) {
1811 return nullptr;
1812 }
1813 catch (const triton::exceptions::Exception& e) {
1814 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1815 }
1816 }
1817
1818
1819 static PyObject* TritonContext_getSymbolicRegisters(PyObject* self, PyObject* noarg) {
1820 PyObject* ret = nullptr;
1821
1822 try {
1823 auto regs = PyTritonContext_AsTritonContext(self)->getSymbolicRegisters();
1824
1825 ret = xPyDict_New();
1826 for (auto it = regs.begin(); it != regs.end(); it++) {
1827 xPyDict_SetItem(ret, PyLong_FromUint64(it->first), PySymbolicExpression(it->second));
1828 }
1829 }
1830 catch (const triton::exceptions::PyCallbacks&) {
1831 return nullptr;
1832 }
1833 catch (const triton::exceptions::Exception& e) {
1834 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1835 }
1836
1837 return ret;
1838 }
1839
1840
1841 static PyObject* TritonContext_getSymbolicRegister(PyObject* self, PyObject* reg) {
1842 if (!PyRegister_Check(reg))
1843 return PyErr_Format(PyExc_TypeError, "TritonContext::getSymbolicRegister(): Expects a Register as argument.");
1844
1845 try {
1846 return PySymbolicExpression(PyTritonContext_AsTritonContext(self)->getSymbolicRegister(*PyRegister_AsRegister(reg)));
1847 }
1848 catch (const triton::exceptions::PyCallbacks&) {
1849 return nullptr;
1850 }
1851 catch (const triton::exceptions::Exception& e) {
1852 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1853 }
1854 }
1855
1856
1857 static PyObject* TritonContext_getSymbolicRegisterValue(PyObject* self, PyObject* reg) {
1858 if (!PyRegister_Check(reg))
1859 return PyErr_Format(PyExc_TypeError, "TritonContext::getSymbolicRegisterValue(): Expects a Register as argument.");
1860
1861 try {
1862 return PyLong_FromUint512(PyTritonContext_AsTritonContext(self)->getSymbolicRegisterValue(*PyRegister_AsRegister(reg)));
1863 }
1864 catch (const triton::exceptions::PyCallbacks&) {
1865 return nullptr;
1866 }
1867 catch (const triton::exceptions::Exception& e) {
1868 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1869 }
1870 }
1871
1872
1873 static PyObject* TritonContext_getSymbolicVariable(PyObject* self, PyObject* arg) {
1874 try {
1875 if (PyLong_Check(arg) || PyInt_Check(arg))
1876 return PySymbolicVariable(PyTritonContext_AsTritonContext(self)->getSymbolicVariable(PyLong_AsUsize(arg)));
1877
1878 else if (PyStr_Check(arg))
1879 return PySymbolicVariable(PyTritonContext_AsTritonContext(self)->getSymbolicVariable(PyStr_AsString(arg)));
1880
1881 else
1882 return PyErr_Format(PyExc_TypeError, "TritonContext::getSymbolicVariable(): Expects an integer or a string as argument.");
1883 }
1884 catch (const triton::exceptions::PyCallbacks&) {
1885 return nullptr;
1886 }
1887 catch (const triton::exceptions::Exception& e) {
1888 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1889 }
1890 }
1891
1892
1893 static PyObject* TritonContext_getSymbolicVariables(PyObject* self, PyObject* noarg) {
1894 PyObject* ret = nullptr;
1895
1896 try {
1897 const auto& variables = PyTritonContext_AsTritonContext(self)->getSymbolicVariables();
1898
1899 ret = xPyDict_New();
1900 for (auto sv: variables)
1901 xPyDict_SetItem(ret, PyLong_FromUsize(sv.first), PySymbolicVariable(sv.second));
1902 }
1903 catch (const triton::exceptions::PyCallbacks&) {
1904 return nullptr;
1905 }
1906 catch (const triton::exceptions::Exception& e) {
1907 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1908 }
1909
1910 return ret;
1911 }
1912
1913
1914 static PyObject* TritonContext_getTaintedMemory(PyObject* self, PyObject* noarg) {
1915 PyObject* ret = nullptr;
1916 triton::usize size = 0, index = 0;
1917
1918 try {
1919 std::unordered_set<triton::uint64> addresses = PyTritonContext_AsTritonContext(self)->getTaintedMemory();
1920
1921 size = addresses.size();
1922 ret = xPyList_New(size);
1923 for (auto it = addresses.begin(); it != addresses.end(); it++) {
1924 PyList_SetItem(ret, index, PyLong_FromUint64(*it));
1925 index++;
1926 }
1927 }
1928 catch (const triton::exceptions::PyCallbacks&) {
1929 return nullptr;
1930 }
1931 catch (const triton::exceptions::Exception& e) {
1932 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1933 }
1934
1935 return ret;
1936 }
1937
1938
1939 static PyObject* TritonContext_getTaintedRegisters(PyObject* self, PyObject* noarg) {
1940 PyObject* ret = nullptr;
1941 triton::usize size = 0, index = 0;
1942
1943 try {
1944 std::unordered_set<const triton::arch::Register*> registers = PyTritonContext_AsTritonContext(self)->getTaintedRegisters();
1945
1946 size = registers.size();
1947 ret = xPyList_New(size);
1948 for (const auto* reg: registers) {
1949 PyList_SetItem(ret, index, PyRegister(*reg));
1950 index++;
1951 }
1952 }
1953 catch (const triton::exceptions::PyCallbacks&) {
1954 return nullptr;
1955 }
1956 catch (const triton::exceptions::Exception& e) {
1957 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1958 }
1959
1960 return ret;
1961 }
1962
1963
1964 static PyObject* TritonContext_getTaintedSymbolicExpressions(PyObject* self, PyObject* noarg) {
1965 PyObject* ret = nullptr;
1966 triton::usize size = 0, index = 0;
1967
1968 try {
1969 auto expressions = PyTritonContext_AsTritonContext(self)->getTaintedSymbolicExpressions();
1970
1971 size = expressions.size();
1972 ret = xPyList_New(size);
1973 for (auto it = expressions.begin(); it != expressions.end(); it++) {
1974 PyList_SetItem(ret, index, PySymbolicExpression(*it));
1975 index++;
1976 }
1977 }
1978 catch (const triton::exceptions::PyCallbacks&) {
1979 return nullptr;
1980 }
1981 catch (const triton::exceptions::Exception& e) {
1982 return PyErr_Format(PyExc_TypeError, "%s", e.what());
1983 }
1984
1985 return ret;
1986 }
1987
1988
1989 static PyObject* TritonContext_isArchitectureValid(PyObject* self, PyObject* noarg) {
1990 try {
1991 if (PyTritonContext_AsTritonContext(self)->isArchitectureValid() == true)
1992 Py_RETURN_TRUE;
1993 Py_RETURN_FALSE;
1994 }
1995 catch (const triton::exceptions::PyCallbacks&) {
1996 return nullptr;
1997 }
1998 catch (const triton::exceptions::Exception& e) {
1999 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2000 }
2001 }
2002
2003
2004 static PyObject* TritonContext_isConcreteMemoryValueDefined(PyObject* self, PyObject* args) {
2005 PyObject* baseAddr = nullptr;
2006 PyObject* size = nullptr;
2007
2008 /* Extract arguments */
2009 if (PyArg_ParseTuple(args, "|OO", &baseAddr, &size) == false) {
2010 return PyErr_Format(PyExc_TypeError, "TritonContext::isConcreteMemoryValueDefined(): Invalid number of arguments");
2011 }
2012
2013 try {
2014 if (baseAddr && PyMemoryAccess_Check(baseAddr)) {
2015 if (PyTritonContext_AsTritonContext(self)->isConcreteMemoryValueDefined(*PyMemoryAccess_AsMemoryAccess(baseAddr)) == true)
2016 Py_RETURN_TRUE;
2017 Py_RETURN_FALSE;
2018 }
2019 else if (baseAddr && (PyLong_Check(baseAddr) || PyInt_Check(baseAddr))) {
2020 if (size && (PyLong_Check(size) || PyInt_Check(size))) {
2021 if (PyTritonContext_AsTritonContext(self)->isConcreteMemoryValueDefined(PyLong_AsUint64(baseAddr), PyLong_AsUsize(size)) == true)
2022 Py_RETURN_TRUE;
2023 Py_RETURN_FALSE;
2024 }
2025 else {
2026 return PyErr_Format(PyExc_TypeError, "TritonContext::isConcreteMemoryValueDefined(): Expects a size (integer) as second argument.");
2027 }
2028 }
2029 else {
2030 return PyErr_Format(PyExc_TypeError, "TritonContext::isConcreteMemoryValueDefined(): Expects a base address (integer) as arguments or a memory cells.");
2031 }
2032 }
2033 catch (const triton::exceptions::PyCallbacks&) {
2034 return nullptr;
2035 }
2036 catch (const triton::exceptions::Exception& e) {
2037 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2038 }
2039 }
2040
2041
2042 static PyObject* TritonContext_isFlag(PyObject* self, PyObject* reg) {
2043 if (!PyRegister_Check(reg))
2044 return PyErr_Format(PyExc_TypeError, "TritonContext::isFlag(): Expects a Register as argument.");
2045
2046 try {
2047 if (PyTritonContext_AsTritonContext(self)->isFlag(*PyRegister_AsRegister(reg)) == true)
2048 Py_RETURN_TRUE;
2049 Py_RETURN_FALSE;
2050 }
2051 catch (const triton::exceptions::PyCallbacks&) {
2052 return nullptr;
2053 }
2054 catch (const triton::exceptions::Exception& e) {
2055 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2056 }
2057 }
2058
2059
2060 static PyObject* TritonContext_isMemorySymbolized(PyObject* self, PyObject* mem) {
2061 try {
2062 if (PyMemoryAccess_Check(mem)) {
2063 if (PyTritonContext_AsTritonContext(self)->isMemorySymbolized(*PyMemoryAccess_AsMemoryAccess(mem)) == true)
2064 Py_RETURN_TRUE;
2065 }
2066
2067 else if (PyLong_Check(mem) || PyInt_Check(mem)) {
2068 if (PyTritonContext_AsTritonContext(self)->isMemorySymbolized(PyLong_AsUint64(mem)) == true)
2069 Py_RETURN_TRUE;
2070 }
2071
2072 else
2073 return PyErr_Format(PyExc_TypeError, "TritonContext::isMemorySymbolized(): Expects a MemoryAccess or an integer as argument.");
2074 }
2075 catch (const triton::exceptions::PyCallbacks&) {
2076 return nullptr;
2077 }
2078 catch (const triton::exceptions::Exception& e) {
2079 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2080 }
2081
2082 Py_RETURN_FALSE;
2083 }
2084
2085
2086 static PyObject* TritonContext_isMemoryTainted(PyObject* self, PyObject* mem) {
2087 try {
2088 if (PyMemoryAccess_Check(mem)) {
2089 if (PyTritonContext_AsTritonContext(self)->isMemoryTainted(*PyMemoryAccess_AsMemoryAccess(mem)) == true)
2090 Py_RETURN_TRUE;
2091 }
2092
2093 else if (PyLong_Check(mem) || PyInt_Check(mem)) {
2094 if (PyTritonContext_AsTritonContext(self)->isMemoryTainted(PyLong_AsUint64(mem)) == true)
2095 Py_RETURN_TRUE;
2096 }
2097
2098 else
2099 return PyErr_Format(PyExc_TypeError, "TritonContext::isMemoryTainted(): Expects a MemoryAccess or an integer as argument.");
2100 }
2101 catch (const triton::exceptions::PyCallbacks&) {
2102 return nullptr;
2103 }
2104 catch (const triton::exceptions::Exception& e) {
2105 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2106 }
2107
2108 Py_RETURN_FALSE;
2109 }
2110
2111
2112 static PyObject* TritonContext_isRegister(PyObject* self, PyObject* reg) {
2113 if (!PyRegister_Check(reg))
2114 return PyErr_Format(PyExc_TypeError, "TritonContext::isRegister(): Expects a Register as argument.");
2115
2116 try {
2117 if (PyTritonContext_AsTritonContext(self)->isRegister(*PyRegister_AsRegister(reg)) == true)
2118 Py_RETURN_TRUE;
2119 Py_RETURN_FALSE;
2120 }
2121 catch (const triton::exceptions::PyCallbacks&) {
2122 return nullptr;
2123 }
2124 catch (const triton::exceptions::Exception& e) {
2125 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2126 }
2127 }
2128
2129
2130 static PyObject* TritonContext_isRegisterSymbolized(PyObject* self, PyObject* reg) {
2131 if (!PyRegister_Check(reg))
2132 return PyErr_Format(PyExc_TypeError, "TritonContext::isRegisterSymbolized(): Expects a Register as argument.");
2133
2134 try {
2135 if (PyTritonContext_AsTritonContext(self)->isRegisterSymbolized(*PyRegister_AsRegister(reg)) == true)
2136 Py_RETURN_TRUE;
2137 Py_RETURN_FALSE;
2138 }
2139 catch (const triton::exceptions::PyCallbacks&) {
2140 return nullptr;
2141 }
2142 catch (const triton::exceptions::Exception& e) {
2143 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2144 }
2145 }
2146
2147
2148 static PyObject* TritonContext_isRegisterTainted(PyObject* self, PyObject* reg) {
2149 if (!PyRegister_Check(reg))
2150 return PyErr_Format(PyExc_TypeError, "TritonContext::isRegisterTainted(): Expects a Register as argument.");
2151
2152 try {
2153 if (PyTritonContext_AsTritonContext(self)->isRegisterTainted(*PyRegister_AsRegister(reg)) == true)
2154 Py_RETURN_TRUE;
2155 Py_RETURN_FALSE;
2156 }
2157 catch (const triton::exceptions::PyCallbacks&) {
2158 return nullptr;
2159 }
2160 catch (const triton::exceptions::Exception& e) {
2161 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2162 }
2163 }
2164
2165
2166 static PyObject* TritonContext_isRegisterValid(PyObject* self, PyObject* reg) {
2167 if (!PyRegister_Check(reg))
2168 return PyErr_Format(PyExc_TypeError, "TritonContext::isRegisterValid(): Expects a Register as argument.");
2169
2170 try {
2171 if (PyTritonContext_AsTritonContext(self)->isRegisterValid(*PyRegister_AsRegister(reg)) == true)
2172 Py_RETURN_TRUE;
2173 Py_RETURN_FALSE;
2174 }
2175 catch (const triton::exceptions::PyCallbacks&) {
2176 return nullptr;
2177 }
2178 catch (const triton::exceptions::Exception& e) {
2179 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2180 }
2181 }
2182
2183
2184 static PyObject* TritonContext_isSat(PyObject* self, PyObject* node) {
2185 if (!PyAstNode_Check(node))
2186 return PyErr_Format(PyExc_TypeError, "TritonContext::isSat(): Expects a AstNode as argument.");
2187
2188 try {
2189 if (PyTritonContext_AsTritonContext(self)->isSat(PyAstNode_AsAstNode(node)) == true)
2190 Py_RETURN_TRUE;
2191 Py_RETURN_FALSE;
2192 }
2193 catch (const triton::exceptions::PyCallbacks&) {
2194 return nullptr;
2195 }
2196 catch (const triton::exceptions::Exception& e) {
2197 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2198 }
2199 }
2200
2201
2202 static PyObject* TritonContext_isSymbolicExpressionExists(PyObject* self, PyObject* symExprId) {
2203 if (!PyInt_Check(symExprId) && !PyLong_Check(symExprId))
2204 return PyErr_Format(PyExc_TypeError, "TritonContext::isSymbolicExpressionExists(): Expects an integer as argument.");
2205
2206 try {
2207 if (PyTritonContext_AsTritonContext(self)->isSymbolicExpressionExists(PyLong_AsUsize(symExprId)) == true)
2208 Py_RETURN_TRUE;
2209 Py_RETURN_FALSE;
2210 }
2211 catch (const triton::exceptions::PyCallbacks&) {
2212 return nullptr;
2213 }
2214 catch (const triton::exceptions::Exception& e) {
2215 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2216 }
2217 }
2218
2219
2220 static PyObject* TritonContext_isModeEnabled(PyObject* self, PyObject* mode) {
2221 if (!PyInt_Check(mode) && !PyLong_Check(mode))
2222 return PyErr_Format(PyExc_TypeError, "TritonContext::isModeEnabled(): Expects a MODE as argument.");
2223
2224 try {
2225 if (PyTritonContext_AsTritonContext(self)->isModeEnabled(static_cast<triton::modes::mode_e>(PyLong_AsUint32(mode))) == true)
2226 Py_RETURN_TRUE;
2227 Py_RETURN_FALSE;
2228 }
2229 catch (const triton::exceptions::PyCallbacks&) {
2230 return nullptr;
2231 }
2232 catch (const triton::exceptions::Exception& e) {
2233 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2234 }
2235 }
2236
2237
2238 static PyObject* TritonContext_isThumb(PyObject* self, PyObject* noarg) {
2239 try {
2240 if (PyTritonContext_AsTritonContext(self)->isThumb() == true)
2241 Py_RETURN_TRUE;
2242 Py_RETURN_FALSE;
2243 }
2244 catch (const triton::exceptions::PyCallbacks&) {
2245 return nullptr;
2246 }
2247 catch (const triton::exceptions::Exception& e) {
2248 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2249 }
2250 }
2251
2252
2253 static PyObject* TritonContext_liftToDot(PyObject* self, PyObject* node) {
2254 if (!PyAstNode_Check(node) && !PySymbolicExpression_Check(node))
2255 return PyErr_Format(PyExc_TypeError, "TritonContext::liftToDot(): Expects an AstNode or a SymbolicExpression as first argument.");
2256
2257 try {
2258 std::ostringstream stream;
2259
2260 if (PyAstNode_Check(node)) {
2261 PyTritonContext_AsTritonContext(self)->liftToDot(stream, PyAstNode_AsAstNode(node));
2262 }
2263 else {
2265 }
2266
2267 return xPyString_FromString(stream.str().c_str());
2268 }
2269 catch (const triton::exceptions::PyCallbacks&) {
2270 return nullptr;
2271 }
2272 catch (const triton::exceptions::Exception& e) {
2273 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2274 }
2275
2276 Py_INCREF(Py_None);
2277 return Py_None;
2278 }
2279
2280
2281 static PyObject* TritonContext_liftToLLVM(PyObject* self, PyObject* args, PyObject* kwargs) {
2282 PyObject* node = nullptr;
2283 PyObject* fname = nullptr;
2284 PyObject* optimize = nullptr;
2285
2286 static char* keywords[] = {
2287 (char*)"node",
2288 (char*)"fname",
2289 (char*)"optimize",
2290 nullptr
2291 };
2292
2293 /* Extract keywords */
2294 if (PyArg_ParseTupleAndKeywords(args, kwargs, "|OOO", keywords, &node, &fname, &optimize) == false) {
2295 return PyErr_Format(PyExc_TypeError, "TritonContext::liftToLLVM(): Invalid number of arguments");
2296 }
2297
2298 if (node == nullptr || (!PySymbolicExpression_Check(node) && !PyAstNode_Check(node)))
2299 return PyErr_Format(PyExc_TypeError, "TritonContext::liftToLLVM(): Expects a SymbolicExpression or a AstNode as node argument.");
2300
2301 if (fname != nullptr && !PyStr_Check(fname))
2302 return PyErr_Format(PyExc_TypeError, "TritonContext::liftToLLVM(): Expects a string as fname argument.");
2303
2304 if (optimize != nullptr && !PyBool_Check(optimize))
2305 return PyErr_Format(PyExc_TypeError, "TritonContext::liftToLLVM(): Expects a boolean as optimize argument.");
2306
2307 if (fname == nullptr)
2308 fname = PyStr_FromString("__triton");
2309
2310 if (optimize == nullptr)
2311 optimize = PyLong_FromUint32(false);
2312
2313 try {
2314 std::ostringstream stream;
2315 if (PySymbolicExpression_Check(node)) {
2316 PyTritonContext_AsTritonContext(self)->liftToLLVM(stream, PySymbolicExpression_AsSymbolicExpression(node), PyStr_AsString(fname), PyLong_AsBool(optimize));
2317 }
2318 else {
2319 PyTritonContext_AsTritonContext(self)->liftToLLVM(stream, PyAstNode_AsAstNode(node), PyStr_AsString(fname), PyLong_AsBool(optimize));
2320 }
2321 return xPyString_FromString(stream.str().c_str());
2322 }
2323 catch (const triton::exceptions::PyCallbacks&) {
2324 return nullptr;
2325 }
2326 catch (const triton::exceptions::Exception& e) {
2327 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2328 }
2329
2330 Py_INCREF(Py_None);
2331 return Py_None;
2332 }
2333
2334
2335 static PyObject* TritonContext_liftToPython(PyObject* self, PyObject* args, PyObject* kwargs) {
2336 PyObject* expr = nullptr;
2337 PyObject* icomment = nullptr;
2338
2339 static char* keywords[] = {
2340 (char*)"expr",
2341 (char*)"icomment",
2342 nullptr
2343 };
2344
2345 /* Extract keywords */
2346 if (PyArg_ParseTupleAndKeywords(args, kwargs, "|OO", keywords, &expr, &icomment) == false) {
2347 return PyErr_Format(PyExc_TypeError, "TritonContext::liftToPython(): Invalid number of arguments");
2348 }
2349
2350 if (expr == nullptr || !PySymbolicExpression_Check(expr))
2351 return PyErr_Format(PyExc_TypeError, "TritonContext::liftToPython(): Expects a SymbolicExpression as expr argument.");
2352
2353 if (icomment != nullptr && !PyBool_Check(icomment))
2354 return PyErr_Format(PyExc_TypeError, "TritonContext::liftToPython(): Expects a boolean as icomment argument.");
2355
2356 if (icomment == nullptr)
2357 icomment = PyLong_FromUint32(false);
2358
2359 try {
2360 std::ostringstream stream;
2362 return xPyString_FromString(stream.str().c_str());
2363 }
2364 catch (const triton::exceptions::PyCallbacks&) {
2365 return nullptr;
2366 }
2367 catch (const triton::exceptions::Exception& e) {
2368 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2369 }
2370
2371 Py_INCREF(Py_None);
2372 return Py_None;
2373 }
2374
2375
2376 static PyObject* TritonContext_liftToSMT(PyObject* self, PyObject* args, PyObject* kwargs) {
2377 PyObject* expr = nullptr;
2378 PyObject* assert = nullptr;
2379 PyObject* icomment = nullptr;
2380
2381 static char* keywords[] = {
2382 (char*)"expr",
2383 (char*)"assert_",
2384 (char*)"icomment",
2385 nullptr
2386 };
2387
2388 /* Extract keywords */
2389 if (PyArg_ParseTupleAndKeywords(args, kwargs, "|OO", keywords, &expr, &assert, &icomment) == false) {
2390 return PyErr_Format(PyExc_TypeError, "TritonContext::liftToSMT(): Invalid number of arguments");
2391 }
2392
2393 if (expr == nullptr || !PySymbolicExpression_Check(expr))
2394 return PyErr_Format(PyExc_TypeError, "TritonContext::liftToSMT(): Expects a SymbolicExpression as expr argument.");
2395
2396 if (assert != nullptr && !PyBool_Check(assert))
2397 return PyErr_Format(PyExc_TypeError, "TritonContext::liftToSMT(): Expects a boolean as assert_ argument.");
2398
2399 if (assert == nullptr)
2400 assert = PyLong_FromUint32(false);
2401
2402 if (icomment != nullptr && !PyBool_Check(icomment))
2403 return PyErr_Format(PyExc_TypeError, "TritonContext::liftToSMT(): Expects a boolean as icomment argument.");
2404
2405 if (icomment == nullptr)
2406 icomment = PyLong_FromUint32(false);
2407
2408 try {
2409 std::ostringstream stream;
2411 return xPyString_FromString(stream.str().c_str());
2412 }
2413 catch (const triton::exceptions::PyCallbacks&) {
2414 return nullptr;
2415 }
2416 catch (const triton::exceptions::Exception& e) {
2417 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2418 }
2419
2420 Py_INCREF(Py_None);
2421 return Py_None;
2422 }
2423
2424
2425 static PyObject* TritonContext_newSymbolicExpression(PyObject* self, PyObject* args) {
2426 PyObject* node = nullptr;
2427 PyObject* comment = nullptr;
2428 std::string ccomment = "";
2429
2430 /* Extract arguments */
2431 if (PyArg_ParseTuple(args, "|OO", &node, &comment) == false) {
2432 return PyErr_Format(PyExc_TypeError, "TritonContext::newSymbolicExpression(): Invalid number of arguments");
2433 }
2434
2435 if (node == nullptr || (!PyAstNode_Check(node)))
2436 return PyErr_Format(PyExc_TypeError, "TritonContext::newSymbolicExpression(): Expects a AstNode as first argument.");
2437
2438 if (comment != nullptr && !PyStr_Check(comment))
2439 return PyErr_Format(PyExc_TypeError, "TritonContext::newSymbolicExpression(): Expects a sting as second argument.");
2440
2441 if (comment != nullptr)
2442 ccomment = PyStr_AsString(comment);
2443
2444 try {
2445 return PySymbolicExpression(PyTritonContext_AsTritonContext(self)->newSymbolicExpression(PyAstNode_AsAstNode(node), ccomment));
2446 }
2447 catch (const triton::exceptions::PyCallbacks&) {
2448 return nullptr;
2449 }
2450 catch (const triton::exceptions::Exception& e) {
2451 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2452 }
2453 }
2454
2455
2456 static PyObject* TritonContext_newSymbolicVariable(PyObject* self, PyObject* args) {
2457 PyObject* size = nullptr;
2458 PyObject* alias = nullptr;
2459 std::string calias = "";
2460
2461 /* Extract arguments */
2462 if (PyArg_ParseTuple(args, "|OO", &size, &alias) == false) {
2463 return PyErr_Format(PyExc_TypeError, "TritonContext::newSymbolicVariable(): Invalid number of arguments");
2464 }
2465
2466 if (size == nullptr || (!PyLong_Check(size) && !PyInt_Check(size)))
2467 return PyErr_Format(PyExc_TypeError, "TritonContext::newSymbolicVariable(): Expects an integer as first argument.");
2468
2469 if (alias != nullptr && !PyStr_Check(alias))
2470 return PyErr_Format(PyExc_TypeError, "TritonContext::newSymbolicVariable(): Expects a sting as second argument.");
2471
2472 if (alias != nullptr)
2473 calias = PyStr_AsString(alias);
2474
2475 try {
2476 return PySymbolicVariable(PyTritonContext_AsTritonContext(self)->newSymbolicVariable(PyLong_AsUint32(size), calias));
2477 }
2478 catch (const triton::exceptions::PyCallbacks&) {
2479 return nullptr;
2480 }
2481 catch (const triton::exceptions::Exception& e) {
2482 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2483 }
2484 }
2485
2486
2487 static PyObject* TritonContext_popPathConstraint(PyObject* self, PyObject* noarg) {
2488 try {
2489 PyTritonContext_AsTritonContext(self)->popPathConstraint();
2490 }
2491 catch (const triton::exceptions::PyCallbacks&) {
2492 return nullptr;
2493 }
2494 catch (const triton::exceptions::Exception& e) {
2495 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2496 }
2497 Py_INCREF(Py_None);
2498 return Py_None;
2499 }
2500
2501
2502 static PyObject* TritonContext_processing(PyObject* self, PyObject* args) {
2503 PyObject* obj = nullptr;
2504 PyObject* addr = nullptr;
2505
2506 /* Extract arguments */
2507 if (PyArg_ParseTuple(args, "|OO", &obj, &addr) == false) {
2508 return PyErr_Format(PyExc_TypeError, "TritonContext::processing(): Invalid number of arguments");
2509 }
2510
2511 try {
2512 if (PyInstruction_Check(obj)) {
2514 }
2515 else if (PyBasicBlock_Check(obj)) {
2516 triton::uint64 base = 0;
2517 if (addr != nullptr && (PyLong_Check(addr) || PyInt_Check(addr))) {
2518 base = PyLong_AsUint64(addr);
2519 }
2521 }
2522 return PyErr_Format(PyExc_TypeError, "TritonContext::processing(): Expects an Instruction or a BasicBlock as argument.");
2523 }
2524 catch (const triton::exceptions::PyCallbacks&) {
2525 return nullptr;
2526 }
2527 catch (const triton::exceptions::Exception& e) {
2528 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2529 }
2530 }
2531
2532
2533 static PyObject* TritonContext_pushPathConstraint(PyObject* self, PyObject* args, PyObject* kwargs) {
2534 PyObject* node = nullptr;
2535 PyObject* comment = nullptr;
2536 std::string ccomment = "";
2537
2538 static char* keywords[] = {
2539 (char*)"node",
2540 (char*)"comment",
2541 nullptr
2542 };
2543
2544 /* Extract Keywords */
2545 if (PyArg_ParseTupleAndKeywords(args, kwargs, "|OO", keywords, &node, &comment) == false) {
2546 return PyErr_Format(PyExc_TypeError, "TritonContext::pushPathConstraint(): Invalid keyword argument.");
2547 }
2548
2549 if (node == nullptr || (!PyAstNode_Check(node)))
2550 return PyErr_Format(PyExc_TypeError, "TritonContext::pushPathConstraint(): Expects an AstNode as first argument.");
2551
2552 if (comment != nullptr && !PyStr_Check(comment))
2553 return PyErr_Format(PyExc_TypeError, "TritonContext::pushPathConstraint(): Expects a string as second argument.");
2554
2555 if (comment != nullptr)
2556 ccomment = PyStr_AsString(comment);
2557
2558 try {
2559 PyTritonContext_AsTritonContext(self)->pushPathConstraint(PyAstNode_AsAstNode(node), ccomment);
2560 }
2561 catch (const triton::exceptions::PyCallbacks&) {
2562 return nullptr;
2563 }
2564 catch (const triton::exceptions::Exception& e) {
2565 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2566 }
2567
2568 Py_INCREF(Py_None);
2569 return Py_None;
2570 }
2571
2572
2573 static PyObject* TritonContext_removeCallback(PyObject* self, PyObject* args) {
2574 PyObject* cb = nullptr;
2575 PyObject* cb_self = nullptr;
2576 PyObject* function = nullptr;
2577 PyObject* mode = nullptr;
2578
2579 /* Extract arguments */
2580 if (PyArg_ParseTuple(args, "|OO", &mode, &function) == false) {
2581 return PyErr_Format(PyExc_TypeError, "TritonContext::removeCallback(): Invalid number of arguments");
2582 }
2583
2584 if (mode == nullptr || (!PyLong_Check(mode) && !PyInt_Check(mode)))
2585 return PyErr_Format(PyExc_TypeError, "TritonContext::removeCallback(): Expects a CALLBACK as first argument.");
2586
2587 if (function == nullptr || !PyCallable_Check(function))
2588 return PyErr_Format(PyExc_TypeError, "TritonContext::removeCallback(): Expects a function as second argument.");
2589
2590 /* Get the callback (class or static) */
2591 if (PyMethod_Check(function)) {
2592 cb_self = PyMethod_GET_SELF(function);
2593 cb = PyMethod_GET_FUNCTION(function);
2594 }
2595 else {
2596 cb = function;
2597 }
2598
2599 try {
2600 switch (static_cast<triton::callbacks::callback_e>(PyLong_AsUint32(mode))) {
2603 break;
2606 break;
2609 break;
2612 break;
2615 break;
2616 default:
2617 return PyErr_Format(PyExc_TypeError, "TritonContext::removeCallback(): Invalid kind of callback.");
2618 }
2619 }
2620 catch (const triton::exceptions::PyCallbacks&) {
2621 return nullptr;
2622 }
2623 catch (const triton::exceptions::Exception& e) {
2624 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2625 }
2626
2627 Py_INCREF(Py_None);
2628 return Py_None;
2629 }
2630
2631
2632 static PyObject* TritonContext_reset(PyObject* self, PyObject* noarg) {
2633 try {
2634 PyTritonContext_AsTritonContext(self)->reset();
2635 }
2636 catch (const triton::exceptions::PyCallbacks&) {
2637 return nullptr;
2638 }
2639 catch (const triton::exceptions::Exception& e) {
2640 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2641 }
2642
2643 Py_INCREF(Py_None);
2644 return Py_None;
2645 }
2646
2647
2648 static PyObject* TritonContext_setArchitecture(PyObject* self, PyObject* arg) {
2649 if (!PyLong_Check(arg) && !PyInt_Check(arg))
2650 return PyErr_Format(PyExc_TypeError, "TritonContext::setArchitecture(): Expects an ARCH as argument.");
2651
2652 try {
2653 /* Set the architecture */
2654 PyTritonContext_AsTritonContext(self)->setArchitecture(static_cast<triton::arch::architecture_e>(PyLong_AsUint32(arg)));
2655 TritonContext_fillRegistersAttribute(self);
2656 }
2657 catch (const triton::exceptions::PyCallbacks&) {
2658 return nullptr;
2659 }
2660 catch (const triton::exceptions::Exception& e) {
2661 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2662 }
2663
2664 Py_INCREF(Py_None);
2665 return Py_None;
2666 }
2667
2668
2669 static PyObject* TritonContext_setAstRepresentationMode(PyObject* self, PyObject* arg) {
2670 if (!PyLong_Check(arg) && !PyInt_Check(arg))
2671 return PyErr_Format(PyExc_TypeError, "TritonContext::setAstRepresentationMode(): Expects an AST_REPRESENTATION as argument.");
2672
2673 try {
2674 PyTritonContext_AsTritonContext(self)->setAstRepresentationMode(static_cast<triton::ast::representations::mode_e>(PyLong_AsUint32(arg)));
2675 }
2676 catch (const triton::exceptions::PyCallbacks&) {
2677 return nullptr;
2678 }
2679 catch (const triton::exceptions::Exception& e) {
2680 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2681 }
2682
2683 Py_INCREF(Py_None);
2684 return Py_None;
2685 }
2686
2687
2688 static PyObject* TritonContext_setConcreteMemoryAreaValue(PyObject* self, PyObject* args, PyObject* kwargs) {
2689 std::vector<triton::uint8> vv;
2690 PyObject* baseAddr = nullptr;
2691 PyObject* values = nullptr;
2692 PyObject* execCallbacks = nullptr;
2693
2694 static char* keywords[] = {
2695 (char*)"addr",
2696 (char*)"values",
2697 (char*)"callbacks",
2698 nullptr
2699 };
2700
2701 /* Extract keywords */
2702 if (PyArg_ParseTupleAndKeywords(args, kwargs, "OO|O", keywords, &baseAddr, &values, &execCallbacks) == false) {
2703 return PyErr_Format(PyExc_TypeError, "TritonContext::setConcreteMemoryAreaValue(): Invalid keyword argument");
2704 }
2705
2706 if (baseAddr == nullptr || (!PyLong_Check(baseAddr) && !PyInt_Check(baseAddr))) {
2707 return PyErr_Format(PyExc_TypeError, "TritonContext::setConcreteMemoryAreaValue(): Expects an integer as baseAddr keyword.");
2708 }
2709
2710 if (values == nullptr || (!PyList_Check(values) && !PyBytes_Check(values) && !PyByteArray_Check(values))) {
2711 return PyErr_Format(PyExc_TypeError, "TritonContext::setConcreteMemoryAreaValue(): Expects a list or bytes as values keyword.");
2712 }
2713
2714 if (execCallbacks != nullptr && !PyBool_Check(execCallbacks)) {
2715 return PyErr_Format(PyExc_TypeError, "TritonContext::setConcreteMemoryAreaValue(): Expects a boolean as execCallbacks keyword.");
2716 }
2717
2718 if (execCallbacks == nullptr) {
2719 execCallbacks = PyLong_FromUint32(true);
2720 }
2721
2722 // Python object: List
2723 if (PyList_Check(values)) {
2724 for (Py_ssize_t i = 0; i < PyList_Size(values); i++) {
2725 PyObject* item = PyList_GetItem(values, i);
2726
2727 if ((!PyLong_Check(item) && !PyInt_Check(item)) || PyLong_AsUint32(item) > 0xff)
2728 return PyErr_Format(PyExc_TypeError, "TritonContext::setConcreteMemoryAreaValue(): Each item of the list must be a 8-bits integer.");
2729
2730 vv.push_back(static_cast<triton::uint8>(PyLong_AsUint32(item) & 0xff));
2731 }
2732
2733 try {
2734 PyTritonContext_AsTritonContext(self)->setConcreteMemoryAreaValue(PyLong_AsUint64(baseAddr), vv, PyLong_AsBool(execCallbacks));
2735 }
2736 catch (const triton::exceptions::PyCallbacks&) {
2737 return nullptr;
2738 }
2739 catch (const triton::exceptions::Exception& e) {
2740 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2741 }
2742 }
2743
2744 // Python object: Bytes
2745 else if (PyBytes_Check(values)) {
2746 triton::uint8* area = reinterpret_cast<triton::uint8*>(PyBytes_AsString(values));
2747 triton::usize size = static_cast<triton::usize>(PyBytes_Size(values));
2748
2749 try {
2750 PyTritonContext_AsTritonContext(self)->setConcreteMemoryAreaValue(PyLong_AsUint64(baseAddr), area, size, PyLong_AsBool(execCallbacks));
2751 }
2752 catch (const triton::exceptions::PyCallbacks&) {
2753 return nullptr;
2754 }
2755 catch (const triton::exceptions::Exception& e) {
2756 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2757 }
2758 }
2759
2760 // Python object: ByteArray
2761 else if (PyByteArray_Check(values)) {
2762 triton::uint8* area = reinterpret_cast<triton::uint8*>(PyByteArray_AsString(values));
2763 triton::usize size = static_cast<triton::usize>(PyByteArray_Size(values));
2764
2765 try {
2766 PyTritonContext_AsTritonContext(self)->setConcreteMemoryAreaValue(PyLong_AsUint64(baseAddr), area, size, PyLong_AsBool(execCallbacks));
2767 }
2768 catch (const triton::exceptions::PyCallbacks&) {
2769 return nullptr;
2770 }
2771 catch (const triton::exceptions::Exception& e) {
2772 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2773 }
2774 }
2775
2776 // Invalid Python object
2777 else
2778 return PyErr_Format(PyExc_TypeError, "TritonContext::setConcreteMemoryAreaValue(): Something wrong.");
2779
2780 Py_INCREF(Py_None);
2781 return Py_None;
2782 }
2783
2784
2785 static PyObject* TritonContext_setConcreteMemoryValue(PyObject* self, PyObject* args, PyObject* kwargs) {
2786 PyObject* mem = nullptr;
2787 PyObject* value = nullptr;
2788 PyObject* execCallbacks = nullptr;
2789
2790 static char* keywords[] = {
2791 (char*)"mem",
2792 (char*)"value",
2793 (char*)"callbacks",
2794 nullptr
2795 };
2796
2797 /* Extract keywords */
2798 if (PyArg_ParseTupleAndKeywords(args, kwargs, "OO|O", keywords, &mem, &value, &execCallbacks) == false) {
2799 return PyErr_Format(PyExc_TypeError, "TritonContext::setConcreteMemoryValue(): Invalid keyword argument");
2800 }
2801
2802 if (mem == nullptr || (!PyLong_Check(mem) && !PyInt_Check(mem) && !PyMemoryAccess_Check(mem))) {
2803 return PyErr_Format(PyExc_TypeError, "TritonContext::setConcreteMemoryValue(): Expects a MemoryAccess or an integer as mem keyword.");
2804 }
2805
2806 if (value == nullptr || (!PyLong_Check(value) && !PyInt_Check(value))) {
2807 return PyErr_Format(PyExc_TypeError, "TritonContext::setConcreteMemoryValue(): Expects an integer as value keyword.");
2808 }
2809
2810 if (execCallbacks != nullptr && !PyBool_Check(execCallbacks)) {
2811 return PyErr_Format(PyExc_TypeError, "TritonContext::setConcreteMemoryAreaValue(): Expects a boolean as execCallbacks keyword.");
2812 }
2813
2814 if (execCallbacks == nullptr) {
2815 execCallbacks = PyLong_FromUint32(true);
2816 }
2817
2818 /* setConcreteMemoryValue(integer, integer) */
2819 if (PyLong_Check(mem) || PyInt_Check(mem)) {
2820 triton::uint64 addr = PyLong_AsUint64(mem);
2821 triton::uint32 cvalue = PyLong_AsUint32(value);
2822
2823 if (cvalue > 0xff)
2824 return PyErr_Format(PyExc_TypeError, "TritonContext::setConcreteMemoryValue(): Value must be on 8 bits.");
2825
2826 try {
2827 PyTritonContext_AsTritonContext(self)->setConcreteMemoryValue(addr, static_cast<triton::uint8>(cvalue & 0xff), PyLong_AsBool(execCallbacks));
2828 }
2829 catch (const triton::exceptions::PyCallbacks&) {
2830 return nullptr;
2831 }
2832 catch (const triton::exceptions::Exception& e) {
2833 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2834 }
2835
2836 }
2837
2838 /* setConcreteMemoryValue(MemoryAccess) */
2839 else if (PyMemoryAccess_Check(mem)) {
2840 try {
2841 triton::uint512 cvalue = PyLong_AsUint512(value);
2842 PyTritonContext_AsTritonContext(self)->setConcreteMemoryValue(*PyMemoryAccess_AsMemoryAccess(mem), cvalue, PyLong_AsBool(execCallbacks));
2843 }
2844 catch (const triton::exceptions::PyCallbacks&) {
2845 return nullptr;
2846 }
2847 catch (const triton::exceptions::Exception& e) {
2848 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2849 }
2850 }
2851
2852 /* Invalid */
2853 else
2854 return PyErr_Format(PyExc_TypeError, "TritonContext::setConcreteMemoryValue(): something wrong.");
2855
2856 Py_INCREF(Py_None);
2857 return Py_None;
2858 }
2859
2860
2861 static PyObject* TritonContext_setConcreteRegisterValue(PyObject* self, PyObject* args, PyObject* kwargs) {
2862 PyObject* reg = nullptr;
2863 PyObject* value = nullptr;
2864 PyObject* execCallbacks = nullptr;
2865
2866 static char* keywords[] = {
2867 (char*)"reg",
2868 (char*)"value",
2869 (char*)"callbacks",
2870 nullptr
2871 };
2872
2873 /* Extract keywords */
2874 if (PyArg_ParseTupleAndKeywords(args, kwargs, "OO|O", keywords, &reg, &value, &execCallbacks) == false) {
2875 return PyErr_Format(PyExc_TypeError, "TritonContext::setConcreteRegisterValue(): Invalid keyword argument");
2876 }
2877
2878 if (reg == nullptr || !PyRegister_Check(reg)) {
2879 return PyErr_Format(PyExc_TypeError, "TritonContext::setConcreteRegisterValue(): Expects a Register as reg keyword.");
2880 }
2881
2882 if (value == nullptr || (!PyLong_Check(value) && !PyInt_Check(value))) {
2883 return PyErr_Format(PyExc_TypeError, "TritonContext::setConcreteRegisterValue(): Expects an integer as value keyword.");
2884 }
2885
2886 if (execCallbacks != nullptr && !PyBool_Check(execCallbacks)) {
2887 return PyErr_Format(PyExc_TypeError, "TritonContext::setConcreteMemoryAreaValue(): Expects a boolean as execCallbacks keyword.");
2888 }
2889
2890 if (execCallbacks == nullptr) {
2891 execCallbacks = PyLong_FromUint32(true);
2892 }
2893
2894 try {
2895 triton::uint512 cvalue = PyLong_AsUint512(value);
2896 PyTritonContext_AsTritonContext(self)->setConcreteRegisterValue(*PyRegister_AsRegister(reg), cvalue, PyLong_AsBool(execCallbacks));
2897 }
2898 catch (const triton::exceptions::PyCallbacks&) {
2899 return nullptr;
2900 }
2901 catch (const triton::exceptions::Exception& e) {
2902 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2903 }
2904
2905 Py_INCREF(Py_None);
2906 return Py_None;
2907 }
2908
2909
2910 static PyObject* TritonContext_setConcreteVariableValue(PyObject* self, PyObject* args) {
2911 PyObject* symVar = nullptr;
2912 PyObject* value = nullptr;
2913
2914 /* Extract arguments */
2915 if (PyArg_ParseTuple(args, "|OO", &symVar, &value) == false) {
2916 return PyErr_Format(PyExc_TypeError, "TritonContext::setConcreteVariableValue(): Invalid number of arguments");
2917 }
2918
2919 if (symVar == nullptr || !PySymbolicVariable_Check(symVar))
2920 return PyErr_Format(PyExc_TypeError, "TritonContext::setConcreteVariableValue(): Bad argument type.");
2921
2922 if (value == nullptr)
2923 return PyErr_Format(PyExc_TypeError, "TritonContext::setConcreteVariableValue(): Expects a second argument as integer value.");
2924
2925 try {
2926 PyTritonContext_AsTritonContext(self)->setConcreteVariableValue(PySymbolicVariable_AsSymbolicVariable(symVar), PyLong_AsUint512(value));
2927 }
2928 catch (const triton::exceptions::PyCallbacks&) {
2929 return nullptr;
2930 }
2931 catch (const triton::exceptions::Exception& e) {
2932 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2933 }
2934
2935 Py_INCREF(Py_None);
2936 return Py_None;
2937 }
2938
2939
2940 static PyObject* TritonContext_setMode(PyObject* self, PyObject* args) {
2941 PyObject* mode = nullptr;
2942 PyObject* flag = nullptr;
2943
2944 /* Extract arguments */
2945 if (PyArg_ParseTuple(args, "|OO", &mode, &flag) == false) {
2946 return PyErr_Format(PyExc_TypeError, "TritonContext::setMode(): Invalid number of arguments");
2947 }
2948
2949 if (mode == nullptr || (!PyLong_Check(mode) && !PyInt_Check(mode)))
2950 return PyErr_Format(PyExc_TypeError, "TritonContext::setMode(): Expects a MODE as argument.");
2951
2952 if (flag == nullptr || !PyBool_Check(flag))
2953 return PyErr_Format(PyExc_TypeError, "TritonContext::setMode(): Expects an boolean flag as second argument.");
2954
2955 try {
2957 }
2958 catch (const triton::exceptions::PyCallbacks&) {
2959 return nullptr;
2960 }
2961 catch (const triton::exceptions::Exception& e) {
2962 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2963 }
2964
2965 Py_INCREF(Py_None);
2966 return Py_None;
2967 }
2968
2969
2970 static PyObject* TritonContext_setSolver(PyObject* self, PyObject* solver) {
2971 if (solver == nullptr || (!PyLong_Check(solver) && !PyInt_Check(solver)))
2972 return PyErr_Format(PyExc_TypeError, "TritonContext::setSolver(): Expects a SOLVER as argument.");
2973
2974 try {
2976 }
2977 catch (const triton::exceptions::Exception& e) {
2978 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2979 }
2980
2981 Py_INCREF(Py_None);
2982 return Py_None;
2983 }
2984
2985
2986 static PyObject* TritonContext_setSolverMemoryLimit(PyObject* self, PyObject* megabytes) {
2987 if (megabytes == nullptr || (!PyLong_Check(megabytes) && !PyInt_Check(megabytes)))
2988 return PyErr_Format(PyExc_TypeError, "TritonContext::setSolverMemoryLimit(): Expects an integer as argument.");
2989
2990 try {
2991 PyTritonContext_AsTritonContext(self)->setSolverMemoryLimit(PyLong_AsUint32(megabytes));
2992 }
2993 catch (const triton::exceptions::Exception& e) {
2994 return PyErr_Format(PyExc_TypeError, "%s", e.what());
2995 }
2996
2997 Py_INCREF(Py_None);
2998 return Py_None;
2999 }
3000
3001
3002 static PyObject* TritonContext_setSolverTimeout(PyObject* self, PyObject* ms) {
3003 if (ms == nullptr || (!PyLong_Check(ms) && !PyInt_Check(ms)))
3004 return PyErr_Format(PyExc_TypeError, "TritonContext::setSolverTimeout(): Expects an integer as argument.");
3005
3006 try {
3007 PyTritonContext_AsTritonContext(self)->setSolverTimeout(PyLong_AsUint32(ms));
3008 }
3009 catch (const triton::exceptions::Exception& e) {
3010 return PyErr_Format(PyExc_TypeError, "%s", e.what());
3011 }
3012
3013 Py_INCREF(Py_None);
3014 return Py_None;
3015 }
3016
3017
3018 static PyObject* TritonContext_setTaintMemory(PyObject* self, PyObject* args) {
3019 PyObject* mem = nullptr;
3020 PyObject* flag = nullptr;
3021
3022 /* Extract arguments */
3023 if (PyArg_ParseTuple(args, "|OO", &mem, &flag) == false) {
3024 return PyErr_Format(PyExc_TypeError, "TritonContext::setTaintMemory(): Invalid number of arguments");
3025 }
3026
3027 if (mem == nullptr || !PyMemoryAccess_Check(mem))
3028 return PyErr_Format(PyExc_TypeError, "TritonContext::setTaintMemory(): Expects a MemoryAccess as first argument.");
3029
3030 if (flag == nullptr || !PyBool_Check(flag))
3031 return PyErr_Format(PyExc_TypeError, "TritonContext::setTaintMemory(): Expects a boolean as second argument.");
3032
3033 try {
3034 if (PyTritonContext_AsTritonContext(self)->setTaintMemory(*PyMemoryAccess_AsMemoryAccess(mem), PyLong_AsBool(flag)) == true)
3035 Py_RETURN_TRUE;
3036 Py_RETURN_FALSE;
3037 }
3038 catch (const triton::exceptions::PyCallbacks&) {
3039 return nullptr;
3040 }
3041 catch (const triton::exceptions::Exception& e) {
3042 return PyErr_Format(PyExc_TypeError, "%s", e.what());
3043 }
3044 }
3045
3046
3047 static PyObject* TritonContext_setTaintRegister(PyObject* self, PyObject* args) {
3048 PyObject* reg = nullptr;
3049 PyObject* flag = nullptr;
3050
3051 /* Extract arguments */
3052 if (PyArg_ParseTuple(args, "|OO", &reg, &flag) == false) {
3053 return PyErr_Format(PyExc_TypeError, "TritonContext::setTaintRegister(): Invalid number of arguments");
3054 }
3055
3056 if (reg == nullptr || !PyRegister_Check(reg))
3057 return PyErr_Format(PyExc_TypeError, "TritonContext::setTaintRegister(): Expects a Register as first argument.");
3058
3059 if (flag == nullptr || !PyBool_Check(flag))
3060 return PyErr_Format(PyExc_TypeError, "TritonContext::setTaintRegister(): Expects a boolean as second argument.");
3061
3062 try {
3063 if (PyTritonContext_AsTritonContext(self)->setTaintRegister(*PyRegister_AsRegister(reg), PyLong_AsBool(flag)) == true)
3064 Py_RETURN_TRUE;
3065 Py_RETURN_FALSE;
3066 }
3067 catch (const triton::exceptions::PyCallbacks&) {
3068 return nullptr;
3069 }
3070 catch (const triton::exceptions::Exception& e) {
3071 return PyErr_Format(PyExc_TypeError, "%s", e.what());
3072 }
3073 }
3074
3075
3076 static PyObject* TritonContext_setThumb(PyObject* self, PyObject* state) {
3077 if (state == nullptr || !PyBool_Check(state))
3078 return PyErr_Format(PyExc_TypeError, "TritonContext::setThumb(): Expects an boolean as argument.");
3079
3080 try {
3081 PyTritonContext_AsTritonContext(self)->setThumb(PyLong_AsBool(state));
3082 }
3083 catch (const triton::exceptions::Exception& e) {
3084 return PyErr_Format(PyExc_TypeError, "%s", e.what());
3085 }
3086
3087 Py_INCREF(Py_None);
3088 return Py_None;
3089 }
3090
3091
3092 static PyObject* TritonContext_simplify(PyObject* self, PyObject* args, PyObject* kwargs) {
3093 PyObject* obj = nullptr;
3094 PyObject* solver = nullptr;
3095 PyObject* llvm = nullptr;
3096 PyObject* padding = nullptr;
3097
3098 static char* keywords[] = {
3099 (char*)"obj",
3100 (char*)"solver",
3101 (char*)"llvm",
3102 (char*)"padding",
3103 nullptr
3104 };
3105
3106 /* Extract keywords */
3107 if (PyArg_ParseTupleAndKeywords(args, kwargs, "|OOOO", keywords, &obj, &solver, &llvm, &padding) == false) {
3108 return PyErr_Format(PyExc_TypeError, "TritonContext::simplify(): Invalid number of arguments");
3109 }
3110
3111 if (obj == nullptr || (!PyAstNode_Check(obj) && !PyBasicBlock_Check(obj)))
3112 return PyErr_Format(PyExc_TypeError, "TritonContext::simplify(): Expects a AstNode or a BasicBlock as obj argument.");
3113
3114 if (solver != nullptr && !PyBool_Check(solver))
3115 return PyErr_Format(PyExc_TypeError, "TritonContext::simplify(): Expects a boolean as solver argument.");
3116
3117 if (llvm != nullptr && !PyBool_Check(llvm))
3118 return PyErr_Format(PyExc_TypeError, "TritonContext::simplify(): Expects a boolean as llvm argument.");
3119
3120 if (padding != nullptr && !PyBool_Check(padding))
3121 return PyErr_Format(PyExc_TypeError, "TritonContext::simplify(): Expects a boolean as padding argument.");
3122
3123 if (solver == nullptr)
3124 solver = PyLong_FromUint32(false);
3125
3126 if (llvm == nullptr)
3127 llvm = PyLong_FromUint32(false);
3128
3129 if (padding == nullptr)
3130 padding = PyLong_FromUint32(false);
3131
3132 try {
3133 if (PyAstNode_Check(obj))
3134 return PyAstNode(PyTritonContext_AsTritonContext(self)->simplify(PyAstNode_AsAstNode(obj), PyLong_AsBool(solver), PyLong_AsBool(llvm)));
3135
3136 else if (PyBasicBlock_Check(obj))
3138
3139 else
3140 return PyErr_Format(PyExc_TypeError, "TritonContext::simplify(): Something wrong.");
3141 }
3142 catch (const triton::exceptions::PyCallbacks&) {
3143 return nullptr;
3144 }
3145 catch (const triton::exceptions::Exception& e) {
3146 return PyErr_Format(PyExc_TypeError, "%s", e.what());
3147 }
3148 }
3149
3150
3151 static PyObject* TritonContext_sliceExpressions(PyObject* self, PyObject* expr) {
3152 PyObject* ret = nullptr;
3153
3154 if (!PySymbolicExpression_Check(expr))
3155 return PyErr_Format(PyExc_TypeError, "TritonContext::sliceExpressions(): Expects a SymbolicExpression as argument.");
3156
3157 try {
3158 auto exprs = PyTritonContext_AsTritonContext(self)->sliceExpressions(PySymbolicExpression_AsSymbolicExpression(expr));
3159
3160 ret = xPyDict_New();
3161 for (auto it = exprs.begin(); it != exprs.end(); it++)
3162 xPyDict_SetItem(ret, PyLong_FromUsize(it->first), PySymbolicExpression(it->second));
3163 }
3164 catch (const triton::exceptions::PyCallbacks&) {
3165 return nullptr;
3166 }
3167 catch (const triton::exceptions::Exception& e) {
3168 return PyErr_Format(PyExc_TypeError, "%s", e.what());
3169 }
3170
3171 return ret;
3172 }
3173
3174
3175 static PyObject* TritonContext_symbolizeExpression(PyObject* self, PyObject* args) {
3176 PyObject* exprId = nullptr;
3177 PyObject* symVarSize = nullptr;
3178 PyObject* symVarAlias = nullptr;
3179 std::string calias = "";
3180
3181 /* Extract arguments */
3182 if (PyArg_ParseTuple(args, "|OOO", &exprId, &symVarSize, &symVarAlias) == false) {
3183 return PyErr_Format(PyExc_TypeError, "TritonContext::symbolizeExpression(): Invalid number of arguments");
3184 }
3185
3186 if (exprId == nullptr || (!PyLong_Check(exprId) && !PyInt_Check(exprId)))
3187 return PyErr_Format(PyExc_TypeError, "TritonContext::symbolizeExpression(): Expects an integer as first argument.");
3188
3189 if (symVarSize == nullptr || (!PyLong_Check(symVarSize) && !PyInt_Check(symVarSize)))
3190 return PyErr_Format(PyExc_TypeError, "TritonContext::symbolizeExpression(): Expects an integer as second argument.");
3191
3192 if (symVarAlias != nullptr && !PyStr_Check(symVarAlias))
3193 return PyErr_Format(PyExc_TypeError, "TritonContext::symbolizeExpression(): Expects a sting as third argument.");
3194
3195 if (symVarAlias != nullptr)
3196 calias = PyStr_AsString(symVarAlias);
3197
3198 try {
3199 return PySymbolicVariable(PyTritonContext_AsTritonContext(self)->symbolizeExpression(PyLong_AsUsize(exprId), PyLong_AsUint32(symVarSize), calias));
3200 }
3201 catch (const triton::exceptions::PyCallbacks&) {
3202 return nullptr;
3203 }
3204 catch (const triton::exceptions::Exception& e) {
3205 return PyErr_Format(PyExc_TypeError, "%s", e.what());
3206 }
3207 }
3208
3209
3210 static PyObject* TritonContext_symbolizeMemory(PyObject* self, PyObject* args) {
3211 PyObject* mem = nullptr;
3212 PyObject* symVarAlias = nullptr;
3213 std::string calias = "";
3214
3215 /* Extract arguments */
3216 if (PyArg_ParseTuple(args, "|OO", &mem, &symVarAlias) == false) {
3217 return PyErr_Format(PyExc_TypeError, "TritonContext::symbolizeMemory(): Invalid number of arguments");
3218 }
3219
3220 if (mem == nullptr || (!PyMemoryAccess_Check(mem)))
3221 return PyErr_Format(PyExc_TypeError, "TritonContext::symbolizeMemory(): Expects a MemoryAccess as first argument.");
3222
3223 if (symVarAlias != nullptr && !PyStr_Check(symVarAlias))
3224 return PyErr_Format(PyExc_TypeError, "TritonContext::symbolizeMemory(): Expects a sting as second argument.");
3225
3226 if (symVarAlias != nullptr)
3227 calias = PyStr_AsString(symVarAlias);
3228
3229 try {
3230 return PySymbolicVariable(PyTritonContext_AsTritonContext(self)->symbolizeMemory(*PyMemoryAccess_AsMemoryAccess(mem), calias));
3231 }
3232 catch (const triton::exceptions::PyCallbacks&) {
3233 return nullptr;
3234 }
3235 catch (const triton::exceptions::Exception& e) {
3236 return PyErr_Format(PyExc_TypeError, "%s", e.what());
3237 }
3238 }
3239
3240
3241 static PyObject* TritonContext_symbolizeRegister(PyObject* self, PyObject* args) {
3242 PyObject* reg = nullptr;
3243 PyObject* symVarAlias = nullptr;
3244 std::string calias = "";
3245
3246 /* Extract arguments */
3247 if (PyArg_ParseTuple(args, "|OO", &reg, &symVarAlias) == false) {
3248 return PyErr_Format(PyExc_TypeError, "TritonContext::symbolizeRegister(): Invalid number of arguments");
3249 }
3250
3251 if (reg == nullptr || (!PyRegister_Check(reg)))
3252 return PyErr_Format(PyExc_TypeError, "TritonContext::symbolizeRegister(): Expects a Register as first argument.");
3253
3254 if (symVarAlias != nullptr && !PyStr_Check(symVarAlias))
3255 return PyErr_Format(PyExc_TypeError, "TritonContext::symbolizeRegister(): Expects a sting as second argument.");
3256
3257 if (symVarAlias != nullptr)
3258 calias = PyStr_AsString(symVarAlias);
3259
3260 try {
3261 return PySymbolicVariable(PyTritonContext_AsTritonContext(self)->symbolizeRegister(*PyRegister_AsRegister(reg), calias));
3262 }
3263 catch (const triton::exceptions::PyCallbacks&) {
3264 return nullptr;
3265 }
3266 catch (const triton::exceptions::Exception& e) {
3267 return PyErr_Format(PyExc_TypeError, "%s", e.what());
3268 }
3269 }
3270
3271
3272 static PyObject* TritonContext_synthesize(PyObject* self, PyObject* args, PyObject* kwargs) {
3273 PyObject* node = nullptr;
3274 PyObject* constant = nullptr;
3275 PyObject* subexpr = nullptr;
3276 PyObject* opaque = nullptr;
3277
3278 static char* keywords[] = {
3279 (char*)"node",
3280 (char*)"constant",
3281 (char*)"subexpr",
3282 (char*)"opaque",
3283 nullptr
3284 };
3285
3286 /* Extract keywords */
3287 if (PyArg_ParseTupleAndKeywords(args, kwargs, "|OOOO", keywords, &node, &constant, &subexpr, &opaque) == false) {
3288 return PyErr_Format(PyExc_TypeError, "TritonContext::synthesize(): Invalid number of arguments");
3289 }
3290
3291 if (node == nullptr || !PyAstNode_Check(node))
3292 return PyErr_Format(PyExc_TypeError, "TritonContext::synthesize(): Expects a AstNode as node argument.");
3293
3294 if (constant != nullptr && !PyBool_Check(constant))
3295 return PyErr_Format(PyExc_TypeError, "TritonContext::synthesize(): Expects a boolean as constant argument.");
3296
3297 if (subexpr != nullptr && !PyBool_Check(subexpr))
3298 return PyErr_Format(PyExc_TypeError, "TritonContext::synthesize(): Expects a boolean as subexpr argument.");
3299
3300 if (opaque != nullptr && !PyBool_Check(opaque))
3301 return PyErr_Format(PyExc_TypeError, "TritonContext::synthesize(): Expects a boolean as opaque argument.");
3302
3303 if (constant == nullptr)
3304 constant = PyLong_FromUint32(true);
3305
3306 if (subexpr == nullptr)
3307 subexpr = PyLong_FromUint32(true);
3308
3309 if (opaque == nullptr)
3310 opaque = PyLong_FromUint32(false);
3311
3312 try {
3313 auto result = PyTritonContext_AsTritonContext(self)->synthesize(PyAstNode_AsAstNode(node), PyLong_AsBool(constant), PyLong_AsBool(subexpr), PyLong_AsBool(opaque));
3314 if (result.successful()) {
3315 return PyAstNode(result.getOutput());
3316 }
3317 else {
3318 Py_INCREF(Py_None);
3319 return Py_None;
3320 }
3321 }
3322 catch (const triton::exceptions::PyCallbacks&) {
3323 return nullptr;
3324 }
3325 catch (const triton::exceptions::Exception& e) {
3326 return PyErr_Format(PyExc_TypeError, "%s", e.what());
3327 }
3328 }
3329
3330
3331 static PyObject* TritonContext_taintAssignment(PyObject* self, PyObject* args) {
3332 PyObject* op1 = nullptr;
3333 PyObject* op2 = nullptr;
3334 bool ret = false;
3335
3336 /* Extract arguments */
3337 if (PyArg_ParseTuple(args, "OO", &op1, &op2) == false) {
3338 return PyErr_Format(PyExc_TypeError, "TritonContext::taintAssignment(): Invalid number of arguments");
3339 }
3340
3341 try {
3342 if (PyMemoryAccess_Check(op1) && PyImmediate_Check(op2))
3344
3345 else if (PyMemoryAccess_Check(op1) && PyMemoryAccess_Check(op2))
3347
3348 else if (PyMemoryAccess_Check(op1) && PyRegister_Check(op2))
3350
3351 else if (PyRegister_Check(op1) && PyImmediate_Check(op2))
3352 ret = PyTritonContext_AsTritonContext(self)->taintAssignment(*PyRegister_AsRegister(op1), *PyImmediate_AsImmediate(op2));
3353
3354 else if (PyRegister_Check(op1) && PyMemoryAccess_Check(op2))
3356
3357 else if (PyRegister_Check(op1) && PyRegister_Check(op2))
3358 ret = PyTritonContext_AsTritonContext(self)->taintAssignment(*PyRegister_AsRegister(op1), *PyRegister_AsRegister(op2));
3359
3360 else
3361 return PyErr_Format(PyExc_TypeError, "TritonContext::taintAssignment(): Invalid kind of parameter.");
3362
3363 if (ret == true) {
3364 Py_RETURN_TRUE;
3365 }
3366 Py_RETURN_FALSE;
3367 }
3368 catch (const triton::exceptions::PyCallbacks&) {
3369 return nullptr;
3370 }
3371 catch (const triton::exceptions::Exception& e) {
3372 return PyErr_Format(PyExc_TypeError, "%s", e.what());
3373 }
3374 }
3375
3376
3377 static PyObject* TritonContext_taintMemory(PyObject* self, PyObject* mem) {
3378 try {
3379 if (PyMemoryAccess_Check(mem)) {
3380 if (PyTritonContext_AsTritonContext(self)->taintMemory(*PyMemoryAccess_AsMemoryAccess(mem)) == true)
3381 Py_RETURN_TRUE;
3382 }
3383
3384 else if (PyLong_Check(mem) || PyInt_Check(mem)) {
3385 if (PyTritonContext_AsTritonContext(self)->taintMemory(PyLong_AsUint64(mem)) == true)
3386 Py_RETURN_TRUE;
3387 }
3388
3389 else
3390 return PyErr_Format(PyExc_TypeError, "TritonContext::taintMemory(): Expects a MemoryAccess or an integer as argument.");
3391 }
3392 catch (const triton::exceptions::PyCallbacks&) {
3393 return nullptr;
3394 }
3395 catch (const triton::exceptions::Exception& e) {
3396 return PyErr_Format(PyExc_TypeError, "%s", e.what());
3397 }
3398 Py_RETURN_FALSE;
3399 }
3400
3401
3402 static PyObject* TritonContext_taintRegister(PyObject* self, PyObject* reg) {
3403 if (!PyRegister_Check(reg))
3404 return PyErr_Format(PyExc_TypeError, "TritonContext::taintRegister(): Expects a Register as argument.");
3405
3406 try {
3407 if (PyTritonContext_AsTritonContext(self)->taintRegister(*PyRegister_AsRegister(reg)) == true)
3408 Py_RETURN_TRUE;
3409 Py_RETURN_FALSE;
3410 }
3411 catch (const triton::exceptions::PyCallbacks&) {
3412 return nullptr;
3413 }
3414 catch (const triton::exceptions::Exception& e) {
3415 return PyErr_Format(PyExc_TypeError, "%s", e.what());
3416 }
3417 }
3418
3419
3420 static PyObject* TritonContext_taintUnion(PyObject* self, PyObject* args) {
3421 PyObject* op1 = nullptr;
3422 PyObject* op2 = nullptr;
3423 bool ret = false;
3424
3425 /* Extract arguments */
3426 if (PyArg_ParseTuple(args, "OO", &op1, &op2) == false) {
3427 return PyErr_Format(PyExc_TypeError, "TritonContext::taintUnion(): Invalid number of arguments");
3428 }
3429
3430 try {
3431 if (PyMemoryAccess_Check(op1) && PyImmediate_Check(op2))
3433
3434 else if (PyMemoryAccess_Check(op1) && PyMemoryAccess_Check(op2))
3436
3437 else if (PyMemoryAccess_Check(op1) && PyRegister_Check(op2))
3439
3440 else if (PyRegister_Check(op1) && PyImmediate_Check(op2))
3442
3443 else if (PyRegister_Check(op1) && PyMemoryAccess_Check(op2))
3445
3446 else if (PyRegister_Check(op1) && PyRegister_Check(op2))
3448
3449 else
3450 return PyErr_Format(PyExc_TypeError, "TritonContext::taintUnion(): Invalid kind of parameter.");
3451
3452 if (ret == true) {
3453 Py_RETURN_TRUE;
3454 }
3455 Py_RETURN_FALSE;
3456 }
3457 catch (const triton::exceptions::PyCallbacks&) {
3458 return nullptr;
3459 }
3460 catch (const triton::exceptions::Exception& e) {
3461 return PyErr_Format(PyExc_TypeError, "%s", e.what());
3462 }
3463 }
3464
3465
3466 static PyObject* TritonContext_untaintMemory(PyObject* self, PyObject* mem) {
3467 try {
3468 if (PyMemoryAccess_Check(mem)) {
3469 if (PyTritonContext_AsTritonContext(self)->untaintMemory(*PyMemoryAccess_AsMemoryAccess(mem)) == true)
3470 Py_RETURN_TRUE;
3471 }
3472
3473 else if (PyLong_Check(mem) || PyInt_Check(mem)) {
3474 if (PyTritonContext_AsTritonContext(self)->untaintMemory(PyLong_AsUint64(mem)) == true)
3475 Py_RETURN_TRUE;
3476 }
3477
3478 else
3479 return PyErr_Format(PyExc_TypeError, "TritonContext::untaintMemory(): Expects a MemoryAccess or an integer as argument.");
3480 }
3481 catch (const triton::exceptions::PyCallbacks&) {
3482 return nullptr;
3483 }
3484 catch (const triton::exceptions::Exception& e) {
3485 return PyErr_Format(PyExc_TypeError, "%s", e.what());
3486 }
3487 Py_RETURN_FALSE;
3488 }
3489
3490
3491 static PyObject* TritonContext_untaintRegister(PyObject* self, PyObject* reg) {
3492 if (!PyRegister_Check(reg))
3493 return PyErr_Format(PyExc_TypeError, "TritonContext::untaintRegister(): Expects a Register as argument.");
3494
3495 try {
3496 if (PyTritonContext_AsTritonContext(self)->untaintRegister(*PyRegister_AsRegister(reg)) == true)
3497 Py_RETURN_TRUE;
3498 Py_RETURN_FALSE;
3499 }
3500 catch (const triton::exceptions::PyCallbacks&) {
3501 return nullptr;
3502 }
3503 catch (const triton::exceptions::Exception& e) {
3504 return PyErr_Format(PyExc_TypeError, "%s", e.what());
3505 }
3506 }
3507
3508
3509 static PyObject* TritonContext_getParentRegister(PyObject* self, PyObject* reg) {
3510 if (!PyRegister_Check(reg))
3511 return PyErr_Format(PyExc_TypeError, "TritonContext::getParentRegister(): Expects a Register as argument.");
3512
3513 try {
3514 return PyRegister(PyTritonContext_AsTritonContext(self)->getParentRegister(PyRegister_AsRegister(reg)->getId()));
3515 }
3516 catch (const triton::exceptions::PyCallbacks&) {
3517 return nullptr;
3518 }
3519 catch (const triton::exceptions::Exception& e) {
3520 return PyErr_Format(PyExc_TypeError, "%s", e.what());
3521 }
3522 }
3523
3524
3525 static PyObject* TritonContext_getattro(PyObject* self, PyObject* name) {
3526 try {
3527 /* Access to the registers attribute */
3528 if (std::string(PyStr_AsString(name)) == "registers") {
3529
3530 /* Check if the architecture is defined */
3531 if (PyTritonContext_AsTritonContext(self)->getArchitecture() == triton::arch::ARCH_INVALID)
3532 return PyErr_Format(PyExc_TypeError, "__getattr__.registers: Architecture is not defined.");
3533
3534 /* Maybe null if TritonContext was created over the PyTritonContextRef function */
3535 if (((TritonContext_Object*)(self))->regAttr == nullptr)
3536 TritonContext_fillRegistersAttribute(self);
3537
3538 Py_INCREF(((TritonContext_Object*)(self))->regAttr);
3539 return ((TritonContext_Object*)(self))->regAttr;
3540 }
3541 }
3542 catch (const triton::exceptions::PyCallbacks&) {
3543 return nullptr;
3544 }
3545 catch (const triton::exceptions::Exception& e) {
3546 return PyErr_Format(PyExc_TypeError, "%s", e.what());
3547 }
3548
3549 return PyObject_GenericGetAttr((PyObject *)self, name);
3550 }
3551
3552
3554 PyMethodDef TritonContext_callbacks[] = {
3555 {"addCallback", (PyCFunction)TritonContext_addCallback, METH_VARARGS, ""},
3556 {"assignSymbolicExpressionToMemory", (PyCFunction)TritonContext_assignSymbolicExpressionToMemory, METH_VARARGS, ""},
3557 {"assignSymbolicExpressionToRegister", (PyCFunction)TritonContext_assignSymbolicExpressionToRegister, METH_VARARGS, ""},
3558 {"buildSemantics", (PyCFunction)TritonContext_buildSemantics, METH_O, ""},
3559 {"clearCallbacks", (PyCFunction)TritonContext_clearCallbacks, METH_NOARGS, ""},
3560 {"clearModes", (PyCFunction)TritonContext_clearModes, METH_NOARGS, ""},
3561 {"clearConcreteMemoryValue", (PyCFunction)TritonContext_clearConcreteMemoryValue, METH_VARARGS, ""},
3562 {"clearPathConstraints", (PyCFunction)TritonContext_clearPathConstraints, METH_NOARGS, ""},
3563 {"concretizeAllMemory", (PyCFunction)TritonContext_concretizeAllMemory, METH_NOARGS, ""},
3564 {"concretizeAllRegister", (PyCFunction)TritonContext_concretizeAllRegister, METH_NOARGS, ""},
3565 {"concretizeMemory", (PyCFunction)TritonContext_concretizeMemory, METH_O, ""},
3566 {"concretizeRegister", (PyCFunction)TritonContext_concretizeRegister, METH_O, ""},
3567 {"createSymbolicMemoryExpression", (PyCFunction)TritonContext_createSymbolicMemoryExpression, METH_VARARGS, ""},
3568 {"createSymbolicRegisterExpression", (PyCFunction)TritonContext_createSymbolicRegisterExpression, METH_VARARGS, ""},
3569 {"createSymbolicVolatileExpression", (PyCFunction)TritonContext_createSymbolicVolatileExpression, METH_VARARGS, ""},
3570 {"disassembly", (PyCFunction)TritonContext_disassembly, METH_VARARGS, ""},
3571 {"evaluateAstViaSolver", (PyCFunction)TritonContext_evaluateAstViaSolver, METH_O, ""},
3572 {"getAllRegisters", (PyCFunction)TritonContext_getAllRegisters, METH_NOARGS, ""},
3573 {"getArchitecture", (PyCFunction)TritonContext_getArchitecture, METH_NOARGS, ""},
3574 {"getAstContext", (PyCFunction)TritonContext_getAstContext, METH_NOARGS, ""},
3575 {"getAstRepresentationMode", (PyCFunction)TritonContext_getAstRepresentationMode, METH_NOARGS, ""},
3576 {"getConcreteMemoryAreaValue", (PyCFunction)(void*)(PyCFunctionWithKeywords)TritonContext_getConcreteMemoryAreaValue, METH_VARARGS | METH_KEYWORDS, ""},
3577 {"getConcreteMemoryValue", (PyCFunction)(void*)(PyCFunctionWithKeywords)TritonContext_getConcreteMemoryValue, METH_VARARGS | METH_KEYWORDS, ""},
3578 {"getConcreteRegisterValue", (PyCFunction)(void*)(PyCFunctionWithKeywords)TritonContext_getConcreteRegisterValue, METH_VARARGS | METH_KEYWORDS, ""},
3579 {"getConcreteVariableValue", (PyCFunction)TritonContext_getConcreteVariableValue, METH_O, ""},
3580 {"getGprBitSize", (PyCFunction)TritonContext_getGprBitSize, METH_NOARGS, ""},
3581 {"getGprSize", (PyCFunction)TritonContext_getGprSize, METH_NOARGS, ""},
3582 {"getImmediateAst", (PyCFunction)TritonContext_getImmediateAst, METH_O, ""},
3583 {"getMemoryAst", (PyCFunction)TritonContext_getMemoryAst, METH_O, ""},
3584 {"getModel", (PyCFunction)(void*)(PyCFunctionWithKeywords)TritonContext_getModel, METH_VARARGS | METH_KEYWORDS, ""},
3585 {"getModels", (PyCFunction)(void*)(PyCFunctionWithKeywords)TritonContext_getModels, METH_VARARGS | METH_KEYWORDS, ""},
3586 {"getParentRegister", (PyCFunction)TritonContext_getParentRegister, METH_O, ""},
3587 {"getParentRegisters", (PyCFunction)TritonContext_getParentRegisters, METH_NOARGS, ""},
3588 {"getPathConstraints", (PyCFunction)TritonContext_getPathConstraints, METH_NOARGS, ""},
3589 {"getPathPredicate", (PyCFunction)TritonContext_getPathPredicate, METH_NOARGS, ""},
3590 {"getPathPredicateSize", (PyCFunction)TritonContext_getPathPredicateSize, METH_NOARGS, ""},
3591 {"getPredicatesToReachAddress", (PyCFunction)TritonContext_getPredicatesToReachAddress, METH_O, ""},
3592 {"getRegister", (PyCFunction)TritonContext_getRegister, METH_O, ""},
3593 {"getRegisterAst", (PyCFunction)TritonContext_getRegisterAst, METH_O, ""},
3594 {"getSolver", (PyCFunction)TritonContext_getSolver, METH_NOARGS, ""},
3595 {"getSymbolicExpression", (PyCFunction)TritonContext_getSymbolicExpression, METH_O, ""},
3596 {"getSymbolicExpressions", (PyCFunction)TritonContext_getSymbolicExpressions, METH_NOARGS, ""},
3597 {"getSymbolicMemory", (PyCFunction)TritonContext_getSymbolicMemory, METH_VARARGS, ""},
3598 {"getSymbolicMemoryValue", (PyCFunction)TritonContext_getSymbolicMemoryValue, METH_O, ""},
3599 {"getSymbolicRegister", (PyCFunction)TritonContext_getSymbolicRegister, METH_O, ""},
3600 {"getSymbolicRegisterValue", (PyCFunction)TritonContext_getSymbolicRegisterValue, METH_O, ""},
3601 {"getSymbolicRegisters", (PyCFunction)TritonContext_getSymbolicRegisters, METH_NOARGS, ""},
3602 {"getSymbolicVariable", (PyCFunction)TritonContext_getSymbolicVariable, METH_O, ""},
3603 {"getSymbolicVariables", (PyCFunction)TritonContext_getSymbolicVariables, METH_NOARGS, ""},
3604 {"getTaintedMemory", (PyCFunction)TritonContext_getTaintedMemory, METH_NOARGS, ""},
3605 {"getTaintedRegisters", (PyCFunction)TritonContext_getTaintedRegisters, METH_NOARGS, ""},
3606 {"getTaintedSymbolicExpressions", (PyCFunction)TritonContext_getTaintedSymbolicExpressions, METH_NOARGS, ""},
3607 {"isArchitectureValid", (PyCFunction)TritonContext_isArchitectureValid, METH_NOARGS, ""},
3608 {"isConcreteMemoryValueDefined", (PyCFunction)TritonContext_isConcreteMemoryValueDefined, METH_VARARGS, ""},
3609 {"isFlag", (PyCFunction)TritonContext_isFlag, METH_O, ""},
3610 {"isMemorySymbolized", (PyCFunction)TritonContext_isMemorySymbolized, METH_O, ""},
3611 {"isMemoryTainted", (PyCFunction)TritonContext_isMemoryTainted, METH_O, ""},
3612 {"isModeEnabled", (PyCFunction)TritonContext_isModeEnabled, METH_O, ""},
3613 {"isRegister", (PyCFunction)TritonContext_isRegister, METH_O, ""},
3614 {"isRegisterSymbolized", (PyCFunction)TritonContext_isRegisterSymbolized, METH_O, ""},
3615 {"isRegisterTainted", (PyCFunction)TritonContext_isRegisterTainted, METH_O, ""},
3616 {"isRegisterValid", (PyCFunction)TritonContext_isRegisterValid, METH_O, ""},
3617 {"isSat", (PyCFunction)TritonContext_isSat, METH_O, ""},
3618 {"isSymbolicExpressionExists", (PyCFunction)TritonContext_isSymbolicExpressionExists, METH_O, ""},
3619 {"isThumb", (PyCFunction)TritonContext_isThumb, METH_NOARGS, ""},
3620 {"liftToDot", (PyCFunction)TritonContext_liftToDot, METH_O, ""},
3621 {"liftToLLVM", (PyCFunction)(void*)(PyCFunctionWithKeywords)TritonContext_liftToLLVM, METH_VARARGS | METH_KEYWORDS, ""},
3622 {"liftToPython", (PyCFunction)(void*)(PyCFunctionWithKeywords)TritonContext_liftToPython, METH_VARARGS | METH_KEYWORDS, ""},
3623 {"liftToSMT", (PyCFunction)(void*)(PyCFunctionWithKeywords)TritonContext_liftToSMT, METH_VARARGS | METH_KEYWORDS, ""},
3624 {"newSymbolicExpression", (PyCFunction)TritonContext_newSymbolicExpression, METH_VARARGS, ""},
3625 {"newSymbolicVariable", (PyCFunction)TritonContext_newSymbolicVariable, METH_VARARGS, ""},
3626 {"popPathConstraint", (PyCFunction)TritonContext_popPathConstraint, METH_NOARGS, ""},
3627 {"processing", (PyCFunction)TritonContext_processing, METH_VARARGS, ""},
3628 {"pushPathConstraint", (PyCFunction)(void*)(PyCFunctionWithKeywords)TritonContext_pushPathConstraint, METH_VARARGS | METH_KEYWORDS, ""},
3629 {"removeCallback", (PyCFunction)TritonContext_removeCallback, METH_VARARGS, ""},
3630 {"reset", (PyCFunction)TritonContext_reset, METH_NOARGS, ""},
3631 {"setArchitecture", (PyCFunction)TritonContext_setArchitecture, METH_O, ""},
3632 {"setAstRepresentationMode", (PyCFunction)TritonContext_setAstRepresentationMode, METH_O, ""},
3633 {"setConcreteMemoryAreaValue", (PyCFunction)(void*)(PyCFunctionWithKeywords)TritonContext_setConcreteMemoryAreaValue, METH_VARARGS | METH_KEYWORDS, ""},
3634 {"setConcreteMemoryValue", (PyCFunction)(void*)(PyCFunctionWithKeywords)TritonContext_setConcreteMemoryValue, METH_VARARGS | METH_KEYWORDS, ""},
3635 {"setConcreteRegisterValue", (PyCFunction)(void*)(PyCFunctionWithKeywords)TritonContext_setConcreteRegisterValue, METH_VARARGS | METH_KEYWORDS, ""},
3636 {"setConcreteVariableValue", (PyCFunction)TritonContext_setConcreteVariableValue, METH_VARARGS, ""},
3637 {"setMode", (PyCFunction)TritonContext_setMode, METH_VARARGS, ""},
3638 {"setSolver", (PyCFunction)TritonContext_setSolver, METH_O, ""},
3639 {"setSolverMemoryLimit", (PyCFunction)TritonContext_setSolverMemoryLimit, METH_O, ""},
3640 {"setSolverTimeout", (PyCFunction)TritonContext_setSolverTimeout, METH_O, ""},
3641 {"setTaintMemory", (PyCFunction)TritonContext_setTaintMemory, METH_VARARGS, ""},
3642 {"setTaintRegister", (PyCFunction)TritonContext_setTaintRegister, METH_VARARGS, ""},
3643 {"setThumb", (PyCFunction)TritonContext_setThumb, METH_O, ""},
3644 {"simplify", (PyCFunction)(void*)(PyCFunctionWithKeywords)TritonContext_simplify, METH_VARARGS | METH_KEYWORDS, ""},
3645 {"sliceExpressions", (PyCFunction)TritonContext_sliceExpressions, METH_O, ""},
3646 {"symbolizeExpression", (PyCFunction)TritonContext_symbolizeExpression, METH_VARARGS, ""},
3647 {"symbolizeMemory", (PyCFunction)TritonContext_symbolizeMemory, METH_VARARGS, ""},
3648 {"symbolizeRegister", (PyCFunction)TritonContext_symbolizeRegister, METH_VARARGS, ""},
3649 {"synthesize", (PyCFunction)(void*)(PyCFunctionWithKeywords)TritonContext_synthesize, METH_VARARGS | METH_KEYWORDS, ""},
3650 {"taintAssignment", (PyCFunction)TritonContext_taintAssignment, METH_VARARGS, ""},
3651 {"taintMemory", (PyCFunction)TritonContext_taintMemory, METH_O, ""},
3652 {"taintRegister", (PyCFunction)TritonContext_taintRegister, METH_O, ""},
3653 {"taintUnion", (PyCFunction)TritonContext_taintUnion, METH_VARARGS, ""},
3654 {"untaintMemory", (PyCFunction)TritonContext_untaintMemory, METH_O, ""},
3655 {"untaintRegister", (PyCFunction)TritonContext_untaintRegister, METH_O, ""},
3656 {nullptr, nullptr, 0, nullptr}
3657 };
3658
3659
3661 PyTypeObject TritonContext_Type = {
3662 PyVarObject_HEAD_INIT(&PyType_Type, 0)
3663 "TritonContext", /* tp_name */
3664 sizeof(TritonContext_Object), /* tp_basicsize */
3665 0, /* tp_itemsize */
3666 (destructor)TritonContext_dealloc, /* tp_dealloc */
3667 0, /* tp_print or tp_vectorcall_offset */
3668 0, /* tp_getattr */
3669 0, /* tp_setattr */
3670 0, /* tp_compare */
3671 0, /* tp_repr */
3672 0, /* tp_as_number */
3673 0, /* tp_as_sequence */
3674 0, /* tp_as_mapping */
3675 0, /* tp_hash */
3676 0, /* tp_call */
3677 0, /* tp_str */
3678 (getattrofunc)TritonContext_getattro, /* tp_getattro */
3679 0, /* tp_setattro */
3680 0, /* tp_as_buffer */
3681 Py_TPFLAGS_DEFAULT, /* tp_flags */
3682 "TritonContext objects", /* tp_doc */
3683 0, /* tp_traverse */
3684 0, /* tp_clear */
3685 0, /* tp_richcompare */
3686 0, /* tp_weaklistoffset */
3687 0, /* tp_iter */
3688 0, /* tp_iternext */
3689 TritonContext_callbacks, /* tp_methods */
3690 0, /* tp_members */
3691 0, /* tp_getset */
3692 0, /* tp_base */
3693 0, /* tp_dict */
3694 0, /* tp_descr_get */
3695 0, /* tp_descr_set */
3696 0, /* tp_dictoffset */
3697 0, /* tp_init */
3698 0, /* tp_alloc */
3699 0, /* tp_new */
3700 0, /* tp_free */
3701 0, /* tp_is_gc */
3702 0, /* tp_bases */
3703 0, /* tp_mro */
3704 0, /* tp_cache */
3705 0, /* tp_subclasses */
3706 0, /* tp_weaklist */
3707 0, /* tp_del */
3708 #if IS_PY3
3709 0, /* tp_version_tag */
3710 0, /* tp_finalize */
3711 #if IS_PY3_8
3712 0, /* tp_vectorcall */
3713 #if !IS_PY3_9
3714 0, /* bpo-37250: kept for backwards compatibility in CPython 3.8 only */
3715 #endif
3716 #endif
3717 #else
3718 0 /* tp_version_tag */
3719 #endif
3720 };
3721
3722
3723 PyObject* PyTritonContext(void) {
3724 PyType_Ready(&TritonContext_Type);
3726
3727 if (object != nullptr) {
3728 object->ctx = new triton::Context();
3729 object->ref = false;
3730 object->regAttr = nullptr;
3731 }
3732
3733 return (PyObject*)object;
3734 }
3735
3736
3738 PyType_Ready(&TritonContext_Type);
3740
3741 if (object != nullptr) {
3742 object->ctx = new triton::Context(arch);
3743 object->ref = false;
3744 object->regAttr = nullptr;
3745 }
3746
3747 return (PyObject*)object;
3748 }
3749
3750
3752 PyType_Ready(&TritonContext_Type);
3754
3755 if (object != nullptr) {
3756 object->ctx = &ctx;
3757 object->ref = true;
3758 object->regAttr = nullptr;
3759 }
3760
3761 return (PyObject*)object;
3762 }
3763
3764 }; /* python namespace */
3765 }; /* bindings namespace */
3766}; /* triton namespace */
This is the main Triton Context class.
Definition context.hpp:45
This class is used to represent an instruction.
This class is used to represent a memory access.
This class is used when an instruction has a register operand.
Definition register.hpp:44
The exception class used by callbacks.
The root class of all exceptions.
TRITON_EXPORT const char * what() const
Returns the exception message.
register_e
Types of register.
Definition archEnums.hpp:68
std::shared_ptr< triton::ast::AbstractNode > SharedAbstractNode
Shared Abstract Node.
Definition ast.hpp:59
constexpr triton::uint32 flag
flag size in bit
Definition cpuSize.hpp:58
ComparableFunctor< void(triton::Context &, const triton::arch::Register &)> getConcreteRegisterValueCallback
The prototype of a GET_CONCRETE_REGISTER_VALUE callback.
Definition callbacks.hpp:53
ComparableFunctor< triton::ast::SharedAbstractNode(triton::Context &, const triton::ast::SharedAbstractNode &)> symbolicSimplificationCallback
The prototype of a SYMBOLIC_SIMPLIFICATION callback.
Definition callbacks.hpp:75
ComparableFunctor< void(triton::Context &, const triton::arch::Register &, const triton::uint512 &value)> setConcreteRegisterValueCallback
The prototype of a SET_CONCRETE_REGISTER_VALUE callback.
Definition callbacks.hpp:67
ComparableFunctor< void(triton::Context &, const triton::arch::MemoryAccess &, const triton::uint512 &value)> setConcreteMemoryValueCallback
The prototype of a SET_CONCRETE_MEMORY_VALUE callback.
Definition callbacks.hpp:60
ComparableFunctor< void(triton::Context &, const triton::arch::MemoryAccess &)> getConcreteMemoryValueCallback
The prototype of a GET_CONCRETE_MEMORY_VALUE callback.
Definition callbacks.hpp:46
mode_e
Enumerates all kinds of mode.
PyObject * PyTritonContextRef(triton::Context &ctx)
Creates a TritonContext python class which is a reference to another Context.
PyObject * xPyClass_New(PyObject *b, PyObject *d, PyObject *n)
Creates a PyClass and raises an exception if it fails. dict is copied in Py3 ! All references are dec...
PyObject * PyPathConstraint(const triton::engines::symbolic::PathConstraint &pc)
Creates the PathConstraint python class.
PyObject * PySymbolicVariable(const triton::engines::symbolic::SharedSymbolicVariable &symVar)
Creates the SymbolicVariable python class.
PyObject * PySolverModel(const triton::engines::solver::SolverModel &model)
Creates the SolverModel python class.
triton::uint64 PyLong_AsUint64(PyObject *vv)
Returns a triton::uint64 from a pyObject.
Definition utils.cpp:137
PyObject * PyLong_FromUsize(triton::usize value)
Returns a pyObject from a triton::usize.
Definition utils.cpp:288
PyObject * xPyTuple_New(Py_ssize_t len)
Creates a PyTuple and raises an exception if it fails.
PyObject * xPyString_FromString(const char *v)
Creates a PyString and raises an exception if it fails.
bool PyLong_AsBool(PyObject *obj)
Returns a bool from a pyObject.
Definition utils.cpp:45
PyObject * PyLong_FromUint512(triton::uint512 value)
Returns a pyObject from a triton::uint512.
Definition utils.cpp:418
triton::uint512 PyLong_AsUint512(PyObject *vv)
Returns a triton::uint512 from a pyObject.
Definition utils.cpp:224
PyObject * PyAstContext(const triton::ast::SharedAstContext &actx)
Creates an AstContext python class.
PyObject * PyBasicBlock(void)
Creates the BasicBlock python class.
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.
int xPyDict_SetItem(PyObject *p, PyObject *key, PyObject *val)
Same as PyDict_SetItem but decrements reference on object and key.
PyObject * PyLong_FromUint64(triton::uint64 value)
Returns a pyObject from a triton::uint64.
Definition utils.cpp:328
PyObject * PyRegister(const triton::arch::Register &reg)
Creates the Register python class.
PyObject * PyTritonContext(void)
Creates the new TritonContext python class.
triton::uint32 PyLong_AsUint32(PyObject *vv)
Returns a triton::uint32 from a pyObject.
Definition utils.cpp:108
triton::usize PyLong_AsUsize(PyObject *vv)
Returns a triton::usize from a pyObject.
Definition utils.cpp:79
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 * xPyDict_New(void)
Creates a PyDict and raises an exception if it fails.
PyObject * PyLong_FromUint32(triton::uint32 value)
Returns a pyObject from a triton::uint32.
Definition utils.cpp:322
PyObject * PyAstNode(const triton::ast::SharedAbstractNode &node)
Creates the AstNode python class.
mode_e
All types of representation mode.
Definition astEnums.hpp:98
std::shared_ptr< triton::engines::symbolic::SymbolicExpression > SharedSymbolicExpression
Shared Symbolic Expression.
Definition ast.hpp:40
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
PyTypeObject TritonContext_Type
Description of the python representation of a TritonContext.
PyMethodDef TritonContext_callbacks[]
TritonContext methods.
The Triton namespace.
#define PySymbolicVariable_Check(v)
#define PyImmediate_Check(v)
#define PyRegister_AsRegister(v)
#define PyMemoryAccess_Check(v)
#define PyTritonContext_AsTritonContext(v)
#define PyInstruction_AsInstruction(v)
#define PyImmediate_AsImmediate(v)
#define PyInstruction_Check(v)
#define PyAstNode_Check(v)
#define PyMemoryAccess_AsMemoryAccess(v)
#define PyBasicBlock_AsBasicBlock(v)
#define PyRegister_Check(v)
#define PyBasicBlock_Check(v)
#define PySymbolicExpression_Check(v)
#define PySymbolicVariable_AsSymbolicVariable(v)
#define PyAstNode_AsAstNode(v)
#define PySymbolicExpression_AsSymbolicExpression(v)