1 /// Types and constants of EVM architecture 2 module capstone.evm; 3 4 import std.conv: to; 5 6 import capstone.api; 7 import capstone.capstone; 8 import capstone.detail; 9 import capstone.instruction; 10 import capstone.instructiongroup; 11 import capstone.internal; 12 import capstone.register; 13 import capstone.utils; 14 15 /** Architecture-specific Register variant 16 17 Note that this is a dummy enum as there are no valid registers 18 */ 19 class EvmRegister : RegisterImpl!EvmRegisterId { 20 package this(in Capstone cs, in int id) { 21 super(cs, id); 22 } 23 } 24 25 /// Architecture-specific InstructionGroup variant 26 class EvmInstructionGroup : InstructionGroupImpl!EvmInstructionGroupId { 27 package this(in Capstone cs, in int id) { 28 super(cs, id); 29 } 30 } 31 32 /// Architecture-specific Detail variant 33 class EvmDetail : DetailImpl!(EvmRegister, EvmInstructionGroup, EvmInstructionDetail) { 34 package this(in Capstone cs, cs_detail* internal) { 35 super(cs, internal); 36 } 37 } 38 39 /// Architecture-specific instruction variant 40 class EvmInstruction : InstructionImpl!(EvmInstructionId, EvmRegister, EvmDetail) { 41 package this(in Capstone cs, cs_insn* internal) { 42 super(cs, internal); 43 } 44 } 45 46 /// Architecture-specific Capstone variant 47 class CapstoneEvm : CapstoneImpl!(EvmInstructionId, EvmInstruction) { 48 /** Creates an architecture-specific instance with a given mode of interpretation 49 50 Params: 51 modeFlags = The (initial) mode of interpretation, which can still be changed later on 52 */ 53 this(in ModeFlags modeFlags){ 54 super(Arch.evm, modeFlags); 55 } 56 } 57 58 /// Evm-specific information about an instruction 59 struct EvmInstructionDetail { 60 ubyte pop; /// Number of items popped from the stack 61 ubyte push; /// Number of items pushed into the stack 62 uint fee; /// Gas fee for the instruction 63 64 package this(in Capstone cs, cs_arch_detail arch_detail){ 65 const internal = arch_detail.evm; 66 pop = internal.pop; 67 push = internal.push; 68 fee = internal.fee; 69 } 70 } 71 72 //============================================================================= 73 // Constants 74 //============================================================================= 75 76 /** EVM register 77 78 Note that this is a dummy enum as there are no valid registers 79 */ 80 enum EvmRegisterId { 81 invalid = 0 82 } 83 84 /// EVM instruction 85 enum EvmInstructionId { 86 stop = 0, 87 add = 1, 88 mul = 2, 89 sub = 3, 90 div = 4, 91 sdiv = 5, 92 mod = 6, 93 smod = 7, 94 addmod = 8, 95 mulmod = 9, 96 exp = 10, 97 signextend = 11, 98 lt = 16, 99 gt = 17, 100 slt = 18, 101 sgt = 19, 102 eq = 20, 103 iszero = 21, 104 and = 22, 105 or = 23, 106 xor = 24, 107 not = 25, 108 byte_ = 26, 109 sha3 = 32, 110 address = 48, 111 balance = 49, 112 origin = 50, 113 caller = 51, 114 callvalue = 52, 115 calldataload = 53, 116 calldatasize = 54, 117 calldatacopy = 55, 118 codesize = 56, 119 codecopy = 57, 120 gasprice = 58, 121 extcodesize = 59, 122 extcodecopy = 60, 123 returndatasize = 61, 124 returndatacopy = 62, 125 blockhash = 64, 126 coinbase = 65, 127 timestamp = 66, 128 number = 67, 129 difficulty = 68, 130 gaslimit = 69, 131 pop = 80, 132 mload = 81, 133 mstore = 82, 134 mstore8 = 83, 135 sload = 84, 136 sstore = 85, 137 jump = 86, 138 jumpi = 87, 139 pc = 88, 140 msize = 89, 141 gas = 90, 142 jumpdest = 91, 143 push1 = 96, 144 push2 = 97, 145 push3 = 98, 146 push4 = 99, 147 push5 = 100, 148 push6 = 101, 149 push7 = 102, 150 push8 = 103, 151 push9 = 104, 152 push10 = 105, 153 push11 = 106, 154 push12 = 107, 155 push13 = 108, 156 push14 = 109, 157 push15 = 110, 158 push16 = 111, 159 push17 = 112, 160 push18 = 113, 161 push19 = 114, 162 push20 = 115, 163 push21 = 116, 164 push22 = 117, 165 push23 = 118, 166 push24 = 119, 167 push25 = 120, 168 push26 = 121, 169 push27 = 122, 170 push28 = 123, 171 push29 = 124, 172 push30 = 125, 173 push31 = 126, 174 push32 = 127, 175 dup1 = 128, 176 dup2 = 129, 177 dup3 = 130, 178 dup4 = 131, 179 dup5 = 132, 180 dup6 = 133, 181 dup7 = 134, 182 dup8 = 135, 183 dup9 = 136, 184 dup10 = 137, 185 dup11 = 138, 186 dup12 = 139, 187 dup13 = 140, 188 dup14 = 141, 189 dup15 = 142, 190 dup16 = 143, 191 swap1 = 144, 192 swap2 = 145, 193 swap3 = 146, 194 swap4 = 147, 195 swap5 = 148, 196 swap6 = 149, 197 swap7 = 150, 198 swap8 = 151, 199 swap9 = 152, 200 swap10 = 153, 201 swap11 = 154, 202 swap12 = 155, 203 swap13 = 156, 204 swap14 = 157, 205 swap15 = 158, 206 swap16 = 159, 207 log0 = 160, 208 log1 = 161, 209 log2 = 162, 210 log3 = 163, 211 log4 = 164, 212 create = 240, 213 call = 241, 214 callcode = 242, 215 return_ = 243, 216 delegatecall = 244, 217 callblackbox = 245, 218 staticcall = 250, 219 revert = 253, 220 suicide = 255, 221 222 invalid = 512 223 } 224 225 /// Group of EVM instructions 226 enum EvmInstructionGroupId { 227 invalid = 0, // cs_grp_invalid 228 229 jump, // all jump instructions 230 231 math = 8, // math instructions 232 stack_write, // instructions write to stack 233 stack_read, // instructions read from stack 234 mem_write, // instructions write to memory 235 mem_read, // instructions read from memory 236 store_write, // instructions write to storage 237 store_read, // instructions read from storage 238 halt // instructions halt execution 239 }