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

前端 未结 7 930
迷失自我
迷失自我 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条回答
  •  旧时难觅i
    2021-01-24 03:33

    You cannot avoid these functions to be called.

    A C++ program can do anything it wants, it could have some code that loads the strcpy symbol from libc and runs it. If a malicious developer want to call that function, you have no way to avoid it. To do that you'd need to run the C++ code in some special environment (in a sandbox, or virtual machine), but I'm afraid such technology is not available.

    If you trust the developers, and you're just looking for a way to remind them not to call certain functions, then there could be some solution.

    One solution could be avoiding to #include libc headers (like cstring), and only include your own header files where you only declared the desired functions.

    Another solution could be that of looking to the compiled executable in order to find out what functions are called, or to LD_PRELOAD a library that redefines (and thus overrides) standard functions to make them print a warning at runtime.

提交回复
热议问题