- 论坛徽章:
- 0
|
mainc.- #include <linux/module.h>
- #include <linux/init.h>
- #include <linux/kernel.h>
- #define DRIVER_AUTHOR "kamus <kamus.sun@gmail.com>"
- #define DRIVER_DESC "A simple modify syscall"
- MODULE_AUTHOR(DRIVER_AUTHOR);
- MODULE_DESCRIPTION(DRIVER_DESC);
- MODULE_LICENSE("GPL");
- void** my_table;
- struct idt
- {
- unsigned short offset_low;
- unsigned short sel;
- unsigned char none,flags;
- unsigned short offset_high;
- }__attribute__ ((packed));
- #define gdb_printk(format,args...) \
- printk(KERN_INFO "Entry Function:%s-%s-%d "format,__FILE__,__FUNCTION__,__LINE__,##args)
- static unsigned long get_syscall_table()
- {
- #define OFFSET_SYSCALL 100
- unsigned char idtr[6] = {0};
- struct idt *idt;
- unsigned int sys_call_off = 0;
- unsigned int retval;
- // char sc_asm[OFFSET_SYSCALL] = {0};
- asm (
- "sidt %0"
- :"=m"(idtr)
- :
- // :"a"(idtrp)
- :"memory"
- );
- gdb_printk("idt base 0x%x\t limit 0x%x\n",*(unsigned int *)(idtr+2),*(unsigned short *)idtr);
- idt = (struct idt *)(*(unsigned int *)&idtr[2] + 8 * 0x80);
- // gdb_printk("idt offset1 is 0x%x\n",idt->offset_low);
- gdb_printk("syscall offset is 0x%x\n",sys_call_off);
- return 0;
- }
- static int intercept_init(void)
- {
- my_table = (void **)get_syscall_table();
- if(my_table == NULL)
- return -1;
- gdb_printk("syscall table %p\n",(void *)my_table);
- return 0;
- }
- static int __init syscall_init(void)
- {
- int ret;
- gdb_printk("entry syscall module\n");
- ret = intercept_init();
- return 0;
- }
- static void __exit syscall_exit(void)
- {
- gdb_printk("exit syscall module\n");
- }
- module_init(syscall_init);
- module_exit(syscall_exit);
复制代码 Makefile- TARGET:=syscall
- syscall-objs:=main.o misc.o
- obj-m:=$(TARGET).o
- KERNELDIR:=/lib/modules/${shell uname -r}/build
- PWD:=${shell pwd}
- .PHONY:install uninstall clean
- default:
- $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
- install:
- insmod $(TARGET).ko
- uninstall:
- rmmod $(TARGET).ko
- clean:
- rm -rf *.o *.mod.c Module.*
复制代码 |
|