Skip to content

Commit

Permalink
Merge pull request #5 from defunctio/refactor
Browse files Browse the repository at this point in the history
release cleanup
  • Loading branch information
dguido authored Jul 17, 2018
2 parents 9434915 + 8c6368b commit 66b8b46
Show file tree
Hide file tree
Showing 14 changed files with 1,002 additions and 660 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ celerybeat-schedule
# virtualenv
.venv
venv/
venv36/
ENV/

# Spyder project settings
Expand Down
55 changes: 50 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,53 @@
# pyevmasm

pyevmasm is an assembler and disassembler library for the Ethereum Virtual Machine (EVM). pyevmasm supports python 2.7 and newer.
pyevmasm is an assembler and disassembler library for the Ethereum Virtual Machine (EVM).

This library is currently new and under development.
## Examples
```
>>> from pyevmasm import instruction_table, disassemble_hex, disassemble_all, assemble_hex
>>> instruction_table[20]
Instruction(0x14, 'EQ', 0, 2, 1, 3, 'Equality comparision.', None, 0)
>>> instruction_table['EQ']
Instruction(0x14, 'EQ', 0, 2, 1, 3, 'Equality comparision.', None, 0)
>>> instrs = list(disassemble_all(binascii.unhexlify('608060405260043610603f57600035')))
>>> instrs.insert(1, instruction_table['JUMPI'])
>>> a = assemble_hex(instrs)
>>> a
'0x60805760405260043610603f57600035'
>>> print(disassemble_hex(a))
PUSH1 0x80
JUMPI
PUSH1 0x40
MSTORE
...
>>> assemble_hex('PUSH1 0x40\nMSTORE\n')
'0x604052'
```

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.
## evmasm
`evmasm` is a commandline utility that uses pyevmasm to assemble or disassemble EVM.

# evmasm
evmasm is a commandline utility that uses pyevmasm to assemble or disassemble EVM. Below is an example of disassembling the preamble of compiled contract.
```
usage: evmasm [-h] (-a | -d | -t) [-bi] [-bo] [-i [INPUT]] [-o [OUTPUT]]
pyevmasm the EVM assembler and disassembler
optional arguments:
-h, --help show this help message and exit
-a, --assemble Assemble EVM instructions to opcodes
-d, --disassemble Disassemble EVM to opcodes
-t, --print-opcode-table
List supported EVM opcodes
-bi, --binary-input Binary input mode (-d only)
-bo, --binary-output Binary output mode (-a only)
-i [INPUT], --input [INPUT]
Input file, default=stdin
-o [OUTPUT], --output [OUTPUT]
Output file, default=stdout
```


Example; disassembling the preamble of compiled contract.
```
$ echo -n "608060405260043610603f57600035" | evmasm -d
00000000: PUSH1 0x80
Expand All @@ -25,6 +64,8 @@ $ echo -n "608060405260043610603f57600035" | evmasm -d

# Installation

Python >=2.7 or Python >=3.3 is required.

Install the latest stable version using pip:
```
pip install pyevmasm
Expand All @@ -37,3 +78,7 @@ cd pyevmasm
python setup.py install
```

## Documentation
[https://pyevmasm.readthedocs.io](https://pyevmasm.readthedocs.io)

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.
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = pyevmasm
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
10 changes: 10 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
API Reference
=============

evmasm
------
.. automodule:: pyevmasm.evmasm
:members:
.. py:data:: instruction
Instance of InstructionTable for EVM. (see; InstructionTable)
156 changes: 156 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------

project = 'pyevmasm'
copyright = '2018, Trail of Bits'
author = 'Trail of Bits'

# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = ''


# -- General configuration ---------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.todo', 'sphinx.ext.viewcode', 'sphinx.ext.autodoc'
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path .
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself. Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
# html_sidebars = {}


# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'pyevmasmdoc'


# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'pyevmasm.tex', 'pyevmasm Documentation',
'Trail of Bits', 'manual'),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'pyevmasm', 'pyevmasm Documentation',
[author], 1)
]


# -- Options for Texinfo output ----------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'pyevmasm', 'pyevmasm Documentation',
author, 'pyevmasm', 'One line description of project.',
'Miscellaneous'),
]
21 changes: 21 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.. pyevmasm documentation master file, created by
sphinx-quickstart on Wed Jul 11 19:50:09 2018.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to pyevmasm's documentation!
====================================

.. toctree::
:maxdepth: 2
:caption: Contents:

api


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
59 changes: 0 additions & 59 deletions evmasm

This file was deleted.

4 changes: 3 additions & 1 deletion pyevmasm/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .evmasm import EVMAsm
from .evmasm import instruction_table, Instruction # noqa: F401
from .evmasm import assemble, assemble_all, assemble_hex, assemble_one
from .evmasm import disassemble, disassemble_all, disassemble_hex, disassemble_one
Loading

0 comments on commit 66b8b46

Please sign in to comment.