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
getch
必须是一个函数(不是宏)。实际上,在ncurses-6.1中,getch
定义为