问题
After porting some obfuscated C code into C++ (namely Fairy-Max chess engine by Harm Geert Muller), I get lots of warnings similar to these:
suggest parentheses around comparison in operand of '&' [-Werror=parentheses]
suggest parentheses around '+' in operand of '&'
While turning off the warnings is not an option, the solution is to add parenthesis in expressions according to the operator precedence.
For example:
if(z&S&&!ab&K==INF&d>2&v>V&v<Beta){
needs to be transformed into this:
if((z&S) && ((!ab)&(K==INF)&(d>2)&(v>V)&(v<Beta))) {
But doing this manually is quite time-consuming.
I tried to use this deobfuscation tool, which uses clang-format
internally, but it does not add parenthesis into expressions...
Question
Is there a tool (preferably online) that can take a C/C++ expression as an input and return a warnings-free equivalent expression as an output?
回答1:
Geordi can do it.
I've long wanted a web version, but last time I tried to get Geordi working on my VPS I failed miserably due to Haskell dependency gubbins. May give it another go one day.
Meanwhile, you can log onto Freenode IRC and /msg geordi --precedence *p->data
(for example). You'll get a private message tab open up with the result (e.g. *(p->data)
). Feel free to keep sending --precedence <expression>
requests in that tab.
来源:https://stackoverflow.com/questions/56424972/parenthesis-calculator-for-c-c-expressions-operator-precedence