|
1 | 1 | # pyevmasm |
2 | 2 |
|
3 | | -pyevmasm is an assembler and disassembler library for the Ethereum Virtual Machine (EVM). pyevmasm supports python 2.7 and newer. |
| 3 | +pyevmasm is an assembler and disassembler library for the Ethereum Virtual Machine (EVM). pyevmasm supports python 2.7 and newer. You can find the documentation [here](rtdlink). |
4 | 4 |
|
5 | 5 | This library is currently new and under development. |
6 | 6 |
|
7 | 7 | New issues, feature requests, and contributions are welcome. Join us in #ethereum channel on the [Empire Hacking Slack](https://empireslacking.herokuapp.com) to discuss Ethereum security tool development. |
8 | 8 |
|
| 9 | + |
| 10 | +Example; |
| 11 | +``` |
| 12 | +>>> from pyevmasm import instruction_table, disassemble_hex, disassemble_all, assemble_hex |
| 13 | +>>> instruction_table[20] |
| 14 | +Instruction(0x14, 'EQ', 0, 2, 1, 3, 'Equality comparision.', None, 0) |
| 15 | +>>> instruction_table['EQ'] |
| 16 | +Instruction(0x14, 'EQ', 0, 2, 1, 3, 'Equality comparision.', None, 0) |
| 17 | +>>> instrs = list(disassemble_all(binascii.unhexlify('608060405260043610603f57600035'))) |
| 18 | +>>> instrs.insert(1, instruction_table['JUMPI']) |
| 19 | +>>> a = assemble_hex(instrs) |
| 20 | +>>> a |
| 21 | +'0x60805760405260043610603f57600035' |
| 22 | +>>> print(disassemble_hex(a)) |
| 23 | +PUSH1 0x80 |
| 24 | +JUMPI |
| 25 | +PUSH1 0x40 |
| 26 | +MSTORE |
| 27 | +... |
| 28 | +>>> assemble_hex('PUSH1 0x40\nMSTORE\n') |
| 29 | +'0x604052' |
| 30 | +``` |
| 31 | + |
9 | 32 | # evmasm |
10 | | -evmasm is a commandline utility that uses pyevmasm to assemble or disassemble EVM. Below is an example of disassembling the preamble of compiled contract. |
| 33 | +evmasm is a commandline utility that uses pyevmasm to assemble or disassemble EVM. |
| 34 | + |
| 35 | +``` |
| 36 | +usage: evmasm [-h] (-a | -d | -t) [-bi] [-bo] [-i [INPUT]] [-o [OUTPUT]] |
| 37 | +
|
| 38 | +pyevmasm the EVM assembler and disassembler |
| 39 | +
|
| 40 | +optional arguments: |
| 41 | + -h, --help show this help message and exit |
| 42 | + -a, --assemble Assemble EVM instructions to opcodes |
| 43 | + -d, --disassemble Disassemble EVM to opcodes |
| 44 | + -t, --print-opcode-table |
| 45 | + List supported EVM opcodes |
| 46 | + -bi, --binary-input Binary input mode (-d only) |
| 47 | + -bo, --binary-output Binary output mode (-a only) |
| 48 | + -i [INPUT], --input [INPUT] |
| 49 | + Input file, default=stdin |
| 50 | + -o [OUTPUT], --output [OUTPUT] |
| 51 | + Output file, default=stdout |
| 52 | +``` |
| 53 | + |
11 | 54 |
|
| 55 | +Example; disassembling the preamble of compiled contract. |
12 | 56 | ``` |
13 | 57 | $ echo -n "608060405260043610603f57600035" | evmasm -d |
14 | 58 | 00000000: PUSH1 0x80 |
|
0 commit comments