1

In search for a c++ parser I recently stumbled across the project below. Within it there's a parser that seems extremely well suited to my needs, however I believe the author(s) have deliberately obfuscated some of the core pieces of code, which make examining the code a little difficult.

https://github.com/ArashPartow/math-parser-benchmark-project/blob/master/fparser/fpoptimizer.cc

There is a description in the file and on the author's website about there being a plain deobfuscated version, however the indicated site seems to only have a dead-link and attempts to contact the author have been fruitless.

I was wondering if fellow SOers would know of a quick and easy way to reverse the obfuscation in the above mentioned file.

Now I'm not sure because I'm not a C++ expert, but it could be that there is a legitimate reasons for the code to be the way it is, presumably as the name of the file suggests it could be for performance reasons.

Oliver Salzburg
  • 21,652
  • 20
  • 93
  • 138
Gerdiner
  • 1,435
  • 3
  • 15
  • 19
  • 8
    "NOTE: This file contains generated code (from the optimizer sources) and is not intended to be modified by hand. If you want to modify the optimizer, download the development version of the library." – Mysticial Apr 03 '13 at 03:14
  • 7
    @Mysticial: `however the indicated site seems to only have a dead-link and attempts to contact the author have been fruitless` – Lightness Races in Orbit Apr 03 '13 at 03:17
  • I would begin with getting rid of the macroes, try this: http://stackoverflow.com/questions/277258/c-c-source-file-after-preprocessing# I think that that code has been intentionally obfuscated, there is seemingly nothing that would improve performance of that code. – Kupto Apr 03 '13 at 03:18
  • 1
    Meanwhile, I don't understand how "optimizing" C++ improves performance. WTF is going on? – Lightness Races in Orbit Apr 03 '13 at 03:18
  • 1
    @Mystical: The question explains the situation. – Gerdiner Apr 03 '13 at 03:22
  • @LightnessRacesinOrbit I am not sure if you can really "optimize" well written code better that compiler's optimizer (talking gcc or Visual Studio) as long as it is still in c/c++ code. You can usually create many optimizations when you are on the assembler level though... – Kupto Apr 03 '13 at 03:23
  • 1
    @Gerdiner The point I was trying to make is basically, to give up if you can't find the original. I'm not too convinced that it will be readable even after preprocessor substitutions. – Mysticial Apr 03 '13 at 03:24
  • @Kupto: Within the scope of your program's logic, sure, but this is just rewriting the program lexically, which seems pointless unless you want to compile it over and over again in a tight loop for some mission-critical purpose. Doubtful. – Lightness Races in Orbit Apr 03 '13 at 03:26
  • @LightnessRacesinOrbit yes... that is what I was saying `there is seemingly nothing that would improve performance of that code`. The file looks the way it does because it is intentionally obfuscated. – Kupto Apr 03 '13 at 03:29
  • @Kupto: Yes, and I am saying that this seems pointless. – Lightness Races in Orbit Apr 03 '13 at 03:30
  • The 3.blah versions do not appear, at first glance, to be obfuscated. Possibly some 4.blah version isn't either. I'd start with the 3.blah version, and see if 4.blah has any features I care about. – Yakk - Adam Nevraumont Apr 03 '13 at 03:35

2 Answers2

5

Most compilers have options to just run the preprocessor on the code & generate the preprocessor output. That will remove any obfuscation done using #defines.

For e.g. in MSVC, you can run cl /P fpoptimizer.cc. This will create a file called fpoptimizer.i which will contain the pre-processed file.

You can remove the #includes in the program before doing this - so that only the #defines in the program are preprocessed and not other stuff.

gcc provides the -E option to do something similar.

user93353
  • 13,733
  • 8
  • 60
  • 122
  • 1
    I gave that a go, it produced a 1.8MB file, which included all kinds of other things. Is there way to only include the stuff that is in the file itself? btw it produces stuff like this, is there a way to make it a bit more formatted via that command option? TailCall_cLessOrEq;Ljh:this-> ByteCode.pop_back(); ByteCodePtr-=1; opcode= cLess;;goto TailCall_cLess;Lji:this-> ByteCode.pop_back(); ByteCodePtr-=1; opcode= cGreaterOrEq;;goto TailCall_cGreaterOrEq;Ljj:this-> ByteCode.pop_back(); ByteCodePtr-=1; opcode= cGreater;;goto TailCall_cGreater;Ljk:this-> ByteCode.pop_back(); – Gerdiner Apr 03 '13 at 03:26
  • @Gerdiner - As I said remove #includes from the file before doing this - this will ensure that pre-processing is done only for `#defines` from the file. – user93353 Apr 03 '13 at 03:27
5

In this specific case, you could just try this link to the project page, with the latest devel files - I just worked out it was the version being wrong - the link says 4.5 and the current version is 4.5.2 as of this revision. They don't seem to keep old versions around so grab the latest there

Journeyman Geek
  • 211
  • 1
  • 7
  • 22