【发布时间】:2016-09-18 16:02:56
【问题描述】:
一段时间以来,我一直在尝试在 Ubuntu 16.04LTS 上制作键盘记录器,这就是我目前所拥有的:
#include <stdio.h>
#include <fcntl.h>
#include <linux/input.h>
#include <stdbool.h>
int main()
{
char devname[] = "/dev/input/event0";
int device = open(devname, O_RDONLY);
struct input_event ev;
bool logging = true;
while(logging)
{
if (read(device,&ev, sizeof(ev)) >= 0){
printf("Key: %i State: %i Type: %i\n",ev.code,ev.value,ev.type);
}
}
}
但是,当我编译并运行它(gcc)时,它没有输出任何东西! 我已经尝试了 /dev/input/by-id 中列出的所有设备,但似乎没有任何效果。
当我使用 GCC 编译代码时,我收到警告:
keylogger.c: In function ‘main’:
keylogger.c:15:7: warning: implicit declaration of function ‘read’ [-Wimplicit-function-declaration]
if (read(device,&ev, sizeof(ev)) >= 0){
^
我不知道这是否与程序的功能有关。
感谢任何帮助!谢谢!
【问题讨论】:
-
read的原型在unistd.h.. 每当您收到这种类型的隐式函数声明警告时,请执行man **function_name**..man有多个页面.. 并且read在页面中2 ...所以你做man 2 read -
@ParnabSanyal 谢谢,但不幸的是它仍然无法正常工作。检查一下,Ubuntu中的默认键盘是/dev/input/event0,对吗?
-
我知道...我还没有给你解决方案。我还没有。我已经告诉你修复隐式函数警告的方法。
-
我明白了,我很抱歉。
-
没关系。做一件事。在读取函数调用之后.. 执行
printf("%s\n",strerror(errno));。看看它说了什么。做两个导入errno.h和string.h
标签: c linux ubuntu ubuntu-16.04 keylogger