UTF-8 fun With radare2

November 9, 2017

Aside from the most hardcore, I guess everyone uses terminals with some measure of utf-8 support. So why not take advantage of that? radare2 sure does. So this is how radare2 reflines (lines pointing to code jumps etc) look out of the box -

[0x000036de]> pd 7
  ,=< 0x000036de      0f84c50d0000   je 0x44a9
  |   0x000036e4      83f803         cmp eax, 3
 ,==< 0x000036e7      740f           je 0x36f8
 ||   0x000036e9      83e801         sub eax, 1
,===< 0x000036ec      0f8416090000   je 0x4008
|||   0x000036f2      ff1588c52100   call qword [reloc.abort_128]
|`--> 0x000036f8      c70536dc2100.  mov dword [0x00221338], 0

Not too pretty, right? That’s because r2 doesn’t assume utf-8 support. However, it has a handy config variable that can help us out here - e scr.utf8, which is set to false by default. Let’s try enabling it.

[0x000036de]> e scr.utf8 = true

[0x000036de]> pd 7
  ┌─< 0x000036de      0f84c50d0000   je 0x44a9
  │   0x000036e4      83f803         cmp eax, 3
 ┌──< 0x000036e7      740f           je 0x36f8
 ││   0x000036e9      83e801         sub eax, 1
┌───< 0x000036ec      0f8416090000   je 0x4008
│││   0x000036f2      ff1588c52100   call qword [reloc.abort_128]
│└──> 0x000036f8      c70536dc2100.  mov dword [0x00221338], 0

Now isn’t that much better to look at? But that’s not enough now, is it? xvilka posted an issue recently (#8586) about adding curved corners to reflines, like in tig. And so I took that up, and added another config variable for it, scr.utf8.curvy. Let’s see what we get by setting that to true. Note: for this to work, you need to also have e scr.utf8 = true.

[0x000036de]> e scr.utf8.curvy = true
[0x000036de]> pd 7
  ╭─< 0x000036de      0f84c50d0000   je 0x44a9
  │   0x000036e4      83f803         cmp eax, 3
 ╭──< 0x000036e7      740f           je 0x36f8
 ││   0x000036e9      83e801         sub eax, 1
╭───< 0x000036ec      0f8416090000   je 0x4008
│││   0x000036f2      ff1588c52100   call qword [reloc.abort_128]
│╰──> 0x000036f8      c70536dc2100.  mov dword [0x00221338], 0

Not much, yeah, but that corners are curved. That’s still kinda cool-looking, isn’t it?