├── LICENSE.txt
├── README.md
├── examples
├── radare2_kernel_test.ipynb
└── radare2_kernel_test.png
├── kernel_spec
└── kernel.json
├── radare2.py
└── setup.py
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # jupyter-radare2
2 |
3 | [](https://github.com/guedou/r2m2/releases)
4 | [](https://twitter.com/intent/follow?screen_name=guedou)
5 |
6 | This is a simple [radare2](https://github.com/radare/radare2)
7 | [Jupyter](http://jupyter.org/) kernel, that can be used to make interactive
8 | radare2 tutorials, or take advanced notes.
9 |
10 | ## Demos
11 |
12 | The kernel can be used either from a notebook or a console:
13 |
14 | [](https://github.com/guedou/jupyter-radare2/tree/master/examples/radare2_kernel_test.ipynb)
15 |
16 | ```
17 | jupyter console --kernel radare2
18 | Jupyter console 5.2.0
19 |
20 | radare2 Jupyter kernel
21 |
22 |
23 | In [1]: o /bin/ls
24 | 9
25 | In [2]: afl
26 |
27 | In [3]: afl~main
28 |
29 | In [4]: pd 5
30 | ;-- entry0:
31 | 0x00005430 31ed xor ebp, ebp
32 | 0x00005432 4989d1 mov r9, rdx
33 | 0x00005435 5e pop rsi
34 | 0x00005436 4889e2 mov rdx, rsp
35 | 0x00005439 4883e4f0 and rsp, 0xfffffffffffffff0
36 | In [5]:
37 | Do you really want to exit ([y]/n)? y
38 | Shutting down kernel
39 | ```
40 |
41 |
42 | ## Installing the kernel
43 |
44 | Check that `radare2` is present in your $PATH, then type:
45 | ```
46 | virtualenv ve_r2_kernel
47 | source ve_r2_kernel/bin/activate
48 | pip install jupyter r2pipe
49 | python setup.py install
50 | ```
51 |
52 | ## De-installing the kernel
53 |
54 | Simply type:
55 | ```
56 | deactivate
57 | rm -rf ve_r2_kernel
58 | rm -rf $HOME/.local/share/jupyter/kernels/radare2
59 | ```
60 |
--------------------------------------------------------------------------------
/examples/radare2_kernel_test.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "metadata": {
7 | "collapsed": false
8 | },
9 | "outputs": [
10 | {
11 | "name": "stdout",
12 | "output_type": "stream",
13 | "text": [
14 | "9"
15 | ]
16 | }
17 | ],
18 | "source": [
19 | "o /bin/ls"
20 | ]
21 | },
22 | {
23 | "cell_type": "code",
24 | "execution_count": 2,
25 | "metadata": {
26 | "collapsed": false
27 | },
28 | "outputs": [
29 | {
30 | "name": "stdout",
31 | "output_type": "stream",
32 | "text": [
33 | "arch x86\n",
34 | "binsz 128811\n",
35 | "bintype elf\n",
36 | "bits 64\n",
37 | "canary true\n",
38 | "class ELF64\n",
39 | "crypto false\n",
40 | "endian little\n",
41 | "havecode true\n",
42 | "intrp /lib64/ld-linux-x86-64.so.2\n",
43 | "lang c\n",
44 | "linenum false\n",
45 | "lsyms false\n",
46 | "machine AMD x86-64 architecture\n",
47 | "maxopsz 16\n",
48 | "minopsz 1\n",
49 | "nx true\n",
50 | "os linux\n",
51 | "pcalign 0\n",
52 | "pic true\n",
53 | "relocs false\n",
54 | "relro partial relro\n",
55 | "rpath NONE\n",
56 | "static false\n",
57 | "stripped true\n",
58 | "subsys linux\n",
59 | "va true"
60 | ]
61 | }
62 | ],
63 | "source": [
64 | "iI"
65 | ]
66 | },
67 | {
68 | "cell_type": "code",
69 | "execution_count": 3,
70 | "metadata": {
71 | "collapsed": false
72 | },
73 | "outputs": [
74 | {
75 | "name": "stdout",
76 | "output_type": "stream",
77 | "text": [
78 | ";-- entry0:\n",
79 | " 0x00005430 31ed xor ebp, ebp\n",
80 | " 0x00005432 4989d1 mov r9, rdx\n",
81 | " 0x00005435 5e pop rsi\n",
82 | " 0x00005436 4889e2 mov rdx, rsp\n",
83 | " 0x00005439 4883e4f0 and rsp, 0xfffffffffffffff0"
84 | ]
85 | }
86 | ],
87 | "source": [
88 | "pd 5"
89 | ]
90 | },
91 | {
92 | "cell_type": "code",
93 | "execution_count": 4,
94 | "metadata": {
95 | "collapsed": false
96 | },
97 | "outputs": [
98 | {
99 | "name": "stdout",
100 | "output_type": "stream",
101 | "text": []
102 | }
103 | ],
104 | "source": [
105 | "aaa"
106 | ]
107 | },
108 | {
109 | "cell_type": "code",
110 | "execution_count": 5,
111 | "metadata": {
112 | "collapsed": false
113 | },
114 | "outputs": [
115 | {
116 | "name": "stdout",
117 | "output_type": "stream",
118 | "text": []
119 | }
120 | ],
121 | "source": [
122 | "s fcn.main"
123 | ]
124 | },
125 | {
126 | "cell_type": "code",
127 | "execution_count": 6,
128 | "metadata": {
129 | "collapsed": false
130 | },
131 | "outputs": [
132 | {
133 | "name": "stdout",
134 | "output_type": "stream",
135 | "text": [
136 | "0x00003640 2 16 -> 48 sym.imp.textdomain\n",
137 | "0x00003680 2 16 -> 48 sym.imp.bindtextdomain\n",
138 | "0x00003bb0 8 337 main"
139 | ]
140 | }
141 | ],
142 | "source": [
143 | "afl~main"
144 | ]
145 | },
146 | {
147 | "cell_type": "code",
148 | "execution_count": 7,
149 | "metadata": {
150 | "collapsed": false
151 | },
152 | "outputs": [
153 | {
154 | "name": "stdout",
155 | "output_type": "stream",
156 | "text": [
157 | "- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF\n",
158 | "0x00003bb0 4157 4156 4155 4154 4189 fc55 5348 89f5 AWAVAUATA..USH..\n",
159 | "0x00003bc0 4883 ec48 488b 3e64 488b 0425 2800 0000 H..HH.>dH..%(...\n",
160 | "0x00003bd0 4889 4424 3831 c0e8 a4bb 0000 488d 35b2 H.D$81......H.5.\n",
161 | "0x00003be0 6901 00bf 0600 0000 e803 feff ff48 8d35 i............H.5\n",
162 | "0x00003bf0 2d3a 0100 488d 3d0c 3a01 00e8 80fa ffff -:..H.=.:.......\n",
163 | "0x00003c00 488d 3d00 3a01 00e8 34fa ffff 488d 3ded H.=.:...4...H.=.\n",
164 | "0x00003c10 8200 00c7 055b b921 0002 0000 00e8 fe1f .....[.!........\n",
165 | "0x00003c20 0100 48b8 0000 0000 0000 0080 c705 5ac8 ..H...........Z.\n",
166 | "0x00003c30 2100 0000 0000 c605 fbc8 2100 0148 8905 !.........!..H..\n",
167 | "0x00003c40 acc9 2100 8b05 16b9 2100 48c7 05ab c921 ..!.....!.H....!\n",
168 | "0x00003c50 0000 0000 0048 c705 98c9 2100 ffff ffff .....H....!.....\n",
169 | "0x00003c60 c605 f1c8 2100 0083 f802 0f84 1502 0000 ....!...........\n",
170 | "0x00003c70 83f8 0374 2f83 e801 7405 e8d1 f8ff ffbf ...t/...t.......\n",
171 | "0x00003c80 0100 0000 e827 f9ff ff85 c00f 8424 0b00 .....'.......$..\n",
172 | "0x00003c90 00c7 051d c921 0002 0000 00c6 05b6 c821 .....!.........!\n",
173 | "0x00003ca0 0001 eb16 be07 0000 0031 ffc7 0503 c921 .........1.....!"
174 | ]
175 | }
176 | ],
177 | "source": [
178 | "px 256 @ 0x00003bb0"
179 | ]
180 | }
181 | ],
182 | "metadata": {
183 | "kernelspec": {
184 | "display_name": "radare2",
185 | "language": "",
186 | "name": "radare2"
187 | },
188 | "language_info": {
189 | "file_extension": ".r2",
190 | "mimetype": "text/plain",
191 | "name": "radare2"
192 | }
193 | },
194 | "nbformat": 4,
195 | "nbformat_minor": 2
196 | }
197 |
--------------------------------------------------------------------------------
/examples/radare2_kernel_test.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/guedou/jupyter-radare2/584e3cd4a66f10459a6e801b02c8ceea213b866b/examples/radare2_kernel_test.png
--------------------------------------------------------------------------------
/kernel_spec/kernel.json:
--------------------------------------------------------------------------------
1 | {"argv":["python","-m","radare2", "-f", "{connection_file}"],
2 | "display_name":"radare2"
3 | }
4 |
--------------------------------------------------------------------------------
/radare2.py:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2017 Guillaume Valadon
2 |
3 | """
4 | A Jupyter kernel for radare2
5 | """
6 |
7 |
8 | import r2pipe
9 |
10 | from ipykernel.kernelbase import Kernel
11 | from ipykernel.kernelapp import IPKernelApp
12 |
13 |
14 | class Radare2Kernel(Kernel):
15 | """radare2 Jupyter kernel"""
16 |
17 | # Kernel information
18 | implementation = "radare2"
19 | implementation_version = "0.1"
20 | banner = "radare2 Jupyter kernel"
21 |
22 | # Language information
23 | language_info = {
24 | "name": "radare2",
25 | "mimetype": "text/plain",
26 | "file_extension": ".r2",
27 | }
28 |
29 |
30 | def _get_r2pipe(self):
31 | """Get the r2pipe handle"""
32 |
33 | if not hasattr(self, "r2"):
34 | self.r2 = r2pipe.open("-")
35 |
36 | def do_execute(self, code, silent, store_history=True, user_expressions=None,
37 | allow_stdin=False):
38 | """Execute a radare2 commmand using r2pipe"""
39 |
40 | self._get_r2pipe()
41 |
42 | if not silent:
43 | result = self.r2.cmd(code)
44 | stream = {"name": "stdout", "text": result}
45 | self.send_response(self.iopub_socket, "stream", stream)
46 |
47 | return {"status": "ok",
48 | "execution_count": self.execution_count,
49 | "payload": [],
50 | "user_expressions": {},
51 | }
52 |
53 |
54 | if __name__ == "__main__":
55 | IPKernelApp.launch_instance(kernel_class=Radare2Kernel)
56 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2017 Guillaume Valadon
2 |
3 |
4 | import os
5 | import json
6 | from setuptools import setup
7 |
8 | from jupyter_client.kernelspec import install_kernel_spec
9 | from IPython.utils.tempdir import TemporaryDirectory
10 |
11 |
12 | setup(name="jupyter_radare2",
13 | description="A Jupyter radare2 kernel",
14 | author="Guillaume Valadon",
15 | author_email="guillaume@valadon.net",
16 | version="0.1",
17 | url="https://github.com/guedou/jupyter_radare2",
18 | py_modules=["radare2"],
19 | )
20 |
21 |
22 | install_directory = install_kernel_spec("./kernel_spec", "radare2", user=True,
23 | replace=True)
24 |
--------------------------------------------------------------------------------