Update docs

pull/2/head
Bernhard Mueller 7 years ago
parent ede936d811
commit ec3b7fc094
  1. 18
      README.md
  2. 1
      code.bin
  3. 1
      code_bin
  4. 1
      code_compiled
  5. 1
      incode
  6. 1
      lol
  7. 35
      mythril.py
  8. 6
      util.py

@ -51,14 +51,22 @@ The virtual machine language is described in the [Ethereum Yellowpaper](http://g
### Tracing EVM execution ### Tracing EVM execution
You can run a piece of bytecode in the [PyEthereum](https://github.com/ethereum/pyethereum) VM and trace its execution using the `-t` flag. This will output the instructions executed as well as the state of the stack for every execution step. You can run a piece of bytecode in the [PyEthereum](https://github.com/ethereum/pyethereum) VM and trace its execution using the `-t` flag. This will output the instructions executed as well as the state of the stack for every execution step. You can run code directly from the command line,.
```bash ```bash
$ ./mythril.py -t -c "0x606060405050" $ ./mythril.py -t -c "0x606060405050"
vm address=b'\x01#Eg\x89\xab\xcd\xef\x01#Eg\x89\xab\xcd\xef\x01#Eg' gas=b'1000000' storage={'storage': {}, 'balance': '0', 'nonce': '0', 'code': '0x'} steps=0 depth=0 pushvalue=96 stack=[] pc=b'0' op=PUSH1 inst=96 vm stack=[] op=PUSH1 steps=0 pc=b'0' address=b'\x01#Eg\x89\xab\xcd\xef\x01#Eg\x89\xab\xcd\xef\x01#Eg' depth=0 pushvalue=96 gas=b'1000000' storage={'code': '0x', 'nonce': '0', 'balance': '0', 'storage': {}} inst=96
vm gas=b'999997' steps=1 depth=0 pushvalue=64 stack=[b'96'] pc=b'2' op=PUSH1 inst=96 vm stack=[b'96'] op=PUSH1 steps=1 depth=0 pushvalue=64 gas=b'999997' pc=b'2' inst=96
vm gas=b'999994' steps=2 depth=0 stack=[b'96', b'64'] pc=b'4' op=POP inst=80 vm stack=[b'96', b'64'] op=POP steps=2 depth=0 gas=b'999994' pc=b'4' inst=80
vm gas=b'999992' steps=3 depth=0 stack=[b'96'] pc=b'5' op=POP inst=80 vm stack=[b'96'] op=POP steps=3 depth=0 gas=b'999992' pc=b'5' inst=80
```
For larger contracts, you might prefer to compile them to a binary file instead:
```
$ ./mythril.py -a contract.easm -o contract.bin
$ ./mythril.py --trace -f contract.bin
``` ```
### Disassembling a contract from the Ethereum blockchain ### Disassembling a contract from the Ethereum blockchain

@ -0,0 +1 @@
a4050c60708090PP

@ -0,0 +1 @@
`60`40PP

@ -0,0 +1 @@
`60`40PP

@ -0,0 +1 @@
0x606060405050

1
lol

@ -0,0 +1 @@
`60`40PP

@ -18,11 +18,12 @@ def exitWithError(message):
parser = argparse.ArgumentParser(description='Ethereum VM bytecode assembler/ disassembler') parser = argparse.ArgumentParser(description='Ethereum VM bytecode assembler/ disassembler')
parser.add_argument('-d', '--disassemble', action='store_true', help='disassemble, use with -c or --txid') parser.add_argument('-d', '--disassemble', action='store_true', help='disassemble, use with -c, -f or --txid')
parser.add_argument('-a', '--assemble', help='produce bytecode from easm input file', metavar='INPUT FILE') parser.add_argument('-a', '--assemble', help='produce bytecode from easm input file', metavar='INPUTFILE')
parser.add_argument('-t', '--trace', action='store_true', help='trace bytecode provided via the -c argument') parser.add_argument('-t', '--trace', action='store_true', help='trace bytecode provided via the -c or -f argument')
parser.add_argument('-c', '--code', help='bytecode string ("6060604052...")', metavar='BYTECODE') parser.add_argument('-c', '--code', help='hex-encoded bytecode string ("6060604052...")', metavar='BYTECODE')
parser.add_argument('-o', '--outfile') parser.add_argument('-o', '--outfile')
parser.add_argument('-f', '--infile', metavar='INPUTFILE')
parser.add_argument('--txid', help='id of contract creation transaction') parser.add_argument('--txid', help='id of contract creation transaction')
parser.add_argument('--rpchost', default='127.0.0.1', help='RPC host') parser.add_argument('--rpchost', default='127.0.0.1', help='RPC host')
parser.add_argument('--rpcport', type=int, default=8545, help='RPC port') parser.add_argument('--rpcport', type=int, default=8545, help='RPC port')
@ -43,8 +44,17 @@ if (args.disassemble):
except Exception as e: except Exception as e:
exitWithError("Exception loading bytecode via RPC" + str(e.message)) exitWithError("Exception loading bytecode via RPC" + str(e.message))
elif (args.infile):
try:
encoded_bytecode = util.file_to_string(args.infile).rstrip()
except Exception as e:
exitWithError("Exception loading bytecode from file" + str(e.message))
else: else:
exitWithError("Disassembler: Provide the input bytecode via the -c or --txid arguments") exitWithError("Disassembler: Provide the input bytecode via -c BYTECODE, -f INPUT_FILE or --txid TXID")
disassembly = asm.disassemble(util.safe_decode(encoded_bytecode)) disassembly = asm.disassemble(util.safe_decode(encoded_bytecode))
@ -72,10 +82,21 @@ elif (args.trace):
if args.code: if args.code:
evm.trace(util.safe_decode(args.code)) bytecode = util.safe_decode(args.code)
elif (args.infile):
try:
bytecode = util.file_to_raw_bytes(args.infile)
except Exception as e:
exitWithError("Exception loading bytecode from file" + str(e.message))
else: else:
exitWithError("Trace: Provide the input bytecode using -c <bytecode>") exitWithError("Trace: Provide the input bytecode using -c BYTECODE or -f INPUT_FILE")
evm.trace(bytecode)
else: else:
parser.print_help() parser.print_help()

@ -30,6 +30,12 @@ def raw_bytes_to_file(filename, bytestring):
f.write(bytestring) f.write(bytestring)
def file_to_raw_bytes(filename):
with open(filename, 'rb') as f:
data = f.read()
return data
def string_to_file(filename, string): def string_to_file(filename, string):
with open(filename, 'w') as f: with open(filename, 'w') as f:
f.write(string) f.write(string)

Loading…
Cancel
Save