Security analysis tool for EVM bytecode. Supports smart contracts built for Ethereum, Hedera, Quorum, Vechain, Roostock, Tron and other EVM-compatible blockchains.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mythril/ether/util.py

48 lines
1.1 KiB

from rpc.client import EthJsonRpc
import codecs
7 years ago
def safe_decode(hex_encoded_string):
if (hex_encoded_string.startswith("0x")):
return codecs.decode(hex_encoded_string[2:], 'hex_codec')
7 years ago
else:
return codecs.decode(hex_encoded_string, 'hex_codec')
7 years ago
def bytecode_from_blockchain(creation_tx_hash, rpc_host='127.0.0.1', rpc_port=8545):
"""Load bytecode from a local node via
creation_tx_hash = ID of transaction that created the contract.
"""
eth = EthJsonRpc(rpc_host, rpc_port)
7 years ago
trace = eth.traceTransaction(creation_tx_hash)
if trace['returnValue']:
return trace['returnValue']
raise RuntimeError("Transaction trace didn't return any bytecode")
def raw_bytes_to_file(filename, bytestring):
with open(filename, 'wb') as f:
f.write(bytestring)
7 years ago
def file_to_raw_bytes(filename):
with open(filename, 'rb') as f:
data = f.read()
return data
7 years ago
def string_to_file(filename, string):
with open(filename, 'w') as f:
f.write(string)
7 years ago
def file_to_string(filename):
with open(filename, 'r') as f:
data = f.read()
return data