libTriton version 1.0 build 1592
Loading...
Searching...
No Matches
architecture.hpp
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
8#ifndef TRITON_ARCHITECTURE_H
9#define TRITON_ARCHITECTURE_H
10
11#include <memory>
12#include <set>
13#include <string>
14#include <vector>
15
16#include <triton/archEnums.hpp>
17#include <triton/basicBlock.hpp>
18#include <triton/callbacks.hpp>
20#include <triton/dllexport.hpp>
23#include <triton/register.hpp>
25
26
27
29namespace triton {
36 namespace arch {
46 private:
49
50 protected:
53
55 std::unique_ptr<triton::arch::CpuInterface> cpu;
56
57 public:
59 TRITON_EXPORT Architecture(triton::callbacks::Callbacks* callbacks=nullptr);
60
62 TRITON_EXPORT bool isFlag(triton::arch::register_e regId) const;
63
65 TRITON_EXPORT bool isFlag(const triton::arch::Register& reg) const;
66
68 TRITON_EXPORT bool isRegister(triton::arch::register_e regId) const;
69
71 TRITON_EXPORT bool isRegister(const triton::arch::Register& reg) const;
72
74 TRITON_EXPORT bool isRegisterValid(triton::arch::register_e regId) const;
75
77 TRITON_EXPORT bool isRegisterValid(const triton::arch::Register& reg) const;
78
80 TRITON_EXPORT bool isValid(void) const;
81
83 TRITON_EXPORT bool isThumb(void) const;
84
86 TRITON_EXPORT void setThumb(bool state);
87
89 TRITON_EXPORT bool isMemoryExclusive(const triton::arch::MemoryAccess& mem) const;
90
92 TRITON_EXPORT void setMemoryExclusiveTag(const triton::arch::MemoryAccess& mem, bool tag);
93
95 TRITON_EXPORT triton::arch::architecture_e getArchitecture(void) const;
96
98 TRITON_EXPORT triton::arch::endianness_e getEndianness(void) const;
99
101 TRITON_EXPORT triton::arch::CpuInterface* getCpuInstance(void);
102
104 TRITON_EXPORT triton::uint32 numberOfRegisters(void) const;
105
107 TRITON_EXPORT triton::uint32 gprBitSize(void) const;
108
110 TRITON_EXPORT triton::uint32 gprSize(void) const;
111
114
116 TRITON_EXPORT void clearArchitecture(void);
117
119 TRITON_EXPORT const std::unordered_map<triton::arch::register_e, const triton::arch::Register>& getAllRegisters(void) const;
120
122 TRITON_EXPORT const std::unordered_map<triton::uint64, triton::uint8, IdentityHash<triton::uint64>>& getConcreteMemory(void) const;
123
125 TRITON_EXPORT std::set<const triton::arch::Register*> getParentRegisters(void) const;
126
128 TRITON_EXPORT const triton::arch::Register& getRegister(triton::arch::register_e id) const;
129
131 TRITON_EXPORT const triton::arch::Register& getRegister(const std::string& name) const;
132
135
137 TRITON_EXPORT const triton::arch::Register& getParentRegister(const triton::arch::Register& reg) const;
138
140 TRITON_EXPORT const triton::arch::Register& getProgramCounter(void) const;
141
143 TRITON_EXPORT const triton::arch::Register& getStackPointer(void) const;
144
146 TRITON_EXPORT const triton::arch::Instruction getNopInstruction(void) const;
147
149 TRITON_EXPORT void disassembly(triton::arch::Instruction& inst) const;
150
152 TRITON_EXPORT void disassembly(triton::arch::BasicBlock& block, triton::uint64 addr=0) const;
153
155 TRITON_EXPORT std::vector<triton::arch::Instruction> disassembly(triton::uint64 addr, triton::usize count) const;
156
158 TRITON_EXPORT triton::arch::BasicBlock disassembly(triton::uint64 addr, bool(*filterCallback)(std::vector<triton::arch::Instruction>&)) const;
159
161 TRITON_EXPORT triton::arch::BasicBlock disassembly(triton::uint64 addr) const;
162
164 TRITON_EXPORT triton::uint8 getConcreteMemoryValue(triton::uint64 addr, bool execCallbacks=true) const;
165
167 TRITON_EXPORT triton::uint512 getConcreteMemoryValue(const triton::arch::MemoryAccess& mem, bool execCallbacks=true) const;
168
170 TRITON_EXPORT std::vector<triton::uint8> getConcreteMemoryAreaValue(triton::uint64 baseAddr, triton::usize size, bool execCallbacks=true) const;
171
173 TRITON_EXPORT triton::uint512 getConcreteRegisterValue(const triton::arch::Register& reg, bool execCallbacks=true) const;
174
181 TRITON_EXPORT void setConcreteMemoryValue(triton::uint64 addr, triton::uint8 value, bool execCallbacks=true);
182
189 TRITON_EXPORT void setConcreteMemoryValue(const triton::arch::MemoryAccess& mem, const triton::uint512& value, bool execCallbacks=true);
190
197 TRITON_EXPORT void setConcreteMemoryAreaValue(triton::uint64 baseAddr, const std::vector<triton::uint8>& values, bool execCallbacks=true);
198
205 TRITON_EXPORT void setConcreteMemoryAreaValue(triton::uint64 baseAddr, const void* area, triton::usize size, bool execCallbacks=true);
206
213 TRITON_EXPORT void setConcreteRegisterValue(const triton::arch::Register& reg, const triton::uint512& value, bool execCallbacks=true);
214
216 TRITON_EXPORT bool isConcreteMemoryValueDefined(const triton::arch::MemoryAccess& mem) const;
217
219 TRITON_EXPORT bool isConcreteMemoryValueDefined(triton::uint64 baseAddr, triton::usize size=1) const;
220
222 TRITON_EXPORT void clearConcreteMemoryValue(const triton::arch::MemoryAccess& mem);
223
225 TRITON_EXPORT void clearConcreteMemoryValue(triton::uint64 baseAddr, triton::usize size=1);
226 };
227
229 };
231};
232
233#endif /* TRITON_ARCHITECTURE_H */
The abstract architecture class.
TRITON_EXPORT const triton::arch::Register & getRegister(triton::arch::register_e id) const
Returns register from id.
TRITON_EXPORT void setConcreteMemoryAreaValue(triton::uint64 baseAddr, const std::vector< triton::uint8 > &values, bool execCallbacks=true)
[architecture api] - Sets the concrete value of a memory area.
TRITON_EXPORT std::set< const triton::arch::Register * > getParentRegisters(void) const
Returns all parent registers.
TRITON_EXPORT void setThumb(bool state)
Sets CPU state to Thumb mode. Only valid for Arm32.
TRITON_EXPORT const triton::arch::Register & getStackPointer(void) const
Returns the stack pointer register.
TRITON_EXPORT triton::uint32 numberOfRegisters(void) const
Returns the number of registers according to the CPU architecture.
TRITON_EXPORT triton::uint32 gprBitSize(void) const
Returns the bit in bit of the General Purpose Registers.
TRITON_EXPORT void setConcreteRegisterValue(const triton::arch::Register &reg, const triton::uint512 &value, bool execCallbacks=true)
[architecture api] - Sets the concrete value of a register.
TRITON_EXPORT void setConcreteMemoryValue(triton::uint64 addr, triton::uint8 value, bool execCallbacks=true)
[architecture api] - Sets the concrete value of a memory cell.
TRITON_EXPORT void setArchitecture(triton::arch::architecture_e arch)
Initializes an architecture.
TRITON_EXPORT const std::unordered_map< triton::uint64, triton::uint8, IdentityHash< triton::uint64 > > & getConcreteMemory(void) const
Return all memory.
TRITON_EXPORT void disassembly(triton::arch::Instruction &inst) const
Disassembles the instruction according to the architecture.
TRITON_EXPORT void clearArchitecture(void)
Clears the architecture states (registers and memory).
TRITON_EXPORT bool isMemoryExclusive(const triton::arch::MemoryAccess &mem) const
Returns true if the memory access is tagged as exclusive. Only valid for Arm32 and AArch64.
TRITON_EXPORT std::vector< triton::uint8 > getConcreteMemoryAreaValue(triton::uint64 baseAddr, triton::usize size, bool execCallbacks=true) const
Returns the concrete value of a memory area.
TRITON_EXPORT const triton::arch::Instruction getNopInstruction(void) const
Returns a NOP instruction according to the architecture.
TRITON_EXPORT bool isConcreteMemoryValueDefined(const triton::arch::MemoryAccess &mem) const
Returns true if memory cells have a defined concrete value.
TRITON_EXPORT const std::unordered_map< triton::arch::register_e, const triton::arch::Register > & getAllRegisters(void) const
Returns all registers.
TRITON_EXPORT Architecture(triton::callbacks::Callbacks *callbacks=nullptr)
Constructor.
TRITON_EXPORT bool isFlag(triton::arch::register_e regId) const
Returns true if the register ID is a flag.
TRITON_EXPORT const triton::arch::Register & getProgramCounter(void) const
Returns the program counter register.
std::unique_ptr< triton::arch::CpuInterface > cpu
Instance to the real CPU class.
TRITON_EXPORT void setMemoryExclusiveTag(const triton::arch::MemoryAccess &mem, bool tag)
Sets exclusive memory access tag. Only valid for Arm32 and AArch64.
TRITON_EXPORT triton::uint8 getConcreteMemoryValue(triton::uint64 addr, bool execCallbacks=true) const
Returns the concrete value of a memory cell.
triton::arch::architecture_e arch
The kind of architecture used.
TRITON_EXPORT triton::uint512 getConcreteRegisterValue(const triton::arch::Register &reg, bool execCallbacks=true) const
Returns the concrete value of a register.
TRITON_EXPORT void clearConcreteMemoryValue(const triton::arch::MemoryAccess &mem)
Clears concrete values assigned to the memory cells.
TRITON_EXPORT bool isRegisterValid(triton::arch::register_e regId) const
Returns true if the register ID is a register or a flag.
TRITON_EXPORT bool isRegister(triton::arch::register_e regId) const
Returns true if the register ID is a register.
TRITON_EXPORT bool isThumb(void) const
Returns true if the execution mode is Thumb. Only valid for Arm32.
TRITON_EXPORT triton::arch::architecture_e getArchitecture(void) const
Returns the kind of architecture as triton::arch::architecture_e.
TRITON_EXPORT bool isValid(void) const
Returns true if the architecture is valid.
TRITON_EXPORT triton::arch::endianness_e getEndianness(void) const
Returns the kind of endianness as triton::arch::endianness_e.
TRITON_EXPORT triton::uint32 gprSize(void) const
Returns the bit in byte of the General Purpose Registers.
TRITON_EXPORT const triton::arch::Register & getParentRegister(triton::arch::register_e id) const
Returns parent register from id.
TRITON_EXPORT triton::arch::CpuInterface * getCpuInstance(void)
Returns the instance of the current CPU used.
This class is used to represent a basic block.
This interface is used as abstract CPU interface. All CPU must use this interface.
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 callbacks class.
Definition callbacks.hpp:79
register_e
Types of register.
Definition archEnums.hpp:68
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
The Triton namespace.