我正在尝试编写一个get啮齿类()系统调用,以列出通过调用getdents()返回的所有目录条目,但我遇到了一个似乎无法解决的小问题,不确定这是否是C错误(因为我仍在学习它)或调用本身的一些内容。当我打印每个结构的d_name时,总是缺少目录/文件的第一个字母。
Feb 13 11:39:04 node35 kernel: [ 911.353033] entry: ootkit.c
Feb 13 11:39:04 node35 kernel: [ 911.353035] entry: ootkit.mod.c
Feb 13 11:39:04 node35 kernel: [ 911.353036] entry: ootkit.ko这些文件的名称是rootkit。
我的代码:
asmlinkage int new_getdents(unsigned int fd, struct linux_dirent64 *dirp, unsigned int count)
{
int nread;
int bpos;
struct linux_dirent64 *d;
int (*orig_func)(unsigned int fd, struct linux_dirent64 *dirp, unsigned int count);
t_syscall_hook *open_hook;
open_hook = find_syscall_hook(__NR_getdents);
orig_func = (void*) open_hook->orig_func;
nread = (*orig_func)(fd, dirp, count);
d = dirp;
for (bpos = 0; bpos < nread;) {
d = (struct linux_dirent64 *) ((char*)dirp + bpos);
printk(KERN_INFO "%s\n", d->d_name);
bpos += d->d_reclen;
}
return nread;
}发布于 2014-02-13 17:34:13
我最好的猜测是,您混淆了getdents syscall的遗留版本和"64“版本。即使在64位系统上,似乎也有一个遗留版本(没有64位)编写一个缺少d_type成员的结构(因此,如果您使用现代的"64“版本的结构,名称的第一个字符将被误解为d_type成员)以及(正确的) getdents64 syscall。
https://stackoverflow.com/questions/21760212
复制相似问题