안녕하세요. 열린 전화를 가로 채서 파일을 읽고 파일을 편집하지 않고 출력을 편집해야하는 클래스 할당이 있습니다.이 작업은 모두 커널 공간의로드 가능한 모듈에서 수행됩니다 . 내가 편집을 말할 때 나는 단어를 바꾸어서 그 단어를 밑줄로 대체하는 것을 의미합니다. 단어의 모든 예를 바꿔서 원하는 결과를 얻습니다. 나는 이것을 알아 내려고 노력하면서 온라인에서 봤다. 나는 적절한 예를 찾았지만 나에게 오류를주고 있었다. 커널에 모듈을 입력하자마자 즉시 죽이라고 표시합니다. 사용하지 않기 때문에 제거 할 수 없다고 말합니다. 그렇지 않을 때 가상 컴퓨터를 다시 시작해야합니다. 아래는 코드입니다. 어떤 도움을 주셔서 감사합니다 감사합니다. 당신은 커널에서 수행하지 말아야한다 것들 - 운전 나를 너트 :우분투로드 가능 모듈을 사용하여 파일 읽기
#include <linux/module.h> // Needed by all modules
#include <linux/kernel.h> // Needed for KERN_INFO
#include <linux/fs.h> // Needed by filp
#include <asm/uaccess.h> // Needed by segment descriptors
int init_module(void)
{
// Create variables
struct file *f;
char buf[128];
mm_segment_t fs;
int i;
// Init the buffer with 0
for(i=0;i<128;i++)
buf[i] = 0;
// To see in /var/log/messages that the module is operating
printk(KERN_INFO "My module is loaded\n");
// I am using Fedora and for the test I have chosen following file
// Obviously it is much smaller than the 128 bytes, but hell with it =)
f = filp_open("/etc/fedora-release", O_RDONLY, 0);
if(f == NULL)
printk(KERN_ALERT "filp_open error!!.\n");
else{
// Get current segment descriptor
fs = get_fs();
// Set segment descriptor associated to kernel space
set_fs(get_ds());
// Read the file
f->f_op->read(f, buf, 128, &f->f_pos);
// Restore segment descriptor
set_fs(fs);
// See what we read from file
printk(KERN_INFO "buf:%s\n",buf);
}
filp_close(f,NULL);
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "My module is unloaded\n");
}
module_init(init_module);
module_exit(cleanup_module);
는 read''에 대한 open''하나, 하나를 sys_call 후크를 작성하는 것입니다. http://stackoverflow.com/q/2103315/1212012를 참조하십시오. – purplepsycho