banach-space / clang-tutor

A collection of out-of-tree Clang plugins for teaching and learning
The Unlicense
659 stars 62 forks source link

Obfuscator output is weird for the input with both + and - operations #8

Closed ivafanas closed 3 years ago

ivafanas commented 3 years ago

Please consider the following input file:

int foo(int a, int b) {
  return a + b;
}

int bar(int a, int b) {
  return a - b;
}

Actual obfuscator plugin output is:

int foo(int a, int b) {
  return (a ^ b) + 2 * (a & b);
}

int bar(int a, int b) {
  return a - b;
}

int foo(int a, int b) {
  return a + b;
}

int bar(int a, int b) {
  return (a + ~b) + 1;
}

Expected obfuscator plugin output is:

int foo(int a, int b) {
  return (a ^ b) + 2 * (a & b);
}

int bar(int a, int b) {
  return (a + ~b) + 1;
}

May be it is possible to share Rewriter between matchers and apply rewrite at the end of ObfuscatorASTConsumer::HandleTranslationUnit call

banach-space commented 3 years ago

Thanks for bringing this up and taking the time to submit this!

From my quick recollection, there was something odd about onEndOfTranslationUnit, but I've not looked at it for a while. I will try to recall what was the root cause of this over the weekend.

banach-space commented 3 years ago

I was hoping that I could add you as a reviewer for https://github.com/banach-space/clang-tutor/pull/11. Sadly that's not possible.

Please let me know if you have any comments!