linux hook 系统调用之ioctl
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <asm/unistd.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("xunil@bmy");
MODULE_DESCRIPTION("Different from others, this module automatically locate the entry of sys_call_table !");
void ** sys_call_table = (void **)0xc03c7740;
int (*orig_my_ioctl)(int fd, int cmd);
int a=0;
asmlinkage int hacked_ioctl(int fd,int cmd){
printk("PID %d called sys_mkdir !/n",current->pid);
printk("The pathname=%d;The mode=%d",fd,cmd);
a=cmd;
return orig_my_ioctl(fd,cmd);
}
static int __init find_init(void){
orig_my_ioctl=sys_call_table[__NR_ioctl];
sys_call_table[__NR_ioctl]=hacked_ioctl;
printk("The cmd value=%d",a);
//sys_call_table[__NR_ioctl]=orig_my_ioctl;
return 0;
}
static void __exit find_cleanup(void){
sys_call_table[__NR_ioctl]=orig_my_ioctl;
}
module_init(find_init);
module_exit(find_cleanup);
上面是我再晚上看的一些资料然后写的代码,编译后insmod 后系统直接挂了,不知道什么原因,是因为系统调用ioctl 修改了么,还是什么原因。我的目的是要hook打印机的驱动,自动控制它。如何判断他是调用打印机驱动的呢,我只想过滤打印机的相关操作,其他的设备掉放过,如果哪位大神可以帮助我,感激不尽,我所有的分数都给你,谢了!!!