无法通过LD_PRELOAD钩接ncurses函数>> [

问题描述 投票:0回答:1
我正在尝试挂钩某些ncurses函数,但是它们没有任何作用。ncurses不是静态链接的,所以我不明白为什么它不起作用。

test.cpp

#include <cstdio> #include <cstdlib> #include <curses.h> int main() { initscr(); cbreak(); noecho(); getch(); endwin(); return 0; }

编译为:gcc test.cpp -o test -std=c++11 -lncurses

hook.cpp

#include <dlfcn.h> #include <cstdio> #include <cstdlib> int getch() { typedef int getch (); getch* old_getch = (getch*) dlsym(RTLD_NEXT, "getch"); int result = old_getch(); fprintf(stderr, "getch() = %i\n", result); return result; } int noecho() { typedef int noecho (); noecho* old_noecho = (noecho*) dlsym(RTLD_NEXT, "noecho"); int result = old_noecho(); fprintf(stderr, "noecho() = %i\n", result); return result; } int endwin() { typedef int endwin (); endwin* old_endwin = (endwin*) dlsym(RTLD_NEXT, "endwin"); int result = old_endwin(); printf("endwin called"); return result; }

编译为:gcc hook.cpp -o hook.so -shared -ldl -fPIC -std=c++11

可悲的是它什么也没输出,我完全被困住了。

我正在尝试挂钩某些ncurses函数,但是它们没有任何作用。 ncurses不是静态链接的,所以我不明白为什么它不起作用。 test.cpp #include

#include

c++ linux hook ncurses ld-preload
1个回答
0
投票
该规范没有规定getch必须是一个函数(不是宏)。实际上,在ncurses-6.1中,getch定义为
© www.soinside.com 2019 - 2024. All rights reserved.