weggli-rs / weggli

weggli is a fast and robust semantic search tool for C and C++ codebases. It is designed to help security researchers identify interesting functionality in large codebases.
Apache License 2.0
2.32k stars 127 forks source link

Using regular expressions to match boolean operators. #4

Open mvanotti opened 2 years ago

mvanotti commented 2 years ago

I am having some trouble getting my query to work the way I intend to.

I want to match:

if (_ X _($atomic.fetch_sub())) {
}

where X is either && or ||, however, I cannot get the query right.

-l -R 'op=$\|\|^' -X '{
if (_ $op; _($atomic.fetch_sub())) { _; }
}'

Doesn't return anything, and

weggli/target/release/weggli -l -R 'op=$\|\|^' -X '{
if (_ $op _($atomic.fetch_sub())) { _; }
}'

Fails with:

Error! Query parsing failed: {
if (_ $op [MISSING ; ]  _($atomic.fetch_sub())) { _; }
}

I don't know if this is a bug or if I am not writing the query correctly.

felixwilhelm commented 2 years ago

Using variables in place of operators is not supported (and it would be pretty hard to implement as it requires significant changes to the used C and C++ grammars).

I have to think about the best way to implement something like this. For now you need to write and run two queries unfortunately.