Any way to parse preprocessed source through exter

2020-04-11 10:23发布

I want the compiler to run preprocessing, generate all the .i files like it normally does if I just use the "generate preprocessed file" option, and then run an external tool, wait for it to complete, and then go on with the compilation of those .i files (which by now can be modified of course).

If that is not possible, is there a way to run an external tool on every file that is being compiled before preprocessing and compilation? (Would probably be a hell to debug in environment like that, but still).

If there is no option like that, could this even be done at all? I mean, does the compiler even use those .i files, or are they just output for the user somehow?

Basically, is there any way to automatically tamper with the source before it is compiled, but without modifying the actual files?

Just for refs: I am trying to think of a smart way to obfuscate all the strings with minimum modification of the source.

5条回答
SAY GOODBYE
2楼-- · 2020-04-11 10:26

You could use a make file to generate the .i files first, run your processing on them, then compile them.

查看更多
Anthone
3楼-- · 2020-04-11 10:28

Let x.cpp be your file you want to preprocess.

  1. Set the compiler option to generate preprocessed output for x.cpp, let it be x.i.
  2. Add the x.i to the project and set the "custom build tool" in the properties. Set the "output files" to x.preprocessed.cpp.
  3. Add x.preprocessed.cpp to the project.

See msdn for details.

查看更多
Juvenile、少年°
4楼-- · 2020-04-11 10:35

You should be able to perform a "Pre-Build Event" and plug in any external tools there. In VS200x it's under Configuration Properties -> Build Events -> Pre-Build Events.

查看更多
Viruses.
5楼-- · 2020-04-11 10:40

Just use a decent build system. SCons, waf, or something else if you won't like those two.

查看更多
够拽才男人
6楼-- · 2020-04-11 10:44

Yes, you'd simply update your build system to have a preprocess step, obfuscate step, then compile-to-obj step. By default, most build systems merely merge all those to one step (and skip the obfuscate step). Should be no big deal with any "real" build system like Scons, waf, or even Make.

If you're using Visual Studio, then it is a bit more work. Microsoft wants you to write your build operations in MSBuild, and that's quite a bit of work, IMHO. It's not easy because MSVS is principally an IDE for iterative development, and NOT intended to be a build tool. It's not, and will never be, a build tool (even though it happens to do "build things", but only standard and very simple "build things"). But, you can still use the IDE with a different build tool. For example, we use Scons for our build, and it generates MSVS *.sln and *.vcproj files, and those files merely build with Scons (but all the files are edited in the MSVS IDE).

The simple answer: Your question is very simply a build-operations problem. It should be very straight-forward with any non-"toy" build system.

The distcc (distributed build tool) effectively preprocesses all files locally, then sends the *.i to remote compilers (that do not even need headers installed), and then ships back the *.obj. So, what you're talking about is pretty straight-forward.

查看更多
登录 后发表回答