mirror of https://github.com/ConsenSys/mythril
blockchainethereumsmart-contractssoliditysecurityprogram-analysissecurity-analysissymbolic-execution
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.
48 lines
1.1 KiB
48 lines
1.1 KiB
7 years ago
|
from rpc.client import EthJsonRpc
|
||
7 years ago
|
import codecs
|
||
7 years ago
|
|
||
|
|
||
|
def safe_decode(hex_encoded_string):
|
||
|
if (hex_encoded_string.startswith("0x")):
|
||
7 years ago
|
return codecs.decode(hex_encoded_string[2:], 'hex_codec')
|
||
7 years ago
|
else:
|
||
7 years ago
|
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.
|
||
|
"""
|
||
|
|
||
7 years ago
|
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")
|
||
|
|
||
|
|
||
7 years ago
|
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):
|
||
7 years ago
|
with open(filename, 'w') as f:
|
||
|
f.write(string)
|
||
7 years ago
|
|
||
|
|
||
|
def file_to_string(filename):
|
||
7 years ago
|
with open(filename, 'r') as f:
|
||
|
data = f.read()
|
||
|
return data
|