TLDR: How do I get a panel in radare2 to correctly show the output of a radare2 command piped to an external script?

e.g. afvd | python var_displayer.py

  • This is my current view. Multiple panels, using radare2's v command. Note the afvd and RegisterRefs (drr) panels.

enter image description here

  • I love RegisterRefs (drr) because it shows values at addresses. I love afvd because it shows all var values.
  • Problem: afvd only shows var values as decimal.
  • Sometimes, it makes more sense to see it as hex.
  • Sometimes, it makes more sense to see it as ASCII.
  • I want to create something like afvdr that shows var values in different formats + refstr, like drr does for registers.
  • I want to replace my current afvd panel with this new tool.

What do I have so far?

  • I know that if I take a var's value (e.g. var_8h = 4287356032) and run the r2 command ? <expr>, it will evaluate the expression and show me different representations!

enter image description here

  • I developed a python script, called var_displayer.py that will read the output from avfd and calculate and neatly display the hex and string representations the same as the ? <expr> command would. I run it within r2 using afvd | python scripts/var_displayer.py. Here's the output:

enter image description here

  • This is awesome! I don't have the dereference functionality (treat var value as an address and show the value underlying), which would be useful like drr, but this is great for me!
  • However, a problem occurs when I try to replace the afvd panel with afvd | python scripts/var_displayer.py.

enter image description here

  • Note how the panel only shows the output of afvd, and note how the string generated by my python script is awkwardly appended to the entire radare2 panels output in the bottom left.
  • My python script builds the output string in one variable named output_string and then outputs this string with a call to sys.stdout.write(out_string). Unfortunately, radare2 doesn't seem to expect this for a panel's display.


My Questions Are:

  1. Is it possible to configure a radare2 panel to neatly show the output of an external script/program?
  2. Is there a better way to achieve the evaluate functionality (? <expr>) and dereference evaluate functionality (drr refstr column) for vars that is native to radare2?

I'm falling in love with radare2 for it's customizability and elegance and slick CLI feel, but I'm pretty surprised to find custom script --> panel is not working. I feel like there must be a way to achieve this that I haven't figured out yet.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.