我想使用 LD_Preload 编写一个名为“CSys::Printf”的函数,但我认为这不会那么容易,因为在 C 中你不能在函数名称中包含“::”,这将需要匹配原始函数名。
用于挂钩的一段代码如下所示:
int CSys::Printf(const char *format, ...) {
void *handle;
char *error;
if (conprint == NULL) {
handle = dlopen("dedicated.so", RTLD_LAZY);
if (!handle) {
fputs(dlerror(), stderr);
exit(1);
}
conprint = (int (*)(const char *format, ...))dlsym(handle, "CSys::Printf");
if ((error = dlerror()) != NULL) {
fprintf(stderr, "%s\n", error);
exit(1);
}
printf("*HOOK CSys::Printf OK*");
}
好吧,这应该适用于挂钩任何函数,除了这种情况,编译器不会接受函数名称上的“::”。
我应该怎么办?
谢谢!