#include #include #include #include #include #include #include #include #define PROC_FILE_NAME "crypto_services" unsigned char buffer[1024*1024]; int read_out = 0; // This doesn't use offp properly, so don't copy this behavior! ssize_t read_simple(struct file *filp,char *buf,size_t count,loff_t *offp ) { if(read_out){ read_out = 0; return 0; } memcpy(buf, buffer, strlen(buffer)); read_out = 1; return strlen(buffer); } unsigned int call_count = 0; ssize_t write_simple(struct file *filp,const char *buf,size_t count,loff_t *offp) { int i; strncpy(buffer, buf, count); buffer[count] = 0; printk("Write was called (%u)! The user thinks they're going to write %s to a file.\n", call_count++, buffer); for(i = 0; i < count; i++){ if(buffer[i] <= 90 && buffer[i] >= 65) { // uppercase buffer[i] += 13; if(buffer[i] > 90) buffer[i] -= 26; } else if(buffer[i] <= 122 && buffer[i] >= 97) { // lowercase buffer[i] += 13; if(buffer[i] > 122) buffer[i] -= 26; } } printk("Encrypted: %s\n", buffer); return count; } struct file_operations proc_fops = { read: read_simple, write: write_simple }; int proc_init (void) { printk("We're in the kernel!\n"); proc_create(PROC_FILE_NAME,0,NULL,&proc_fops); return 0; } void proc_cleanup(void) { remove_proc_entry(PROC_FILE_NAME,NULL); } MODULE_LICENSE("GPL"); module_init(proc_init); module_exit(proc_cleanup);