2013-05-01 122 views
1

成員'readdir'的分配當我編譯這個文件時,它會引發以下錯誤。爲什麼我會收到錯誤信息「只讀對象」

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

回答

2

定義ops向量(f_op)的結構可能會在readdir字段的定義中使用const - 也可能是所有其他字段。設置自己的操作向量比在現有的操作向量中替換一個或兩個方法更正常。

相關問題