• Stars
    star
    130
  • Rank 277,575 (Top 6 %)
  • Language
    Python
  • License
    GNU Lesser Genera...
  • Created almost 11 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Bindings of the r2 api for Valabind and friends

radare2 API bindings

  • pip install r2libr Python r2libr bindings 🚀
  • Vala / Swig CI vala swig ci🚀

This repository contains the native bindings generated with Valabind to use the radare2 APIs.

If you are looking for the r2pipe bindings, check this repository.

Description

This directory contains the code necessary to use the r2 api from your favourite language.

Supported target languages:

  • Python
  • JavaScript
  • Java
    • jna Pure Java for FFI
    • java JNI native bindings
  • Go
  • Ruby
  • Perl
  • Lua
  • Vala
  • Rust
    • genbind.py -o /tmp/r2bindings-output -l rust
  • NewLisp
  • Guile
  • OCaml

And some other experimental bindings are for:

  • GIR
  • C++
  • C#

This package also contains the vdoc/ subdirectory which contains the rules used to generate all interactive html documentation.

Dependencies

To build radare2-bindings from repository you need the following programs installed:

  • swig: enables support for python, perl, lua, java and many other
  • vala: if you want to have Vala or Genie bindings
  • valabind: required only in developer mode (not release tarball)

Release tarballs come with all the pregenerated .cxx files, so you have no extra dependencies apart from the language libraries and C++ compiler.

Using r2pm

Fortunely, all those dependencies can be installed with r2pm:

r2pm -cgi vala swig valabind

Source build

To get install all dependencies do the following steps in order:

  • Install vala and swig from your distro
arch$ sudo pacman -S swig valac
deb$ sudo apt install -y swig valac
mac$ brew install swig valac

Or install

  • Install latest release of Vala from tarball or git
  • Fetch valabind from the repository:
$ git clone https://github.com/radare/valabind
$ cd valabind
$ make
$ sudo make install PREFIX=/usr

radare2-bindings

If you compile from the repo you need the latest version of valabind and then:

./configure --prefix=/usr

You can select the languages you want to compile with --enable={list-of-langs}

./configure --prefix=/usr --enable=python
make

r2libr (python)

r2libr are the most complete python bindings generated from source with all libr dynamic libraries bundled in a wheel.

You may have a try without the need to install radare2:

pip3 install --upgrade r2libr

For details, see r2libr.

Experimental radare2 bindgen

Introduction

This script allows to generate native bindings for these languages directly from radare2 C headers:

More languages are planned, in particular:

  • Ruby - I wanted to use ffi-gen but it needs revival and update to the modern Ruby and Clang.
  • OCaml - needs to be written
  • Lua - maybe LuaAutoC can be used, I don't know.

Usage

genbind.py -o /tmp/r2bindings-output

The tool required radare2 to be installed and takes the include directory from the output of r2 -H It is possible also specify the particular languages, for example:

genbind.py -o /tmp/r2bindings-output -l go rust python

PYTHON

To select the version of python to compile for use the PYTHON_CONFIG environment variable as follows:

$ ./configure --prefix=/usr --enable-devel
$ cd python
$ PYTHON_CONFIG=python3.2-config make
$ su -
# PYTHON_CONFIG=python3.2-config make install

RANDOM NOTES

The valabind integration forces us to do some changes in the r2 API.

These api changes are for:

  • Avoid keywords in function names

    Every language has its own keywords, r2api should try to workaround all those keywords to avoid collisions for bindings.

    Example: use, del, from, continue, etc..

    TODO: we need to review APIs, find better names for functions using those keywords, etc..

  • Review basic data structures

    Linked lists, hash tables, r_db, arrays, ... must be reviewed to fit with vala and swig basics to be able to use them with simple APIs or integrate them with the syntax sugar of the target language.

    Example:

  foreach (var foo in binls.get_symbols ()) {
	print ("%s 0x%08"PFMT64x"\n", foo.name, foo.offset);
  }
  • Unit testing

    Having bindings for python, perl, ruby, .. is good for unit testing because it hardly simplifies the way to test APIs, find bugs, ...

    TODO: write unit testing frameworks for perl, ruby, python, etc..

  • API unification for all languages

    All the previous development points are meant to reduce code in r2, avoid syntax exceptions, simplify api usage, and much moar ;)

SWIG is not complete, there are still so many bugs to fix and so many unimplemented stuff. Here's a list of the most anoying things of it:

  • unsigned char * : not implemented

More Repositories

1

radare2

UNIX-like reverse engineering framework and command-line toolset
C
20,356
star
2

iaito

Official QT frontend of radare2
C++
1,047
star
3

radare2-book

The Official Radare2 Book
C
787
star
4

awesome-radare2

A curated list of awesome projects, articles and the other materials powered by Radare2
696
star
5

radeco

radare2-based decompiler and symbol executor
Rust
372
star
6

radare2-r2pipe

Access radare2 via pipe from any programming language!
JavaScript
370
star
7

r2ghidra

Native Ghidra Decompiler for r2
C++
334
star
8

radare2-extras

Source graveyard and random candy for radare2
C
239
star
9

sdb

Simple and fast string based key-value database with support for arrays and json
C
216
star
10

r2con

Radare Congress Stuff
202
star
11

esilsolve

A python symbolic execution framework using radare2's ESIL (Evaluable String Intermediate Language)
Python
159
star
12

r2con2019

r2con2019 - slides and materials
Python
135
star
13

radare2-pm

Package Manager for Radare2
Shell
131
star
14

r2retdec

RetDec plugin for Radare2
C++
123
star
15

r2con2017

r2con 2017 September 6-9
Python
97
star
16

radare2-webui

webui repository for radare2
JavaScript
93
star
17

r2con2018

HTML
92
star
18

r2ai

local language model for radare2
Python
78
star
19

r2wars

Corewars but within r2
C#
56
star
20

r2pipe.rs

Rust crate for r2pipe
Rust
44
star
21

ghidra-r2web

Ghidra plugin to start an r2 webserver to let r2 interact with it
Java
43
star
22

libdemangle

A simple library focusing on demangling symbols for different programing languages
C
39
star
23

r2con2020

Python
35
star
24

radare

advanced unix-like hexadecimal editor and debugger
C
35
star
25

r2jp

Japanese Community of radare2
34
star
26

r2pm

Radare2 cross platform package manager
Go
33
star
27

radare2-r2papi

High Level API on top of the R2Pipe interface
TypeScript
33
star
28

acr

autoconf replacement
Shell
33
star
29

r2pipe-go

Go API to interact with radare2
Go
31
star
30

ghidra-native

C++
29
star
31

r2con2021

28
star
32

r2env

Install multiple versions of r2 and its plugins via Pip on any system!
Python
25
star
33

r2yara

yara and radare2, better together
C
17
star
34

radare2-rlang

Writing Radare2 plugins in various languages
C
15
star
35

radare2-testbins

Rebol
15
star
36

radare2-rust

Playground for Rust and Radare2
Rust
14
star
37

radare.org

http://www.radare.org/
CSS
14
star
38

r2hexagon

Hexagon disassembler code generator from the official instruction manual.
C
11
star
39

r2con2016

r2con2016 repository
C
10
star
40

esil-rs

Radare2's ESIL in Rust
Rust
10
star
41

r2diaphora

Binary Diffing tool ported to radare2
Python
9
star
42

radare2-gsoc-windows

Various Brainstorming/scripts/ideas/etc. for the GSOC-Windows Task
C
9
star
43

ragui

Vala
8
star
44

radare2-release

Releasing is hard
Shell
7
star
45

r2app

Electron Desktop App for Radare2
JavaScript
6
star
46

blog

The radare2 blog, available on radare.today
Shell
6
star
47

r2pipe-codeshare

A place to share your radare2 scripts
Python
6
star
48

radare2-win-installer

Windows installer scripts for radare2
Inno Setup
5
star
49

r2r-go

Go
5
star
50

radareorg

New amazing website for radare.org
Python
4
star
51

radare2-cheatsheets

TeX
4
star
52

radare2-fuzz

Python
4
star
53

ideas

4
star
54

radare2-skel

Sample radare2 project templates
Python
4
star
55

node-r2r

radare2 regressions testsuite in nodejs
JavaScript
3
star
56

iaito-translations

Makefile
3
star
57

.github

Radare Organization Templates
3
star
58

r2shell

C
2
star
59

infrastructure

Terraform, Nomad, Consul and Vault configuration of radare infrastructure
Dockerfile
2
star
60

r2pm-db

Radare2 package manager database
2
star
61

radare2-snap

Radare2 snap and docker repository
Makefile
2
star
62

radare2-fuzztargets

Makefile
1
star
63

r2r-v

R2 regressions testsuite written in V
V
1
star
64

radeco-regressions

Regresion tests for radeco
Rust
1
star
65

radare2-sigs

Zignature masm32 repository
Python
1
star
66

r2sarif

Load, manage and create SARIF documents with radare2
TypeScript
1
star