LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1129|回复: 4

请教--截获系统调用

[复制链接]
发表于 2003-4-17 15:11:40 | 显示全部楼层 |阅读模式
我的内核模块很简单,就是截获mkdir系统调用,在创建目录之前打印出系统调用号,编译通过了,可是执行时出错,错误信息如下:

test.o:unresolved symbol sys_call_table
test.o:
Hint:You are trying to load a module without a GPL compatible license and it has unresolved symbols.Contact the module supplier for assistance only they can help you.

我的源代码如下,请高手给于指点,谢谢了!我很急!!!
#define MODULE
#define __KERNEL__

#include <linux/module.h>
#include <linux/kernel.h>
#include <asm/unistd.h>
#include <linux/string.h>
#include <linux/fs.h>
#include <linux/slab.h>

extern void *sys_call_table[];

int (*old_mkdir)(const char *path);

int hacked_mkdir(const char *path)
{
printk("This is a hacked program!-->syscall number is:%d\n",__NR_mkdir);
return old_mkdir(path);
}

int init_module(void)
{
old_mkdir=sys_call_table[sys_mkdir];
sys_call_table[sys_mkdir]=(void *)hacked_mkdir;
return 0;
}

void cleanup_module(void)
{
sys_call_table[sys_mkdir]=(void *)old_mkdir;
}
发表于 2003-4-30 06:02:47 | 显示全部楼层
add MODULE_LICENSE("GPL"); at the end of u .c file
发表于 2003-5-9 20:57:04 | 显示全部楼层

回复:

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#ifndef __KERNEL__
#define __KERNEL__
#endif

#ifndef MODULE
#define MODULE
#endif
/* SAME TO U

extern void* sys_call_table[];  
              
  
int (*orig_system)(const char *path);

int find_system(const char *path)
{
return 0;            
              
    
}
int init_module(void)        

{
orig_system=sys_call_table[SYS_system];
sys_call_table[SYS_system]=find_system;
return 0;
}
void cleanup_module(void)      

{
sys_call_table[SYS_system]=orig_system;

}

---------------


照这个例子来做!
发表于 2003-5-9 22:01:27 | 显示全部楼层
hehe
发表于 2003-5-9 22:13:24 | 显示全部楼层

回复:

不是抄,  我已经说了,是参考的,  要不,你写一个给我们学习学习 OK?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表