1 //! \file 2 /* 3 ** Copyright (C) - Triton 4 ** 5 ** This program is under the terms of the Apache License 2.0. 6 */ 7 8 #ifndef TRITON_AARCH64CPU_HPP 9 #define TRITON_AARCH64CPU_HPP 10 11 #include <set> 12 #include <unordered_map> 13 #include <vector> 14 15 #include <triton/aarch64Specifications.hpp> 16 #include <triton/archEnums.hpp> 17 #include <triton/callbacks.hpp> 18 #include <triton/cpuInterface.hpp> 19 #include <triton/dllexport.hpp> 20 #include <triton/externalLibs.hpp> 21 #include <triton/instruction.hpp> 22 #include <triton/memoryAccess.hpp> 23 #include <triton/register.hpp> 24 #include <triton/tritonTypes.hpp> 25 26 27 28 //! The Triton namespace 29 namespace triton { 30 /*! 31 * \addtogroup triton 32 * @{ 33 */ 34 35 //! The Architecture namespace 36 namespace arch { 37 /*! 38 * \ingroup triton 39 * \addtogroup arch 40 * @{ 41 */ 42 43 //! The ARM namespace 44 namespace arm { 45 /*! 46 * \ingroup arch 47 * \addtogroup arm 48 * @{ 49 */ 50 51 //! The aarch64 namespace 52 namespace aarch64 { 53 /*! 54 * \ingroup arm 55 * \addtogroup aarch64 56 * @{ 57 */ 58 59 //! \class AArch64Cpu 60 /*! \brief This class is used to describe the ARM (64-bits) spec. */ 61 class AArch64Cpu : public CpuInterface, public AArch64Specifications { 62 63 static const triton::arch::register_e pcId = triton::arch::ID_REG_AARCH64_PC; 64 static const triton::arch::register_e spId = triton::arch::ID_REG_AARCH64_SP; 65 66 private: 67 //! Callbacks API 68 triton::callbacks::Callbacks* callbacks; 69 70 //! Capstone context 71 triton::extlibs::capstone::csh handle; 72 73 //! Copies a AArch64Cpu class. 74 void copy(const AArch64Cpu& other); 75 76 //! Initializes the disassembler 77 inline void disassInit(void); 78 79 protected: 80 /*! \brief map of address -> concrete value 81 * 82 * \details 83 * **item1**: memory address<br> 84 * **item2**: concrete value 85 */ 86 std::unordered_map<triton::uint64, triton::uint8> memory; 87 88 //! Concrete value of x0 89 triton::uint8 x0[triton::size::qword]; 90 //! Concrete value of x1 91 triton::uint8 x1[triton::size::qword]; 92 //! Concrete value of x2 93 triton::uint8 x2[triton::size::qword]; 94 //! Concrete value of x3 95 triton::uint8 x3[triton::size::qword]; 96 //! Concrete value of x4 97 triton::uint8 x4[triton::size::qword]; 98 //! Concrete value of x5 99 triton::uint8 x5[triton::size::qword]; 100 //! Concrete value of x6 101 triton::uint8 x6[triton::size::qword]; 102 //! Concrete value of x7 103 triton::uint8 x7[triton::size::qword]; 104 //! Concrete value of x8 105 triton::uint8 x8[triton::size::qword]; 106 //! Concrete value of x9 107 triton::uint8 x9[triton::size::qword]; 108 //! Concrete value of x10 109 triton::uint8 x10[triton::size::qword]; 110 //! Concrete value of x11 111 triton::uint8 x11[triton::size::qword]; 112 //! Concrete value of x12 113 triton::uint8 x12[triton::size::qword]; 114 //! Concrete value of x13 115 triton::uint8 x13[triton::size::qword]; 116 //! Concrete value of x14 117 triton::uint8 x14[triton::size::qword]; 118 //! Concrete value of x15 119 triton::uint8 x15[triton::size::qword]; 120 //! Concrete value of x16 121 triton::uint8 x16[triton::size::qword]; 122 //! Concrete value of x17 123 triton::uint8 x17[triton::size::qword]; 124 //! Concrete value of x18 125 triton::uint8 x18[triton::size::qword]; 126 //! Concrete value of x19 127 triton::uint8 x19[triton::size::qword]; 128 //! Concrete value of x20 129 triton::uint8 x20[triton::size::qword]; 130 //! Concrete value of x21 131 triton::uint8 x21[triton::size::qword]; 132 //! Concrete value of x22 133 triton::uint8 x22[triton::size::qword]; 134 //! Concrete value of x23 135 triton::uint8 x23[triton::size::qword]; 136 //! Concrete value of x24 137 triton::uint8 x24[triton::size::qword]; 138 //! Concrete value of x25 139 triton::uint8 x25[triton::size::qword]; 140 //! Concrete value of x26 141 triton::uint8 x26[triton::size::qword]; 142 //! Concrete value of x27 143 triton::uint8 x27[triton::size::qword]; 144 //! Concrete value of x28 145 triton::uint8 x28[triton::size::qword]; 146 //! Concrete value of x29 147 triton::uint8 x29[triton::size::qword]; 148 //! Concrete value of x30 149 triton::uint8 x30[triton::size::qword]; 150 //! Concrete value of sp 151 triton::uint8 sp[triton::size::qword]; 152 //! Concrete value of pc 153 triton::uint8 pc[triton::size::qword]; 154 //! Concrete value of spsr 155 triton::uint8 spsr[triton::size::dword]; 156 157 public: 158 //! Constructor. 159 TRITON_EXPORT AArch64Cpu(triton::callbacks::Callbacks* callbacks=nullptr); 160 161 //! Constructor 162 TRITON_EXPORT AArch64Cpu(const AArch64Cpu& other); 163 164 //! Destructor. 165 TRITON_EXPORT virtual ~AArch64Cpu(); 166 167 //! Copies a AArch64Cpu class. 168 TRITON_EXPORT AArch64Cpu& operator=(const AArch64Cpu& other); 169 170 //! Returns true if regId is a GRP. 171 TRITON_EXPORT bool isGPR(triton::arch::register_e regId) const; 172 173 /* Virtual pure inheritance ================================================= */ 174 TRITON_EXPORT bool isFlag(triton::arch::register_e regId) const; 175 TRITON_EXPORT bool isRegister(triton::arch::register_e regId) const; 176 TRITON_EXPORT bool isRegisterValid(triton::arch::register_e regId) const; 177 TRITON_EXPORT bool isThumb(void) const; 178 TRITON_EXPORT const std::unordered_map<triton::arch::register_e, const triton::arch::Register>& getAllRegisters(void) const; 179 TRITON_EXPORT const triton::arch::Register& getParentRegister(const triton::arch::Register& reg) const; 180 TRITON_EXPORT const triton::arch::Register& getParentRegister(triton::arch::register_e id) const; 181 TRITON_EXPORT const triton::arch::Register& getProgramCounter(void) const; 182 TRITON_EXPORT const triton::arch::Register& getRegister(triton::arch::register_e id) 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) const; 195 TRITON_EXPORT void setConcreteMemoryAreaValue(triton::uint64 baseAddr, const std::vector<triton::uint8>& values); 196 TRITON_EXPORT void setConcreteMemoryAreaValue(triton::uint64 baseAddr, const triton::uint8* area, triton::usize size); 197 TRITON_EXPORT void setConcreteMemoryValue(const triton::arch::MemoryAccess& mem, const triton::uint512& value); 198 TRITON_EXPORT void setConcreteMemoryValue(triton::uint64 addr, triton::uint8 value); 199 TRITON_EXPORT void setConcreteRegisterValue(const triton::arch::Register& reg, const triton::uint512& value); 200 TRITON_EXPORT void setThumb(bool state); 201 TRITON_EXPORT bool isConcreteMemoryValueDefined(const triton::arch::MemoryAccess& mem) const; 202 TRITON_EXPORT bool isConcreteMemoryValueDefined(triton::uint64 baseAddr, triton::usize size=1) const; 203 TRITON_EXPORT void clearConcreteMemoryValue(const triton::arch::MemoryAccess& mem); 204 TRITON_EXPORT void clearConcreteMemoryValue(triton::uint64 baseAddr, triton::usize size=1); 205 /* End of virtual pure inheritance ========================================== */ 206 }; 207 208 /*! @} End of aarch64 namespace */ 209 }; 210 /*! @} End of arm namespace */ 211 }; 212 /*! @} End of arch namespace */ 213 }; 214 /*! @} End of triton namespace */ 215 }; 216 217 #endif /* TRITON_AARCH64CPU_HPP */ 218