1
1
# pyevmasm
2
2
3
- pyevmasm is an assembler and disassembler library for the Ethereum Virtual Machine (EVM).
3
+ pyevmasm is an assembler and disassembler library for the Ethereum Virtual Machine (EVM). It includes a commandline utility and a Python API.
4
4
5
- ## Examples
6
- ```
7
- >>> from pyevmasm import instruction_table, disassemble_hex, disassemble_all, assemble_hex
8
- >>> instruction_table[20]
9
- Instruction(0x14, 'EQ', 0, 2, 1, 3, 'Equality comparision.', None, 0)
10
- >>> instruction_table['EQ']
11
- Instruction(0x14, 'EQ', 0, 2, 1, 3, 'Equality comparision.', None, 0)
12
- >>> instrs = list(disassemble_all(binascii.unhexlify('608060405260043610603f57600035')))
13
- >>> instrs.insert(1, instruction_table['JUMPI'])
14
- >>> a = assemble_hex(instrs)
15
- >>> a
16
- '0x60805760405260043610603f57600035'
17
- >>> print(disassemble_hex(a))
18
- PUSH1 0x80
19
- JUMPI
20
- PUSH1 0x40
21
- MSTORE
22
- ...
23
- >>> assemble_hex('PUSH1 0x40\nMSTORE\n')
24
- '0x604052'
25
- ```
5
+ ## CLI Examples with evmasm
26
6
27
- ## evmasm
28
- ` evmasm ` is a commandline utility that uses pyevmasm to assemble or disassemble EVM.
7
+ ` evmasm ` is a commandline utility that uses pyevmasm to assemble or disassemble EVM:
29
8
30
9
```
31
10
usage: evmasm [-h] (-a | -d | -t) [-bi] [-bo] [-i [INPUT]] [-o [OUTPUT]]
@@ -46,8 +25,8 @@ optional arguments:
46
25
Output file, default=stdout
47
26
```
48
27
28
+ Disassembling the preamble of compiled contract:
49
29
50
- Example; disassembling the preamble of compiled contract.
51
30
```
52
31
$ echo -n "608060405260043610603f57600035" | evmasm -d
53
32
00000000: PUSH1 0x80
@@ -62,6 +41,29 @@ $ echo -n "608060405260043610603f57600035" | evmasm -d
62
41
0000000e: CALLDATALOAD
63
42
```
64
43
44
+ ## Python API Examples
45
+
46
+ ```
47
+ >>> from pyevmasm import instruction_table, disassemble_hex, disassemble_all, assemble_hex
48
+ >>> instruction_table[20]
49
+ Instruction(0x14, 'EQ', 0, 2, 1, 3, 'Equality comparision.', None, 0)
50
+ >>> instruction_table['EQ']
51
+ Instruction(0x14, 'EQ', 0, 2, 1, 3, 'Equality comparision.', None, 0)
52
+ >>> instrs = list(disassemble_all(binascii.unhexlify('608060405260043610603f57600035')))
53
+ >>> instrs.insert(1, instruction_table['JUMPI'])
54
+ >>> a = assemble_hex(instrs)
55
+ >>> a
56
+ '0x60805760405260043610603f57600035'
57
+ >>> print(disassemble_hex(a))
58
+ PUSH1 0x80
59
+ JUMPI
60
+ PUSH1 0x40
61
+ MSTORE
62
+ ...
63
+ >>> assemble_hex('PUSH1 0x40\nMSTORE\n')
64
+ '0x604052'
65
+ ```
66
+
65
67
# Installation
66
68
67
69
Python >=2.7 or Python >=3.3 is required.
@@ -71,14 +73,15 @@ Install the latest stable version using pip:
71
73
pip install pyevmasm
72
74
```
73
75
74
- To install the library from source:
76
+ Or, install the library from source:
75
77
```
76
78
git clone https://github.com/trailofbits/pyevmasm
77
79
cd pyevmasm
78
80
python setup.py install
79
81
```
80
82
81
83
## Documentation
84
+
82
85
[ https://pyevmasm.readthedocs.io ] ( https://pyevmasm.readthedocs.io )
83
86
84
87
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.
0 commit comments