rizin icon indicating copy to clipboard operation
rizin copied to clipboard

Rewrite `filter.c`

Open Rot127 opened this issue 3 years ago • 1 comments

Is your feature request related to a problem? Please describe.

I ran into problems with filter.c::filter() while developing https://github.com/rizinorg/rizin/pull/2417. filter() has hard coded assumptions about the asm string which the newly colored asm strings no longer fulfill (lea instructions are no longer recognized because of invalid magic values).

The problem is that fixing it essentially requires me to write more code with magic values. This makes the function even longer and harder to read.

Describe the solution you'd like

Rewrite filter.c in a modular way. filter() should have access to several filters (maybe pre-compiled regex patterns or something similar?) which it then applies on the string. The filters are applied according to certain flags. E.g.

  • asm.arch = x86 -> Apply x86 syntax filter: remove brackets from lea, etc.
  • scr.color=1 -> Ignore color escape sequences during filtering.
  • asm.sub.names=true -> Replace numbers with flag names. etc.

Describe alternatives you've considered

None.

Additional context

filter.c: https://github.com/rizinorg/rizin/blob/9c2c5fa495767b071f8fef1863e285f0305eadef/librz/parse/filter.c

Rot127 avatar Jul 02 '22 13:07 Rot127

Doing this will probably use a lot of the new regex engine. rz_regex_new() has a relatively high runtime. So we should somehow compile those patterns once when Rizin is started and continue using them without reallocating them or freeing them in between. Also see: https://github.com/rizinorg/ideas/issues/51

Rot127 avatar Feb 15 '24 12:02 Rot127