rz-pipe
1 Examples
2 Reference
Rizin
rizin?
open
close
cmd
cmdj
exn:  fail:  rz-pipe:  rizin-not-found
exn:  fail:  rz-pipe:  startup
exn:  fail:  rz-pipe:  unexpected-data
9.3

rz-pipe🔗ℹ

RizinOrg <core@rizin.re>

This package provides a scripting interface for the Rizin Reverse Engineering Framework that builds upon Rizin’s command interface as a simple point of interaction.

While this library itself is written in Typed Racket, it can also be used in untyped Racket with contracts evaluated at runtime.

1 Examples🔗ℹ

Scripting:

#lang racket
 
(require (prefix-in rz: rz-pipe))
 
(define rz (rz:open "/bin/ls"))
(printf "~v\n" (rz:cmd rz "ao @ main"))          ; string result
(printf "~v\n" (rz:cmdj rz "aoj @ main"))        ; json result
(rz:close rz)

Inside a live Rizin session:

  $ rizin crackme0x00b

  [0x080483e0]> #!pipe racket

  Welcome to Racket v9.3 [cs].

  > (require rz-pipe)

  > (cmdj (open) "pdj 1")

  '(#hasheq((bytes . "31ed")

            (comment . "WzEyXSAtci14IHNlY3Rpb24gc2l6ZSA0NjAgbmFtZWQgLnRleHQ=")

            (disasm . "xor ebp, ebp")

            (esil . "ebp,ebp,^=,$z,zf,:=,$p,pf,:=,31,$s,sf,:=,0,cf,:=,0,of,:=")

            (family . "cpu")

            (fcn_addr . 0)

            (fcn_last . 0)

            (flags . ("entry0" "section..text" "sym..text" "sym._start"))

            (offset . 134513632)

            (opcode . "xor ebp, ebp")

            (refptr . #f)

            (reloc . #f)

            (size . 2)

            (type . "xor")

            (type2_num . 0)

            (type_num . 28)))

  >

2 Reference🔗ℹ

type

Rizin

Represents a connection to a running Rizin session.

procedure

(rizin? v) → Boolean

  v : Any
Returns #t if v is a Rizin, #f otherwise.

procedure

(open [filename #:stderr err-mode]) → Rizin

  filename : (U Bytes Path-String #f) = #f
  err-mode : (U 'forward 'ignore) = 'forward
Opens a connection to Rizin.

If filename is given, a new Rizin instance is started as a subprocess and attached to. Pass "--" as filename if no file should be opened. In this mode, err-mode defines how to handle the subprocess’s stderr output:

If filename is #f, open tries to attach to an existing Rizin session hosting the current Racket process. This is meant to be used when running under the #!pipe command inside Rizin itself.

Raises:

procedure

(close rz) → Void

  rz : Rizin
Closes the given connection to Rizin.

procedure

(cmd rz command) → String

  rz : Rizin
  command : String
Executes command inside Rizin and returns its output verbatim as a string.

Raises exn:fail:rz-pipe:unexpected-data if Rizin closed its output before the result of command was fully received, for example because the Rizin process has exited.

procedure

(cmdj rz command) → JSExpr

  rz : Rizin
  command : String
Same as cmd, but the output is parsed as JSON and returned as a jsexpr? value. Make sure that command is a command that outputs JSON, usually one with the j suffix.

Raises exn:fail:read if the output of command is not valid JSON.

The rizin executable could not be found in PATH, or RZ_PIPE_IN/RZ_PIPE_OUT are not available when attaching to an existing session.

Rizin failed to start, either because the given file could not be opened or because another error occurred.

Rizin sent data the library did not recognize.