我正在尝试覆盖预定义的函数,例如 strcmp、getenv 等。我已经使用 LD_PRELOAD 选项覆盖了其中的一些函数。但我不能覆盖字符串类,我怎样才能覆盖 C++ 字符串类
我已经尝试过这样的事情;
class string{
char* str;
public:
string (char* str2){
str = str2;
std::cout << str2 << std::endl ;
}
bool operator==(char* str2) {
std::cout << "c++ => " << str << "==" << str2 << std::endl;
return false;
}
compare(char* str2) {
std::cout << "c++ => " << str << "==" << str2 << std::endl;
return 0;
}
};
但它不起作用我无法打印比较甚至定义的字符串。
编译;
g++ -g -Wall -shared -fPIC -ldl -o bypasscpp.so bypass.cpp
并运行程序;
LD_PRELOAD="./bypasscpp.so" ./app