1 | #ifndef CAPSTONE_EVM_H |
2 | #define CAPSTONE_EVM_H |
3 | |
4 | /* Capstone Disassembly Engine */ |
5 | /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2018 */ |
6 | |
7 | #ifdef __cplusplus |
8 | extern "C" { |
9 | #endif |
10 | |
11 | #include "platform.h" |
12 | |
13 | #ifdef _MSC_VER |
14 | #pragma warning(disable:4201) |
15 | #endif |
16 | |
17 | /// Instruction structure |
18 | typedef struct cs_evm { |
19 | unsigned char pop; ///< number of items popped from the stack |
20 | unsigned char push; ///< number of items pushed into the stack |
21 | unsigned int fee; ///< gas fee for the instruction |
22 | } cs_evm; |
23 | |
24 | /// EVM instruction |
25 | typedef enum evm_insn { |
26 | EVM_INS_STOP = 0, |
27 | EVM_INS_ADD = 1, |
28 | EVM_INS_MUL = 2, |
29 | EVM_INS_SUB = 3, |
30 | EVM_INS_DIV = 4, |
31 | EVM_INS_SDIV = 5, |
32 | EVM_INS_MOD = 6, |
33 | EVM_INS_SMOD = 7, |
34 | EVM_INS_ADDMOD = 8, |
35 | EVM_INS_MULMOD = 9, |
36 | EVM_INS_EXP = 10, |
37 | EVM_INS_SIGNEXTEND = 11, |
38 | EVM_INS_LT = 16, |
39 | EVM_INS_GT = 17, |
40 | EVM_INS_SLT = 18, |
41 | EVM_INS_SGT = 19, |
42 | EVM_INS_EQ = 20, |
43 | EVM_INS_ISZERO = 21, |
44 | EVM_INS_AND = 22, |
45 | EVM_INS_OR = 23, |
46 | EVM_INS_XOR = 24, |
47 | EVM_INS_NOT = 25, |
48 | EVM_INS_BYTE = 26, |
49 | EVM_INS_SHA3 = 32, |
50 | EVM_INS_ADDRESS = 48, |
51 | EVM_INS_BALANCE = 49, |
52 | EVM_INS_ORIGIN = 50, |
53 | EVM_INS_CALLER = 51, |
54 | EVM_INS_CALLVALUE = 52, |
55 | EVM_INS_CALLDATALOAD = 53, |
56 | EVM_INS_CALLDATASIZE = 54, |
57 | EVM_INS_CALLDATACOPY = 55, |
58 | EVM_INS_CODESIZE = 56, |
59 | EVM_INS_CODECOPY = 57, |
60 | EVM_INS_GASPRICE = 58, |
61 | EVM_INS_EXTCODESIZE = 59, |
62 | EVM_INS_EXTCODECOPY = 60, |
63 | EVM_INS_RETURNDATASIZE = 61, |
64 | EVM_INS_RETURNDATACOPY = 62, |
65 | EVM_INS_BLOCKHASH = 64, |
66 | EVM_INS_COINBASE = 65, |
67 | EVM_INS_TIMESTAMP = 66, |
68 | EVM_INS_NUMBER = 67, |
69 | EVM_INS_DIFFICULTY = 68, |
70 | EVM_INS_GASLIMIT = 69, |
71 | EVM_INS_POP = 80, |
72 | EVM_INS_MLOAD = 81, |
73 | EVM_INS_MSTORE = 82, |
74 | EVM_INS_MSTORE8 = 83, |
75 | EVM_INS_SLOAD = 84, |
76 | EVM_INS_SSTORE = 85, |
77 | EVM_INS_JUMP = 86, |
78 | EVM_INS_JUMPI = 87, |
79 | EVM_INS_PC = 88, |
80 | EVM_INS_MSIZE = 89, |
81 | EVM_INS_GAS = 90, |
82 | EVM_INS_JUMPDEST = 91, |
83 | EVM_INS_PUSH1 = 96, |
84 | EVM_INS_PUSH2 = 97, |
85 | EVM_INS_PUSH3 = 98, |
86 | EVM_INS_PUSH4 = 99, |
87 | EVM_INS_PUSH5 = 100, |
88 | EVM_INS_PUSH6 = 101, |
89 | EVM_INS_PUSH7 = 102, |
90 | EVM_INS_PUSH8 = 103, |
91 | EVM_INS_PUSH9 = 104, |
92 | EVM_INS_PUSH10 = 105, |
93 | EVM_INS_PUSH11 = 106, |
94 | EVM_INS_PUSH12 = 107, |
95 | EVM_INS_PUSH13 = 108, |
96 | EVM_INS_PUSH14 = 109, |
97 | EVM_INS_PUSH15 = 110, |
98 | EVM_INS_PUSH16 = 111, |
99 | EVM_INS_PUSH17 = 112, |
100 | EVM_INS_PUSH18 = 113, |
101 | EVM_INS_PUSH19 = 114, |
102 | EVM_INS_PUSH20 = 115, |
103 | EVM_INS_PUSH21 = 116, |
104 | EVM_INS_PUSH22 = 117, |
105 | EVM_INS_PUSH23 = 118, |
106 | EVM_INS_PUSH24 = 119, |
107 | EVM_INS_PUSH25 = 120, |
108 | EVM_INS_PUSH26 = 121, |
109 | EVM_INS_PUSH27 = 122, |
110 | EVM_INS_PUSH28 = 123, |
111 | EVM_INS_PUSH29 = 124, |
112 | EVM_INS_PUSH30 = 125, |
113 | EVM_INS_PUSH31 = 126, |
114 | EVM_INS_PUSH32 = 127, |
115 | EVM_INS_DUP1 = 128, |
116 | EVM_INS_DUP2 = 129, |
117 | EVM_INS_DUP3 = 130, |
118 | EVM_INS_DUP4 = 131, |
119 | EVM_INS_DUP5 = 132, |
120 | EVM_INS_DUP6 = 133, |
121 | EVM_INS_DUP7 = 134, |
122 | EVM_INS_DUP8 = 135, |
123 | EVM_INS_DUP9 = 136, |
124 | EVM_INS_DUP10 = 137, |
125 | EVM_INS_DUP11 = 138, |
126 | EVM_INS_DUP12 = 139, |
127 | EVM_INS_DUP13 = 140, |
128 | EVM_INS_DUP14 = 141, |
129 | EVM_INS_DUP15 = 142, |
130 | EVM_INS_DUP16 = 143, |
131 | EVM_INS_SWAP1 = 144, |
132 | EVM_INS_SWAP2 = 145, |
133 | EVM_INS_SWAP3 = 146, |
134 | EVM_INS_SWAP4 = 147, |
135 | EVM_INS_SWAP5 = 148, |
136 | EVM_INS_SWAP6 = 149, |
137 | EVM_INS_SWAP7 = 150, |
138 | EVM_INS_SWAP8 = 151, |
139 | EVM_INS_SWAP9 = 152, |
140 | EVM_INS_SWAP10 = 153, |
141 | EVM_INS_SWAP11 = 154, |
142 | EVM_INS_SWAP12 = 155, |
143 | EVM_INS_SWAP13 = 156, |
144 | EVM_INS_SWAP14 = 157, |
145 | EVM_INS_SWAP15 = 158, |
146 | EVM_INS_SWAP16 = 159, |
147 | EVM_INS_LOG0 = 160, |
148 | EVM_INS_LOG1 = 161, |
149 | EVM_INS_LOG2 = 162, |
150 | EVM_INS_LOG3 = 163, |
151 | EVM_INS_LOG4 = 164, |
152 | EVM_INS_CREATE = 240, |
153 | EVM_INS_CALL = 241, |
154 | EVM_INS_CALLCODE = 242, |
155 | EVM_INS_RETURN = 243, |
156 | EVM_INS_DELEGATECALL = 244, |
157 | EVM_INS_CALLBLACKBOX = 245, |
158 | EVM_INS_STATICCALL = 250, |
159 | EVM_INS_REVERT = 253, |
160 | EVM_INS_SUICIDE = 255, |
161 | |
162 | EVM_INS_INVALID = 512, |
163 | EVM_INS_ENDING, // <-- mark the end of the list of instructions |
164 | } evm_insn; |
165 | |
166 | /// Group of EVM instructions |
167 | typedef enum evm_insn_group { |
168 | EVM_GRP_INVALID = 0, ///< = CS_GRP_INVALID |
169 | |
170 | EVM_GRP_JUMP, ///< all jump instructions |
171 | |
172 | EVM_GRP_MATH = 8, ///< math instructions |
173 | EVM_GRP_STACK_WRITE, ///< instructions write to stack |
174 | EVM_GRP_STACK_READ, ///< instructions read from stack |
175 | EVM_GRP_MEM_WRITE, ///< instructions write to memory |
176 | EVM_GRP_MEM_READ, ///< instructions read from memory |
177 | EVM_GRP_STORE_WRITE, ///< instructions write to storage |
178 | EVM_GRP_STORE_READ, ///< instructions read from storage |
179 | EVM_GRP_HALT, ///< instructions halt execution |
180 | |
181 | EVM_GRP_ENDING, ///< <-- mark the end of the list of groups |
182 | } evm_insn_group; |
183 | |
184 | #ifdef __cplusplus |
185 | } |
186 | #endif |
187 | |
188 | #endif |
189 | |