I am working on a kernel module that intercepts the read function. It successfully intercepts read calls. But I cannot print the keyboard key presses by printing the buffer
. My goal is to intercept the keyboard key presses and change some keypresses based on the pid and key pressed. For example, I want to change the key "k" to "j" for pid= 4700.How can I log the keypress and modify a few, before application receives it. Is there a better way to do that instead of intercepting read sys call.
unsigned long read_test( const struct pt_regs *regs ) { unsigned int fd = regs->di; char *buf = (char*) regs->si; if ( fd != 0 ) { // fd == 0 --> stdin (sh, sshd) return original_read( regs ); } else { printk( "Reading string from keyboard %s\n", buf); return original_read( regs ); }}