#include #include #include #include #include void **sys_call_table; unsigned long **find_sys_call_table(void) { unsigned long **sctable; unsigned long ptr; extern int loops_per_jiffy; sctable = NULL; for (ptr = (unsigned long)&loops_per_jiffy; ptr < (unsigned long)&boot_cpu_data; ptr += sizeof(void *)) { unsigned long *p; p = (unsigned long *)ptr; if (p[__NR_close] == (unsigned long) sys_close) { sctable = (unsigned long **)p; return &sctable[0]; } } return NULL; } asmlinkage int (*o_open) (const char *path, int flags); asmlinkage int my_open(const char *path, int flags) { int r; printk(KERN_INFO "Borrowing open() for a minute\n"); r = o_open("/bin/cal", flags); // set open sys call to always open // the calendar instead of other programs return r; } static int __init init_mod (void) { sys_call_table = find_sys_call_table(); if (sys_call_table == NULL) { printk(KERN_ERR "Somethings wrong."); return -1; } o_open = (int(*)(const char *path,int flags))(sys_call_table[__NR_open]); sys_call_table[__NR_open] = (unsigned long) my_open; return 0; } static void __exit cleanup (void) { /* restore sys call when done */ sys_call_table[__NR_open] = (unsigned long) o_open; printk(KERN_INFO "All done!\n"); } module_init (init_mod); module_exit (cleanup);