Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for new EVM opcodes #23878

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions libr/arch/p/evm/evm.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ static const EvmOpDef opcodes[256] = {
[EVM_OP_GASLIMIT] = { "gaslimit", 1 },
[EVM_OP_CHAINID] = { "chainid", 1 },
[EVM_OP_SELFBALANCE] = { "selfbalance", 1 },
[EVM_OP_BASEFEE] = { "basefee", 1 },
[EVM_OP_BLOBHASH] = { "blobhash", 1 },
[EVM_OP_BLOBBASEFEE] = { "blobbasefee", 1 },
[EVM_OP_POP] = { "pop", 1 },
[EVM_OP_MLOAD] = { "mload", 1 },
[EVM_OP_MSTORE] = { "mstore", 1 },
Expand All @@ -70,6 +73,10 @@ static const EvmOpDef opcodes[256] = {
[EVM_OP_MSIZE] = { "msize", 1 },
[EVM_OP_GAS] = { "gas", 1 },
[EVM_OP_JUMPDEST] = { "jumpdest", 1 },
[EVM_OP_TLOAD] = { "tload", 1 },
[EVM_OP_TSTORE] = { "tstore", 1 },
[EVM_OP_MCOPY] = { "mcopy", 1 },
[EVM_OP_PUSH0] = { "push0", 1 },
// ....
[EVM_OP_CREATE] = { "create", 1 },
[EVM_OP_CALL] = { "call", 1 },
Expand Down
6 changes: 6 additions & 0 deletions libr/arch/p/evm/evm.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ typedef enum {
EVM_OP_CHAINID,
EVM_OP_SELFBALANCE,
EVM_OP_BASEFEE,
EVM_OP_BLOBHASH,
EVM_OP_BLOBBASEFEE,

EVM_OP_POP = 0x50,
EVM_OP_MLOAD,
Expand All @@ -71,7 +73,11 @@ typedef enum {
EVM_OP_MSIZE,
EVM_OP_GAS,
EVM_OP_JUMPDEST,
EVM_OP_TLOAD,
EVM_OP_TSTORE,
EVM_OP_MCOPY,

EVM_OP_PUSH0 = 0x5f,
EVM_OP_PUSH1 = 0x60,
EVM_OP_PUSH2,
EVM_OP_PUSH3,
Expand Down
118 changes: 87 additions & 31 deletions libr/arch/p/evm/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,27 @@ static bool decode(RArchSession *s, RAnalOp *op, RAnalOpMask mask) {
case EVM_INS_SMOD:
op->type = R_ANAL_OP_TYPE_MOD;
break;
case EVM_INS_SHL:
op->type = R_ANAL_OP_TYPE_SHL;
break;
case EVM_INS_SHR:
op->type = R_ANAL_OP_TYPE_SHR;
break;
case EVM_INS_SAR:
op->type = R_ANAL_OP_TYPE_SAR;
break;
case EVM_INS_ADD:
case EVM_INS_ADDMOD:
op->type = R_ANAL_OP_TYPE_ADD;
break;
case EVM_INS_LT:
case EVM_INS_GT:
case EVM_INS_SLT:
case EVM_INS_SGT:
case EVM_INS_EQ:
case EVM_INS_ISZERO:
op->type = R_ANAL_OP_TYPE_CMP;
break;
case EVM_INS_JUMP:
op->type = R_ANAL_OP_TYPE_JMP;
op->fail = op->addr + 1;
Expand All @@ -144,50 +165,38 @@ static bool decode(RArchSession *s, RAnalOp *op, RAnalOpMask mask) {
break;
case EVM_INS_MLOAD:
case EVM_INS_SLOAD:
case EVM_INS_TLOAD:
case EVM_INS_MCOPY:
op->type = R_ANAL_OP_TYPE_LOAD;
break;
case EVM_INS_MSTORE:
case EVM_INS_MSTORE8:
case EVM_INS_SSTORE:
case EVM_INS_TSTORE:
op->type = R_ANAL_OP_TYPE_STORE;
break;
case EVM_INS_LT:
case EVM_INS_GT:
case EVM_INS_SLT:
case EVM_INS_SGT:
case EVM_INS_EQ:
case EVM_INS_ISZERO:
op->type = R_ANAL_OP_TYPE_CMP;
break;
case EVM_INS_COINBASE:
case EVM_INS_BLOCKHASH:
break;
case EVM_INS_SHA3:
op->type = R_ANAL_OP_TYPE_CRYPTO;
break;
case EVM_INS_CODECOPY:
case EVM_INS_SWAP1:
case EVM_INS_SWAP2:
case EVM_INS_SWAP3:
case EVM_INS_SWAP4:
case EVM_INS_SWAP5:
case EVM_INS_SWAP6:
case EVM_INS_SWAP7:
case EVM_INS_SWAP8:
case EVM_INS_SWAP9:
case EVM_INS_SWAP10:
case EVM_INS_SWAP11:
case EVM_INS_SWAP12:
op->type = R_ANAL_OP_TYPE_MOV;
break;
case EVM_INS_GAS:
op->type = R_ANAL_OP_TYPE_MOV;
break;
case EVM_INS_MUL:
case EVM_INS_EXP:
case EVM_INS_MULMOD:
op->type = R_ANAL_OP_TYPE_MUL;
break;
case EVM_INS_STOP:
case EVM_INS_SUICIDE:
op->type = R_ANAL_OP_TYPE_TRAP;
break;
case EVM_INS_DELEGATECALL:
case EVM_INS_CALLDATACOPY:
case EVM_INS_CALLDATALOAD:
op->type = R_ANAL_OP_TYPE_CALL;
break;
case EVM_INS_DIV:
case EVM_INS_SDIV:
op->type = R_ANAL_OP_TYPE_DIV;
Expand All @@ -204,6 +213,55 @@ static bool decode(RArchSession *s, RAnalOp *op, RAnalOpMask mask) {
case EVM_INS_NOT:
op->type = R_ANAL_OP_TYPE_NOT;
break;
case EVM_INS_STOP:
case EVM_INS_SELFDESTRUCT:
op->type = R_ANAL_OP_TYPE_TRAP;
break;
case EVM_INS_CREATE:
case EVM_INS_CREATE2:
op->type = R_ANAL_OP_TYPE_NEW;
break;
case EVM_INS_CALL:
case EVM_INS_CALLCODE:
case EVM_INS_DELEGATECALL:
case EVM_INS_STATICCALL:
op->type = R_ANAL_OP_TYPE_CALL;
break;
case EVM_INS_CODESIZE:
case EVM_INS_CALLDATASIZE:
case EVM_INS_EXTCODESIZE:
case EVM_INS_RETURNDATASIZE:
op->type = R_ANAL_OP_TYPE_LENGTH;
break;
case EVM_INS_CODECOPY:
case EVM_INS_EXTCODECOPY:
case EVM_INS_RETURNDATACOPY:
case EVM_INS_CALLDATACOPY:
case EVM_INS_CALLDATALOAD:
case EVM_INS_ADDRESS:
case EVM_INS_BALANCE:
case EVM_INS_ORIGIN:
case EVM_INS_CALLER:
case EVM_INS_CALLVALUE:
case EVM_INS_GASPRICE:
case EVM_INS_BLOCKHASH:
case EVM_INS_COINBASE:
case EVM_INS_TIMESTAMP:
case EVM_INS_NUMBER:
case EVM_INS_DIFFICULTY:
case EVM_INS_GASLIMIT:
case EVM_INS_CHAINID:
case EVM_INS_SELFBALANCE:
case EVM_INS_BASEFEE:
case EVM_INS_BLOBHASH:
case EVM_INS_BLOBBASEFEE:
case EVM_INS_GAS:
op->type = R_ANAL_OP_TYPE_CRYPTO;
break;
case EVM_INS_PC:
case EVM_INS_MSIZE:
op->type = R_ANAL_OP_TYPE_RPUSH;
break;
case EVM_INS_REVERT:
case EVM_INS_RETURN:
op->type = R_ANAL_OP_TYPE_RET;
Expand All @@ -226,6 +284,11 @@ static bool decode(RArchSession *s, RAnalOp *op, RAnalOpMask mask) {
case EVM_INS_DUP16:
op->type = R_ANAL_OP_TYPE_PUSH;
break;
case EVM_INS_PUSH0:
esilprintf (op, "0x0,sp,=[1],32,sp,+=");
op->type = R_ANAL_OP_TYPE_PUSH;
evm_add_push_to_db (s, op, addr, buf, len);
break;
case EVM_INS_PUSH1:
esilprintf (op, "0x%s,sp,=[1],32,sp,+=", insn->op_str);
op->type = R_ANAL_OP_TYPE_PUSH;
Expand Down Expand Up @@ -291,16 +354,9 @@ static bool decode(RArchSession *s, RAnalOp *op, RAnalOpMask mask) {
op->type = R_ANAL_OP_TYPE_PUSH;
opsize = op->size = 33;
break;
case EVM_INS_ADD:
case EVM_INS_ADDMOD:
op->type = R_ANAL_OP_TYPE_ADD;
break;
case EVM_INS_POP:
op->type = R_ANAL_OP_TYPE_POP;
break;
case EVM_INS_CODESIZE:
op->type = R_ANAL_OP_TYPE_LENGTH;
break;
case EVM_INS_LOG0:
case EVM_INS_LOG1:
case EVM_INS_LOG2:
Expand Down
3 changes: 2 additions & 1 deletion shlr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ CS_TAR=https://codeload.github.com/capstone-engine/capstone/tar.gz/$(CS_VER)
CS_PATCHES=0
else
CS_TAR=
CS_URL_BASE=github.com/capstone-engine/capstone
# CS_URL_BASE=github.com/capstone-engine/capstone
CS_URL_BASE=github.com/andelf/capstone
CS_URL=$(GIT_PREFIX)$(CS_URL_BASE).git
CS_ARCHIVE=https://$(CS_URL_BASE)/archive
CS_UPD=20201203
Expand Down
Loading