libTriton version 1.0 build 1592
Loading...
Searching...
No Matches
arm32Cpu.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_ARM32CPU_HPP
9#define TRITON_ARM32CPU_HPP
10
11#include <set>
12#include <string>
13#include <unordered_map>
14#include <vector>
15
16#include <triton/archEnums.hpp>
18#include <triton/callbacks.hpp>
20#include <triton/dllexport.hpp>
23#include <triton/register.hpp>
25
26
27
29namespace triton {
36 namespace arch {
44 namespace arm {
52 namespace arm32 {
60
61 class Arm32Cpu : public CpuInterface, public Arm32Specifications {
62
63 static const triton::arch::register_e pcId = triton::arch::ID_REG_ARM32_PC;
64 static const triton::arch::register_e spId = triton::arch::ID_REG_ARM32_SP;
65
66 private:
69
71 std::size_t handleArm;
72
74 std::size_t handleThumb;
75
77 char itStateArray[5];
78
80 triton::uint32 itInstrsCount;
81
83 triton::uint32 itInstrIndex;
84
87
90
92 std::set<triton::uint64> exclusiveMemoryTags;
93
95 void copy(const Arm32Cpu& other);
96
98 inline void disassInit(void);
99
101 void postDisassembly(triton::arch::Instruction& inst) const;
102
105
106 protected:
114 std::unordered_map<triton::uint64, triton::uint8, IdentityHash<triton::uint64>> memory;
115
148 // //! Concrete value of apsr
150
152 bool thumb;
153
154 public:
156 TRITON_EXPORT Arm32Cpu(triton::callbacks::Callbacks* callbacks=nullptr);
157
159 TRITON_EXPORT Arm32Cpu(const Arm32Cpu& other);
160
162 TRITON_EXPORT virtual ~Arm32Cpu();
163
165 TRITON_EXPORT Arm32Cpu& operator=(const Arm32Cpu& other);
166
168 TRITON_EXPORT bool isGPR(triton::arch::register_e regId) const;
169
170 /* Virtual pure inheritance ================================================= */
171 TRITON_EXPORT bool isFlag(triton::arch::register_e regId) const;
172 TRITON_EXPORT bool isRegister(triton::arch::register_e regId) const;
173 TRITON_EXPORT bool isRegisterValid(triton::arch::register_e regId) const;
174 TRITON_EXPORT bool isThumb(void) const;
175 TRITON_EXPORT bool isMemoryExclusive(const triton::arch::MemoryAccess& mem) const;
176 TRITON_EXPORT const std::unordered_map<triton::arch::register_e, const triton::arch::Register>& getAllRegisters(void) const;
177 TRITON_EXPORT const std::unordered_map<triton::uint64, triton::uint8, IdentityHash<triton::uint64>>& getConcreteMemory(void) const;
178 TRITON_EXPORT const triton::arch::Register& getParentRegister(const triton::arch::Register& reg) const;
180 TRITON_EXPORT const triton::arch::Register& getProgramCounter(void) const;
181 TRITON_EXPORT const triton::arch::Register& getRegister(triton::arch::register_e id) const;
182 TRITON_EXPORT const triton::arch::Register& getRegister(const std::string& name) const;
183 TRITON_EXPORT const triton::arch::Register& getStackPointer(void) const;
184 TRITON_EXPORT std::set<const triton::arch::Register*> getParentRegisters(void) const;
185 TRITON_EXPORT std::vector<triton::uint8> getConcreteMemoryAreaValue(triton::uint64 baseAddr, triton::usize size, bool execCallbacks=true) const;
186 TRITON_EXPORT triton::arch::endianness_e getEndianness(void) const;
187 TRITON_EXPORT triton::uint32 gprBitSize(void) const;
188 TRITON_EXPORT triton::uint32 gprSize(void) const;
189 TRITON_EXPORT triton::uint32 numberOfRegisters(void) const;
190 TRITON_EXPORT triton::uint512 getConcreteMemoryValue(const triton::arch::MemoryAccess& mem, bool execCallbacks=true) const;
191 TRITON_EXPORT triton::uint512 getConcreteRegisterValue(const triton::arch::Register& reg, bool execCallbacks=true) const;
192 TRITON_EXPORT triton::uint8 getConcreteMemoryValue(triton::uint64 addr, bool execCallbacks=true) const;
193 TRITON_EXPORT void clear(void);
194 TRITON_EXPORT void disassembly(triton::arch::Instruction& inst);
195 TRITON_EXPORT void setConcreteMemoryAreaValue(triton::uint64 baseAddr, const std::vector<triton::uint8>& values, bool execCallbacks=true);
196 TRITON_EXPORT void setConcreteMemoryAreaValue(triton::uint64 baseAddr, const void* area, triton::usize size, bool execCallbacks=true);
197 TRITON_EXPORT void setConcreteMemoryValue(const triton::arch::MemoryAccess& mem, const triton::uint512& value, bool execCallbacks=true);
198 TRITON_EXPORT void setConcreteMemoryValue(triton::uint64 addr, triton::uint8 value, bool execCallbacks=true);
199 TRITON_EXPORT void setConcreteRegisterValue(const triton::arch::Register& reg, const triton::uint512& value, bool execCallbacks=true);
200 TRITON_EXPORT void setThumb(bool state);
201 TRITON_EXPORT void setMemoryExclusiveTag(const triton::arch::MemoryAccess& mem, bool tag);
202 TRITON_EXPORT bool isConcreteMemoryValueDefined(const triton::arch::MemoryAccess& mem) const;
203 TRITON_EXPORT bool isConcreteMemoryValueDefined(triton::uint64 baseAddr, triton::usize size=1) const;
204 TRITON_EXPORT void clearConcreteMemoryValue(const triton::arch::MemoryAccess& mem);
205 TRITON_EXPORT void clearConcreteMemoryValue(triton::uint64 baseAddr, triton::usize size=1);
206 /* End of virtual pure inheritance ========================================== */
207 };
208
210 };
212 };
214 };
216};
217
218#endif /* TRITON_ARM32CPU_HPP */
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
This class is used to describe the ARM (32-bits) spec.
Definition arm32Cpu.hpp:61
TRITON_EXPORT void setMemoryExclusiveTag(const triton::arch::MemoryAccess &mem, bool tag)
Sets exclusive memory access tag. Only valid for Arm32 and AArch64.
Definition arm32Cpu.cpp:803
TRITON_EXPORT std::set< const triton::arch::Register * > getParentRegisters(void) const
Returns all parent registers.
Definition arm32Cpu.cpp:189
triton::uint8 r2[triton::size::dword]
Concrete value of r2.
Definition arm32Cpu.hpp:121
TRITON_EXPORT const std::unordered_map< triton::uint64, triton::uint8, IdentityHash< triton::uint64 > > & getConcreteMemory(void) const
Return all memory.
Definition arm32Cpu.cpp:184
TRITON_EXPORT triton::uint32 gprSize(void) const
Returns the bit in byte of the General Purpose Registers.
Definition arm32Cpu.cpp:170
triton::uint8 pc[triton::size::dword]
Concrete value of pc.
Definition arm32Cpu.hpp:147
triton::uint8 r7[triton::size::dword]
Concrete value of r7.
Definition arm32Cpu.hpp:131
triton::uint8 sp[triton::size::dword]
Concrete value of sp.
Definition arm32Cpu.hpp:143
triton::uint8 r1[triton::size::dword]
Concrete value of r1.
Definition arm32Cpu.hpp:119
TRITON_EXPORT const triton::arch::Register & getStackPointer(void) const
Returns the stack pointer register.
Definition arm32Cpu.cpp:244
TRITON_EXPORT bool isGPR(triton::arch::register_e regId) const
Returns true if regId is a GRP.
Definition arm32Cpu.cpp:160
TRITON_EXPORT triton::arch::endianness_e getEndianness(void) const
Returns the kind of endianness as triton::arch::endianness_e.
Definition arm32Cpu.cpp:140
triton::uint8 r14[triton::size::dword]
Concrete value of r14.
Definition arm32Cpu.hpp:145
TRITON_EXPORT void clearConcreteMemoryValue(const triton::arch::MemoryAccess &mem)
Clears concrete values assigned to the memory cells.
Definition arm32Cpu.cpp:831
TRITON_EXPORT triton::uint512 getConcreteRegisterValue(const triton::arch::Register &reg, bool execCallbacks=true) const
Returns the concrete value of a register.
Definition arm32Cpu.cpp:635
triton::uint8 r6[triton::size::dword]
Concrete value of r6.
Definition arm32Cpu.hpp:129
TRITON_EXPORT bool isFlag(triton::arch::register_e regId) const
Returns true if the register ID is a flag.
Definition arm32Cpu.cpp:145
TRITON_EXPORT bool isConcreteMemoryValueDefined(const triton::arch::MemoryAccess &mem) const
Returns true if memory cells have a defined concrete value.
Definition arm32Cpu.cpp:817
TRITON_EXPORT void setConcreteMemoryValue(const triton::arch::MemoryAccess &mem, const triton::uint512 &value, bool execCallbacks=true)
[architecture api] - Sets the concrete value of memory cells.
Definition arm32Cpu.cpp:678
TRITON_EXPORT bool isRegisterValid(triton::arch::register_e regId) const
Returns true if the register ID is valid.
Definition arm32Cpu.cpp:155
TRITON_EXPORT bool isThumb(void) const
Returns true if the execution mode is Thumb. Only useful for Arm32.
Definition arm32Cpu.cpp:780
TRITON_EXPORT const triton::arch::Register & getRegister(triton::arch::register_e id) const
Returns register from id.
Definition arm32Cpu.cpp:209
TRITON_EXPORT const triton::arch::Register & getProgramCounter(void) const
Returns the program counter register.
Definition arm32Cpu.cpp:239
virtual TRITON_EXPORT ~Arm32Cpu()
Destructor.
Definition arm32Cpu.cpp:47
TRITON_EXPORT void clear(void)
Clears the architecture states (registers and memory).
Definition arm32Cpu.cpp:109
std::unordered_map< triton::uint64, triton::uint8, IdentityHash< triton::uint64 > > memory
map of address -> concrete value
Definition arm32Cpu.hpp:114
TRITON_EXPORT void disassembly(triton::arch::Instruction &inst)
Disassembles the instruction according to the architecture.
Definition arm32Cpu.cpp:249
TRITON_EXPORT triton::uint32 gprBitSize(void) const
Returns the bit in bit of the General Purpose Registers.
Definition arm32Cpu.cpp:175
TRITON_EXPORT Arm32Cpu(triton::callbacks::Callbacks *callbacks=nullptr)
Constructor.
Definition arm32Cpu.cpp:27
triton::uint8 r5[triton::size::dword]
Concrete value of r5.
Definition arm32Cpu.hpp:127
triton::uint8 r11[triton::size::dword]
Concrete value of r11.
Definition arm32Cpu.hpp:139
triton::uint8 r8[triton::size::dword]
Concrete value of r8.
Definition arm32Cpu.hpp:133
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.
Definition arm32Cpu.cpp:625
triton::uint8 r10[triton::size::dword]
Concrete value of r10.
Definition arm32Cpu.hpp:137
TRITON_EXPORT triton::uint512 getConcreteMemoryValue(const triton::arch::MemoryAccess &mem, bool execCallbacks=true) const
Returns the concrete value of memory cells.
Definition arm32Cpu.cpp:604
triton::uint8 r12[triton::size::dword]
Concrete value of r12.
Definition arm32Cpu.hpp:141
TRITON_EXPORT bool isRegister(triton::arch::register_e regId) const
Returns true if the register ID is a register.
Definition arm32Cpu.cpp:150
TRITON_EXPORT triton::uint32 numberOfRegisters(void) const
Returns the number of registers according to the CPU architecture.
Definition arm32Cpu.cpp:165
TRITON_EXPORT Arm32Cpu & operator=(const Arm32Cpu &other)
Copies a Arm32Cpu class.
Definition arm32Cpu.cpp:134
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.
Definition arm32Cpu.cpp:715
TRITON_EXPORT const std::unordered_map< triton::arch::register_e, const triton::arch::Register > & getAllRegisters(void) const
Returns all registers.
Definition arm32Cpu.cpp:180
TRITON_EXPORT const triton::arch::Register & getParentRegister(const triton::arch::Register &reg) const
Returns parent register from a given one.
Definition arm32Cpu.cpp:229
triton::uint8 r3[triton::size::dword]
Concrete value of r3.
Definition arm32Cpu.hpp:123
TRITON_EXPORT bool isMemoryExclusive(const triton::arch::MemoryAccess &mem) const
Returns true if the given memory access is tagged as exclusive. Only valid for Arm32 and AArch64.
Definition arm32Cpu.cpp:790
triton::uint8 r0[triton::size::dword]
Concrete value of r0.
Definition arm32Cpu.hpp:117
TRITON_EXPORT void setThumb(bool state)
Sets CPU state to Thumb mode.
Definition arm32Cpu.cpp:785
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.
Definition arm32Cpu.cpp:699
triton::uint8 r4[triton::size::dword]
Concrete value of r4.
Definition arm32Cpu.hpp:125
triton::uint8 r9[triton::size::dword]
Concrete value of r9.
Definition arm32Cpu.hpp:135
The Arm32Specifications class defines specifications about the Arm32 CPU.
The callbacks class.
Definition callbacks.hpp:79
register_e
Types of register.
Definition archEnums.hpp:68
condition_e
Types of condition.
constexpr triton::uint32 dword
dword size in byte
Definition cpuSize.hpp:34
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.