SHARE
TWEET

Untitled

a guest Mar 11th, 2011 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <linux/module.h>
  2. #include <linux/kernel.h>
  3. #include <linux/unistd.h>
  4.  
  5. typedef asmlinkage ssize_t (*sys_read_t)(unsigned int fd, char __user * buf, size_t count);
  6.  
  7. // Global variables
  8. void **sys_call_table = NULL;
  9.  
  10. sys_read_t sys_read_original = NULL;
  11.  
  12.  
  13. asmlinkage ssize_t sys_read_hooked(unsigned int fd, char __user * buf, size_t count)
  14. {
  15.         ssize_t ret;
  16.        
  17.         ret = sys_read_original(fd, buf, count);
  18.        
  19.         printk("hi\n");
  20.         return ret;
  21. }
  22.  
  23. int init_module(void)
  24. {
  25.        
  26.         printk(KERN_INFO "Hello World\n");
  27.        
  28.         sys_call_table = 0xc02bfaa0;
  29.        
  30.         printk("saving orig sys_read\n");
  31.         sys_read_original = sys_call_table[__NR_read];
  32.        
  33.         printk("hooking sys_read\n");
  34.         sys_call_table[__NR_read] = sys_read_hooked;
  35.        
  36.         return 0;
  37. }
  38.  
  39.  
  40. void cleanup_module(void)
  41. {
  42.         printk("restoring original sys_read\n");
  43.         sys_call_table[__NR_read] = sys_read_original; 
  44.        
  45.         printk(KERN_INFO "k thx bye\n");
  46. }
  47.  
  48.  
  49. MODULE_LICENSE("GPL");
  50.  
  51. MODULE_AUTHOR("corny");
  52. MODULE_DESCRIPTION("simple hello world");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top