[][src]Crate r2pipe

R2Pipe provides functions to interact with radare2. This aims to be a raw API. For more higher-level functions and structs to abstract over the generated output, see r2pipe.rs-frontend.

Hence this requires you to have radare2 installed on you system. For more information refer to the r2 repository. The module spawns an instance of r2 and communicates with it over pipes. Using commands which produce a JSON output is recommended and easier to parse.

R2Pipes are available for a several of languages. For more information about r2pipes in general head over to the wiki.

Design

All the functionality for the crate are exposed through two structs: R2PipeLang and R2PipeSpawn.

Typically, there are two ways to invoke r2pipe. One by spawning a child-process from inside r2 and second by making the program spawn a child r2process. enum R2Pipe is provided to allow easier use of the library and abstract the difference between these two methods.

The macro open_pipe!() determines which of the two methods to use.

Note: For the second method, the path of the executable to be analyzed must be provided, while this is implicit in the first (pass None) method (executable loaded by r2).

Example

#[macro_use]
extern crate r2pipe;
extern crate serde_json;
use r2pipe::R2Pipe;
fn main() {
    let path = Some("/bin/ls".to_owned());
    let mut r2p = open_pipe!(path).unwrap();
    println!("{}", r2p.cmd("?e Hello World").unwrap());
    if let Ok(json) = r2p.cmdj("ij") {
        println!("{}", serde_json::to_string_pretty(&json).unwrap());
        println!("ARCH {}", json["bin"]["arch"]);
    }
    r2p.close();
}

The crate offers various methods to interact with r2pipe, eg. via process (multi-threadable), http or tcp. Check the examples/ dir for more complete examples.

Re-exports

pub use self::r2::R2;
pub use self::r2pipe::R2Pipe;
pub use self::r2pipe::R2PipeSpawnOptions;

Modules

r2pipe

Provides functionality to connect with radare2.

r2

Few functions for initialization, communication and termination of r2.

Macros

open_pipe