storage can read more elements and also arrays

pull/48/head
Gerhard Wagner 7 years ago
parent 57593f8d66
commit 0961339f93
  1. 1
      .gitignore
  2. 30
      myth

1
.gitignore vendored

@ -12,3 +12,4 @@ dist
*.svg *.svg
laser* laser*
lol* lol*
.idea*

30
myth

@ -17,6 +17,7 @@ from mythril.exceptions import CompilerError
from mythril.analysis.symbolic import StateSpace from mythril.analysis.symbolic import StateSpace
from mythril.analysis.callgraph import generate_graph from mythril.analysis.callgraph import generate_graph
from mythril.analysis.security import fire_lasers from mythril.analysis.security import fire_lasers
from web3 import Web3
from ethereum import utils from ethereum import utils
from pathlib import Path from pathlib import Path
from json.decoder import JSONDecodeError from json.decoder import JSONDecodeError
@ -52,7 +53,7 @@ commands.add_argument('-t', '--trace', action='store_true', help='trace contract
commands.add_argument('-s', '--search', help='search the contract database', metavar='EXPRESSION') commands.add_argument('-s', '--search', help='search the contract database', metavar='EXPRESSION')
commands.add_argument('--xrefs', action='store_true', help='get xrefs from a contract') commands.add_argument('--xrefs', action='store_true', help='get xrefs from a contract')
commands.add_argument('--hash', help='calculate function signature hash', metavar='SIGNATURE') commands.add_argument('--hash', help='calculate function signature hash', metavar='SIGNATURE')
commands.add_argument('--storage', help='read data from storage index, use with -a', metavar='INDEX') commands.add_argument('--storage', help='read state variables from storage index (index,length,array(in case of arrays)), use with -a', metavar='INDEX')
commands.add_argument('--init-db', action='store_true', help='initialize the contract database') commands.add_argument('--init-db', action='store_true', help='initialize the contract database')
inputs = parser.add_argument_group('input arguments') inputs = parser.add_argument_group('input arguments')
@ -235,12 +236,33 @@ if args.storage:
if not args.address: if not args.address:
exitWithError("To read storage, provide the address of a deployed contract with the -a option.") exitWithError("To read storage, provide the address of a deployed contract with the -a option.")
else: else:
position = 0
length = 1
array = 0
try: try:
position = int(args.storage) params = (args.storage).split(",")
if len(params) >= 1 and len(params) <= 3:
position = int(params[0])
if len(params) >= 2 and len(params) <= 3:
print(len(params))
if len(params) == 3:
if re.match("array",params[2]):
array = 1
if len(params) >= 4:
exitWithError("Invalid amount of parameters.")
except ValueError: except ValueError:
exitWithError("Invalid storage index. Please provide a numeric value.") exitWithError("Invalid storage index. Please provide a numeric value.")
if array:
position_formated = str(position).zfill(64)
position = int(Web3.sha3(position_formated),16)
print(eth.eth_getStorageAt(args.address, position=position, block='latest')) if length == 1:
print("{}: ".format(position) + eth.eth_getStorageAt(args.address, position));
else:
for i in range(position, position + length):
print("{}: ".format(hex(i)) + eth.eth_getStorageAt(args.address, i));
elif (args.disassemble): elif (args.disassemble):

Loading…
Cancel
Save