Chinaunix首页 | 论坛 | 博客
  • 博客访问: 529829
  • 博文数量: 120
  • 博客积分: 3030
  • 博客等级: 中校
  • 技术积分: 1445
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-05 01:00
文章存档

2011年(1)

2009年(2)

2008年(32)

2007年(33)

2006年(52)

我的朋友

分类: LINUX

2006-03-08 22:21:27

最近需要替换系统函数,所以接触了一些 ,尝试了下最简单的替换 ,如下 ,发现还是有很多的地方需要琢磨
 
(mkdir.c)
 
#define MODULE
#define __KERNEL__
#include
MODULE_LICENSE("GPL");
#include
#include
#include
#include
#include
#include
#include
#include
 #include
void **sys_call_table = (void**)0xc0300af0 ;    //////////

  / /extern void* sys_call_table[]; /*sys_call_table is exported, so we can access it*/
int (*orig_mkdir)(const char *path); /*the original systemcall*/

int hacked_mkdir(const char *path)
{
 printk("<1>----------hello-------------------\n") ;
 return 0; /*everything is ok, but he new systemcall
 does nothing*/
}
int init_module(void) /*module setup*/
{
 orig_mkdir=sys_call_table[SYS_mkdir];
 sys_call_table[SYS_mkdir]=hacked_mkdir;
 return 0;
}
void cleanup_module(void) /*module shutdown*/
{
 sys_call_table[SYS_mkdir]=orig_mkdir; /*set mkdir syscall to the origal one*/
}
 
 
 
这样就可以通过gcc mkdir.c -c 生成mkdir.o
insmod mkdir
然后就可以使用替换后的mkdir 了
注意redhat9以后的版本没有公开sys_call_table,要得到sys_call_table的地址需要进行cat Systemmap |grep sys_call_table得到地址 ,如果是早期的版本的话直接extern sys_call_table[] 就可以了
 
 
 
 
 
 
 
阅读(881) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:转载一篇关于linux0.11移植的文章

给主人留下些什么吧!~~