libTriton version 1.0 build 1590
Loading...
Searching...
No Matches
initRegNamespace.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
12
13
14/* setup doctest context
15
16>>> from triton import ARCH, TritonContext, REG
17>>> ctxt = TritonContext()
18>>> ctxt.setArchitecture(ARCH.X86_64)
19
20*/
21
74namespace triton {
75 namespace bindings {
76 namespace python {
77
78 void initRegNamespace(PyObject* registersDict) {
79 PyDict_Clear(registersDict);
80
81 // Create X86 REG namespace
82
83 PyObject* x86RegistersDict = xPyDict_New();
84
85 #define REG_SPEC(UPPER_NAME, _1, _2, _3, _4, _5, _6, _7, X86_AVAIL) \
86 if (X86_AVAIL) \
87 xPyDict_SetItemString(x86RegistersDict, #UPPER_NAME, PyLong_FromUint32(triton::arch::ID_REG_X86_##UPPER_NAME));
88 // Use REG not available in capstone as normal register
89 #define REG_SPEC_NO_CAPSTONE REG_SPEC
90 #include "triton/x86.spec"
91
92 PyObject* x86RegistersDictClass = xPyClass_New(nullptr, x86RegistersDict, xPyString_FromString("X86"));
93 xPyDict_SetItemString(registersDict, "X86", x86RegistersDictClass);
94
95 // Create X86_64 REG namespace
96
97 PyObject* x8664RegistersDict = xPyDict_New();
98
99 #define REG_SPEC(UPPER_NAME, _1, _2, _3, _4, _5, _6, _7, _8) \
100 xPyDict_SetItemString(x8664RegistersDict, #UPPER_NAME, PyLong_FromUint32(triton::arch::ID_REG_X86_##UPPER_NAME));
101 // Use REG not available in capstone as normal register
102 #define REG_SPEC_NO_CAPSTONE REG_SPEC
103 #include "triton/x86.spec"
104
105 PyObject* x8664RegistersDictClass = xPyClass_New(nullptr, x8664RegistersDict, xPyString_FromString("X86_64"));
106 xPyDict_SetItemString(registersDict, "X86_64", x8664RegistersDictClass);
107
108 // Create AArch64 REG namespace
109
110 PyObject* aarch64RegistersDict = xPyDict_New();
111
112 #define REG_SPEC(UPPER_NAME, _1, _2, _3, _4, _5) \
113 xPyDict_SetItemString(aarch64RegistersDict, #UPPER_NAME, PyLong_FromUint32(triton::arch::ID_REG_AARCH64_##UPPER_NAME));
114 // Use REG not available in capstone as normal register
115 #define REG_SPEC_NO_CAPSTONE REG_SPEC
116 #define SYS_REG_SPEC REG_SPEC
117 #include "triton/aarch64.spec"
118
119 PyObject* aarch64RegistersDictClass = xPyClass_New(nullptr, aarch64RegistersDict, xPyString_FromString("AARCH64"));
120 xPyDict_SetItemString(registersDict, "AARCH64", aarch64RegistersDictClass);
121
122 // Create ARM32 REG namespace
123
124 PyObject* arm32RegistersDict = xPyDict_New();
125
126 #define REG_SPEC(UPPER_NAME, _1, _2, _3, _4, _5) \
127 xPyDict_SetItemString(arm32RegistersDict, #UPPER_NAME, PyLong_FromUint32(triton::arch::ID_REG_ARM32_##UPPER_NAME));
128 // Use REG not available in capstone as normal register
129 #define REG_SPEC_NO_CAPSTONE REG_SPEC
130 #include "triton/arm32.spec"
131
132 PyObject* arm32RegistersDictClass = xPyClass_New(nullptr, arm32RegistersDict, xPyString_FromString("ARM32"));
133 xPyDict_SetItemString(registersDict, "ARM32", arm32RegistersDictClass);
134 }
135
136 }; /* python namespace */
137 }; /* bindings namespace */
138}; /* triton namespace */
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 * xPyString_FromString(const char *v)
Creates a PyString and raises an exception if it fails.
void initRegNamespace(PyObject *registersDict)
Initializes the REG python namespace.
PyObject * xPyDict_New(void)
Creates a PyDict and raises an exception if it fails.
int xPyDict_SetItemString(PyObject *p, const char *key, PyObject *val)
Same as PyDict_SetItemString but decrements reference on object.
The Triton namespace.