{ "cells": [ { "cell_type": "markdown", "metadata": { "button": false, "new_sheet": false, "run_control": { "read_only": false }, "slideshow": { "slide_type": "slide" } }, "source": [ "# Using Fuzzingbook Code in your own Programs\n", "\n", "This notebook has instructions on how to use the fuzzingbook code in your own programs." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Can I import the code for my own Python projects?\n", "\n", "Yes, you can! (If you like Python, that is.) We provide a `fuzzingbook` Python package that you can install using the `pip` package manager:\n", "\n", "```shell\n", "$ pip install fuzzingbook\n", "```\n", "\n", "Once this is installed, you can import individual classes, constants, or functions from each notebook using\n", "\n", "```python\n", ">>> from fuzzingbook. import \n", "```\n", "\n", "where `` is the name of the class, constant, or function to use, and `` is the name of the respective notebook. (If you read this at fuzzingbook.org, then the notebook name is the identifier preceding `\".html\"` in the URL).\n", "\n", "Here is an example importing `RandomFuzzer` from [the chapter on fuzzers](Fuzzer.ipynb), whose notebook name is `Fuzzer`:\n", "\n", "```python\n", ">>> from fuzzingbook.Fuzzer import RandomFuzzer\n", ">>> f = RandomFuzzer()\n", ">>> f.fuzz()\n", "'!7#%\"*#0=)$;%6*;>638:*>80\"=(/*:-(2<4 !:5*6856&?\"\"11<7+%<%7,4.8,*+&,,$,.\"5%<%76< -5'\n", "```\n", "\n", "The \"Synopsis\" section at the beginning of a chapter gives a short survey on useful code features you can use." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Can I use the code from within a Jupyter notebook?\n", "\n", "Yes, you can! You would first install the `fuzzingbook` package (as above); you can then access all code right from your notebook.\n", "\n", "Another way to use the code is to _import the notebooks directly_. Download the notebooks from the menu. Then, add your own notebooks into the same folder. After importing `fuzzingbook_utils`, you can then simply import the code from other notebooks, just as our own notebooks do.\n", "\n", "Here is again the above example, importing `RandomFuzzer` from [the chapter on fuzzers](Fuzzer.ipynb) – but now from a notebook:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "import fuzzingbook_utils" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [], "source": [ "from Fuzzer import RandomFuzzer" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "data": { "text/plain": [ "'!7#%\"*#0=)$;%6*;>638:*>80\"=(/*:-(2<4 !:5*6856&?\"\"11<7+%<%7,4.8,*+&,,$,.\"5%<%76< -5'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f = RandomFuzzer()\n", "f.fuzz()" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "If you'd like to share your notebook, let us know; we can integrate it in the repository or even in the book." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Can I just run the Python code? I mean, without notebooks?\n", "\n", "Yes, you can! (Although we'd always recommend executing the notebooks instead – they have all the text, and far richer inputs and outputs.) You can download the code as Python programs; simply select \"Resources $\\rightarrow$ Download Code\" for one chapter or \"Resources $\\rightarrow$ All Code\" for all chapters. These code files can be executed, yielding (hopefully) the same results as the notebooks.\n", "\n", "The code files can also be edited if you wish, but (a) they are very obviously generated from notebooks, (b) therefore not much fun to work with, and (c) if you fix any errors, you'll have to back-propagate them to the notebook before you can make a pull request. Use code files only under severely constrained circumstances." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Which other packages do I need to use the Python modules?\n", "\n", "We have attempted to limit the dependencies to a minimum (sometimes using ugly hacks). Generally speaking, if you encounter that a module `X` is not found, just do `pip install X`. Most notebooks (notably, the generic fuzzers) only need modules that are part of the standard Python library.\n", "\n", "For a full list of dependencies, see the [configuration files within the `binder` folder in the project repository](https://github.com/uds-se/fuzzingbook/tree/master/binder); these list all Linux and Python packages required." ] } ], "metadata": { "ipub": { "bibliography": "fuzzingbook.bib", "toc": true }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.8" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": true, "title_cell": "", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": true }, "toc-autonumbering": false }, "nbformat": 4, "nbformat_minor": 2 }