Add Support for Rizin

Rizin is a fork of Radare2 with almost near perfect command compatibility with r2. Any r2 related plugins need to be replaced with their rz counter parts. Solves #1566
pull/1578/head
Maria 3 years ago committed by Gulshan Singh
parent e5fbefc444
commit fd14aa0e55

@ -633,6 +633,7 @@ def load_commands() -> None:
import pwndbg.commands.probeleak
import pwndbg.commands.procinfo
import pwndbg.commands.radare2
import pwndbg.commands.rizin
import pwndbg.commands.reload
import pwndbg.commands.rop
import pwndbg.commands.ropper

@ -0,0 +1,64 @@
import argparse
import subprocess
import pwndbg.commands
import pwndbg.rizin
from pwndbg.color import message
from pwndbg.commands import CommandCategory
parser = argparse.ArgumentParser(description="Launches rizin.", epilog="Example: rz -- -S -AA")
parser.add_argument("--no-seek", action="store_true", help="Do not seek to current pc")
parser.add_argument(
"--no-rebase",
action="store_true",
help="Do not set the base address for PIE according to the current mapping",
)
parser.add_argument("arguments", nargs="*", type=str, help="Arguments to pass to rizin")
@pwndbg.commands.ArgparsedCommand(
parser, aliases=["rizin"], category=CommandCategory.INTEGRATIONS
)
@pwndbg.commands.OnlyWithFile
def rz(arguments, no_seek=False, no_rebase=False) -> None:
filename = pwndbg.gdblib.file.get_file(pwndbg.gdblib.proc.exe)
# Build up the command line to run
cmd = ["rizin"]
flags = ["-e", "io.cache=true"]
if pwndbg.gdblib.proc.alive:
addr = pwndbg.gdblib.regs.pc
if pwndbg.gdblib.elf.get_elf_info(filename).is_pie:
if no_rebase:
addr -= pwndbg.gdblib.elf.exe().address
else:
flags.extend(["-B", hex(pwndbg.gdblib.elf.exe().address)])
if not no_seek:
cmd.extend(["-s", hex(addr)])
cmd.extend(flags)
cmd += arguments
cmd.extend([filename])
try:
subprocess.call(cmd)
except Exception:
print("Could not run rizin. Please ensure it's installed and in $PATH.")
parser = argparse.ArgumentParser(
description="Execute stateful rizin commands through rzpipe.",
epilog="Example: rzpipe pdf sym.main",
)
parser.add_argument("arguments", nargs="+", type=str, help="Arguments to pass to rzpipe")
@pwndbg.commands.ArgparsedCommand(parser, category=CommandCategory.INTEGRATIONS)
@pwndbg.commands.OnlyWithFile
def rzpipe(arguments) -> None:
try:
rz = pwndbg.rizin.rzpipe()
print(rz.cmd(" ".join(arguments)))
except ImportError:
print(message.error("Could not import rzpipe python library"))
except Exception as e:
print(message.error(e))

@ -0,0 +1,31 @@
import gdb
import pwndbg.gdblib.elf
import pwndbg.lib.memoize
@pwndbg.lib.memoize.reset_on_start
@pwndbg.lib.memoize.reset_on_objfile
def rzpipe():
"""
Spawn and return a rzpipe handle for the current process file.
This function requires a rizin installation plus the rzpipe python
library. The base address is automatically set for PIE when loading the
binary.
After opening the handle, the binary is automatically analyzed.
Raises ImportError if rzpipe python library is not available.
Raises Exception if anything goes fatally wrong.
Returns a rzpipe.open handle.
"""
filename = gdb.current_progspace().filename
if not filename:
raise Exception("Could not find objfile to create a rzpipe for")
import rzpipe
flags = ["-e", "io.cache=true"]
if pwndbg.gdblib.elf.get_elf_info(filename).is_pie and pwndbg.gdblib.elf.exe():
flags.extend(["-B", hex(pwndbg.gdblib.elf.exe().address)])
rz = rzpipe.open(filename, flags=flags)
rz.cmd("aaaa")
return rz

@ -36,7 +36,7 @@ module = [
disable_error_code = ["name-defined"]
[[tool.mypy.overrides]]
module = ["capstone.*", "unicorn.*", "pwnlib.*", "elftools.*", "ipdb.*", "r2pipe", "pt"]
module = ["capstone.*", "unicorn.*", "pwnlib.*", "elftools.*", "ipdb.*", "r2pipe", "rzpipe", "pt"]
ignore_missing_imports = true
[tool.isort]

Loading…
Cancel
Save