Skip to content

Commit

Permalink
First working example
Browse files Browse the repository at this point in the history
  • Loading branch information
guedou committed Dec 17, 2017
0 parents commit b8df796
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
3 changes: 3 additions & 0 deletions kernel_spec/kernel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"argv":["python","-m","radare2", "-f", "{connection_file}"],
"display_name":"radare2"
}
57 changes: 57 additions & 0 deletions radare2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright (C) 2017 Guillaume Valadon <[email protected]>

"""
A Jupyter kernel for radare2
"""


import r2pipe

from ipykernel.kernelbase import Kernel
from ipykernel.kernelapp import IPKernelApp


class Radare2Kernel(Kernel):
"""radare2 Jupyter kernel"""

# Kernel information
implementation = "radare2"
implementation_version = "0.1"
banner = "radare2 Jupyter kernel"

# Language information
language_info = {
"name": "radare2",
"mimetype": "text/plain",
"file_extension": ".r2",
}



def _get_r2pipe(self):
"""Get the r2pipe handle"""

if not hasattr(self, "r2"):
self.r2 = r2pipe.open("-")

def do_execute(self, code, silent, store_history=True, user_expressions=None,
allow_stdin=False):
"""Execute a radare2 commmand using r2pipe"""

self._get_r2pipe()

if not silent:
result = self.r2.cmd(code)
print result
stream = {"name": "stdout", "text": result}
self.send_response(self.iopub_socket, "stream", stream)

return {"status": "ok",
"execution_count": self.execution_count,
"payload": [],
"user_expressions": {},
}


if __name__ == "__main__":
IPKernelApp.launch_instance(kernel_class=Radare2Kernel)
22 changes: 22 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (C) 2017 Guillaume Valadon <[email protected]>


import os
import json
from setuptools import setup

from jupyter_client.kernelspec import install_kernel_spec
from IPython.utils.tempdir import TemporaryDirectory


setup(name="jupyter_radare2",
description="A Jupyter radare2 kernel",
author="Guillaume Valadon",
author_email="[email protected]",
version="0.1",
url="https://github.com/guedou/jupyter_radare2",
py_modules=["radare2"],
)


install_kernel_spec("./kernel_spec", "radare2", user=True, replace=True)

0 comments on commit b8df796

Please sign in to comment.