r2pipe

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2021 License: MIT Imports: 13 Imported by: 2

README

r2pipe.go

Go module to interact with radare2

Source

This repository is in sync with radareorg/r2pipe.

Run make sync to update it after changing things in the source repository.

Documentation

GoDoc

Documentation

Overview

Package r2pipe allows to call r2 commands from Go. A simple hello world would look like the following snippet:

package main

import (
	"fmt"

	"github.com/radare/r2pipe-go"
)

func main() {
	r2p, err := r2pipe.NewPipe("malloc://256")
	if err != nil {
		panic(err)
	}
	defer r2p.Close()

	_, err = r2p.Cmd("w Hello World")
	if err != nil {
		panic(err)
	}
	buf, err := r2p.Cmd("ps")
	if err != nil {
		panic(err)
	}
	fmt.Println(buf)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NativeLoad

func NativeLoad() error

Types

type CloseDelegate

type CloseDelegate func(*Pipe) error

type CmdDelegate

type CmdDelegate func(*Pipe, string) (string, error)

type DL

type DL struct {
	// contains filtered or unexported fields
}

type EventDelegate

type EventDelegate func(*Pipe, string, interface{}, string) bool

type Pipe

type Pipe struct {
	File string

	Core unsafe.Pointer
	// contains filtered or unexported fields
}

A Pipe represents a communication interface with r2 that will be used to execute commands and obtain their results.

func NewApiPipe

func NewApiPipe(file string) (*Pipe, error)

func NewNativePipe

func NewNativePipe(file string) (*Pipe, error)

func NewPipe

func NewPipe(file string) (*Pipe, error)

NewPipe returns a new r2 pipe and initializes an r2 core that will try to load the provided file or URI. If file is an empty string, the env vars R2PIPE_{IN,OUT} will be used as file descriptors for input and output, this is the case when r2pipe is called within r2.

func (*Pipe) ApiClose

func (r2p *Pipe) ApiClose() error

func (*Pipe) ApiCmd

func (r2p *Pipe) ApiCmd(cmd string) (string, error)

func (*Pipe) Close

func (r2p *Pipe) Close() error

Close shuts down r2, closing the created pipe.

func (*Pipe) Cmd

func (r2p *Pipe) Cmd(cmd string) (string, error)

Cmd is a helper that allows to run r2 commands and receive their output.

func (*Pipe) Cmdf

func (r2p *Pipe) Cmdf(f string, args ...interface{}) (string, error)

like cmd but formats the command

func (*Pipe) Cmdj

func (r2p *Pipe) Cmdj(cmd string) (out interface{}, err error)

Cmdj acts like Cmd but interprets the output of the command as json. It returns the parsed json keys and values.

func (*Pipe) Cmdjf

func (r2p *Pipe) Cmdjf(f string, args ...interface{}) (interface{}, error)

like cmdj but formats the command

func (*Pipe) ForceClose

func (r2p *Pipe) ForceClose() error

Forcing shutdown of r2, closing the created pipe.

func (*Pipe) NativeClose

func (r2p *Pipe) NativeClose() error

func (*Pipe) NativeCmd

func (r2p *Pipe) NativeCmd(cmd string) (string, error)

func (*Pipe) On

func (r2p *Pipe) On(evname string, p interface{}, cb EventDelegate) error

func (*Pipe) Read

func (r2p *Pipe) Read(p []byte) (n int, err error)

Read implements the standard Read interface: it reads data from the r2 pipe's stdin, blocking until the previously issued commands have finished.

func (*Pipe) ReadErr

func (r2p *Pipe) ReadErr(p []byte) (n int, err error)

func (*Pipe) Write

func (r2p *Pipe) Write(p []byte) (n int, err error)

Write implements the standard Write interface: it writes data to the r2 pipe, blocking until r2 have consumed all the data.

type Ptr

type Ptr = unsafe.Pointer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL