Выбрать главу

[0x00404800]> $pmore='b 300;px'

[0x00404800]> $

$pmore

[0x00404800]> $pmore=

[0x00404800]> $

A single $ in the above will list all defined aliases. It's also possible check the aliased command of an alias:

[0x00404800]> $pmore?

b 200; px

Can we create an alias contains alias ? The answer is yes:

[0x00404800]> $pStart='s 0x0;$pmore'

[0x00404800]> $pStart

- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF

0x00000000 7f45 4c46 0201 0100 0000 0000 0000 0000 .ELF............

0x00000010 0300 3e00 0100 0000 1014 0000 0000 0000 ..>.............

0x00000020 4000 0000 0000 0000 5031 0000 0000 0000 @.......P1......

0x00000030 0000 0000 4000 3800 0d00 4000 1e00 1d00 ....@.8...@.....

0x00000040 0600 0000 0400 0000 4000 0000 0000 0000 ........@.......

0x00000050 4000 0000 0000 0000 4000 0000 0000 0000 @.......@.......

0x00000060 d802 0000 0000 0000 d802 0000 0000 0000 ................

0x00000070 0800 0000 0000 0000 0300 0000 0400 0000 ................

0x00000080 1803 0000 0000 0000 1803 0000 0000 0000 ................

0x00000090 1803 0000 0000 0000 1c00 0000 0000 0000 ................

0x000000a0 1c00 0000 0000 0000 0100 0000 0000 0000 ................

0x000000b0 0100 0000 0400 0000 0000 0000 0000 0000 ................

0x000000c0 0000 0000 0000 0000 ........

[0x00000000]>

The r2pipe api was initially designed for NodeJS in order to support reusing the web's r2.js API from the commandline. The r2pipe module permits interacting with r2 instances in different methods:

   • spawn pipes (r2 -0)

   • http queries (cloud friendly)

   • tcp socket (r2 -c)

pipe spawn async http tcp rap json

nodejs x x x x x - x

python x x - x x x x

swift x x x x - - x

dotnet x x x x - - -

haskell x x - x - - x

java - x - x - - -

golang x x - - - - x

ruby x x - - - - x

rust x x - - - - x

vala - x x - - - -

erlang x x - - - - -

newlisp x - - - - - -

dlang x - - - - - x

perl x - - - - - -

$ pip install r2pipe

import r2pipe

r2 = r2pipe.open("/bin/ls")

r2.cmd('aa')

print(r2.cmd("afl"))

print(r2.cmdj("aflj")) # evaluates JSONs and returns an object

Use this command to install the r2pipe bindings

$ npm install r2pipe

Here's a sample hello world

const r2pipe = require('r2pipe');

r2pipe.open('/bin/ls', (err, res) => {

if (err) {

throw err;

}

r2.cmd ('af @ entry0', function (o) {

r2.cmd ("pdf @ entry0", function (o) {

console.log (o);

r.quit ()

});

});

});

Checkout the GIT repository for more examples and details.

https://github.com/radareorg/radare2-r2pipe/blob/master/nodejs/r2pipe/README.md

Go

$ r2pm -i r2pipe-go

https://github.com/radare/r2pipe-go

package main

import (

"fmt"

"github.com/radare/r2pipe-go"

)

func main() {

r2p, err := r2pipe.NewPipe("/bin/ls")

if err != nil {

panic(err)

}

defer r2p.Close()

buf1, err := r2p.Cmd("?E Hello World")

if err != nil {

panic(err)

}

fmt.Println(buf1)

}

$ cat Cargo.toml

...

[dependencies]

r2pipe = "*"

#[macro_use]

extern crate r2pipe;

use r2pipe::R2Pipe;

fn main() {

let mut r2p = open_pipe!(Some("/bin/ls")).unwrap();

println!("{:?}", r2p.cmd("?e Hello World"));

let json = r2p.cmdj("ij").unwrap();

println!("{}", serde_json::to_string_pretty(&json).unwrap());

println!("ARCH {}", json["bin"]["arch"]);

r2p.close();

}

$ gem install r2pipe

require 'r2pipe'

puts 'r2pipe ruby api demo'

puts '===================='

r2p = R2Pipe.new '/bin/ls'

puts r2p.cmd 'pi 5'

puts r2p.cmd 'pij 1'

puts r2p.json(r2p.cmd 'pij 1')

puts r2p.cmd 'px 64'

r2p.quit

#!/usr/bin/perl

use R2::Pipe;

use strict;

my $r = R2::Pipe->new ("/bin/ls");

print $r->cmd ("pd 5")."\n";

print $r->cmd ("px 64")."\n";

$r->quit ();

#!/usr/bin/env escript

%% -*- erlang -*-

%%! -smp enable

%% -sname hr

-mode(compile).

-export([main/1]).

main(_Args) ->

%% adding r2pipe to modulepath, set it to your r2pipe_erl location

R2pipePATH = filename:dirname(escript:script_name()) ++ "/ebin",

true = code:add_pathz(R2pipePATH),

%% initializing the link with r2

H = r2pipe:init(lpipe),

%% all work goes here

io:format("~s", [r2pipe:cmd(H, "i")]).

import R2pipe

import qualified Data.ByteString.Lazy as L

showMainFunction ctx = do

cmd ctx "s main"

L.putStr =<< cmd ctx "pD `fl $$`"

main = do

-- Run r2 locally

open "/bin/ls" >>= showMainFunction

-- Connect to r2 via HTTP (e.g. if "r2 -qc=h /bin/ls" is running)

open "http://127.0.0.1:9090" >>= showMainFunction

using System;