1
//! \file
2
/*
3
**  Copyright (C) - Triton
4
**
5
**  This program is under the terms of the Apache License 2.0.
6
*/
7

8
#include <triton/pythonBindings.hpp>
9
#include <triton/pythonObjects.hpp>
10
#include <triton/pythonUtils.hpp>
11
#include <triton/pythonXFunctions.hpp>
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

22
/*! \page py_REG_page REG
23
    \brief [**python api**] All information about the REG Python namespace.
24

25
\tableofcontents
26

27
\section REG_py_description Description
28
<hr>
29

30
According to the CPU architecture, the REG namespace contains all enums of registers.
31
It's possible to create a \ref py_Register_page from a register id using `getRegister`
32
like this:
33

34
~~~~~~~~~~~~~{.py}
35
>>> ah = ctxt.getRegister(REG.X86_64.AH)
36
>>> print ah
37
ah:8 bv[15..8]
38

39
~~~~~~~~~~~~~
40

41
Note that creating a \ref py_TritonContext_page, you can directly access the constructed
42
\ref py_Register_page according to your defined architecture.
43

44
~~~~~~~~~~~~~{.py}
45
>>> ctxt.setArchitecture(ARCH.X86_64)
46
>>> print ctxt.registers.zmm1
47
zmm1:512 bv[511..0]
48

49
~~~~~~~~~~~~~
50

51
\section REG_py_api Python API - Items of the REG namespace
52
<hr>
53

54
\subsection REG_X86_py_api x86 registers
55

56
\htmlinclude x86_reg
57

58
\subsection REG_X8664_py_api x86-64 registers
59

60
\htmlinclude x8664_reg
61

62
\subsection REG_ARM32_py_api ARM32 registers
63

64
\htmlinclude arm32_reg
65

66
\subsection REG_AArch64_py_api AArch64 registers
67

68
\htmlinclude aarch64_reg
69

70
*/
71

72

73

74
namespace triton {
75
  namespace bindings {
76
    namespace python {
77

78 1
      void initRegNamespace(PyObject* registersDict) {
79 1
        PyDict_Clear(registersDict);
80

81
        // Create X86 REG namespace
82

83 1
        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 1
        PyObject* x86RegistersDictClass = xPyClass_New(nullptr, x86RegistersDict, xPyString_FromString("X86"));
93 1
        xPyDict_SetItemString(registersDict, "X86", x86RegistersDictClass);
94

95
        // Create X86_64 REG namespace
96

97 1
        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 1
        PyObject* x8664RegistersDictClass = xPyClass_New(nullptr, x8664RegistersDict, xPyString_FromString("X86_64"));
106 1
        xPyDict_SetItemString(registersDict, "X86_64", x8664RegistersDictClass);
107

108
        // Create AArch64 REG namespace
109

110 1
        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
        #include "triton/aarch64.spec"
117

118 1
        PyObject* aarch64RegistersDictClass = xPyClass_New(nullptr, aarch64RegistersDict, xPyString_FromString("AARCH64"));
119 1
        xPyDict_SetItemString(registersDict, "AARCH64", aarch64RegistersDictClass);
120

121
        // Create ARM32 REG namespace
122

123 1
        PyObject* arm32RegistersDict = xPyDict_New();
124

125
        #define REG_SPEC(UPPER_NAME, _1, _2, _3, _4, _5) \
126
          xPyDict_SetItemString(arm32RegistersDict, #UPPER_NAME, PyLong_FromUint32(triton::arch::ID_REG_ARM32_##UPPER_NAME));
127
        // Use REG not available in capstone as normal register
128
        #define REG_SPEC_NO_CAPSTONE REG_SPEC
129
        #include "triton/arm32.spec"
130

131 1
        PyObject* arm32RegistersDictClass = xPyClass_New(nullptr, arm32RegistersDict, xPyString_FromString("ARM32"));
132 1
        xPyDict_SetItemString(registersDict, "ARM32", arm32RegistersDictClass);
133
      }
134

135
    }; /* python namespace */
136
  }; /* bindings namespace */
137 1
}; /* triton namespace */

Read our documentation on viewing source code .

Loading