How to Bypass a Standard C++ Function While Maintaining Its Functionality

前端 未结 7 854
迷失自我
迷失自我 2021-01-24 03:03

I am looking for a way to be able to redefine a set of POSIX functions but then end the redefinition with a call to the original function. The idea is that I am trying to create

7条回答
  •  隐瞒了意图╮
    2021-01-24 03:33

    If using some recent GCC (e.g. version 4.7 or newer) you could also write a GCC plugin or a GCC extension in MELT to replace every call to strcpy to your own mystrcpy. This probably will take you some work (perhaps days, not hours) but has the enormous advantage to work inside the compiler, on the GCC compiler's internal representations (Gimple). So it will be done even after inlining, etc. And since you extend the compiler, you can tailor its behavior to what you want.

    MELT is a domain specific language to extend GCC. It is designed for such tasks.

提交回复
热议问题