This commit is contained in:
Jolan Rathelot
2024-04-15 13:24:34 +02:00
parent 2f8b9a1e37
commit c2114de992
4 changed files with 17 additions and 5 deletions

View File

@@ -56,10 +56,14 @@ static void __exit m_exit(void) {
struct linked_list_node *ptr, *tmp;
misc_deregister(&device);
size_t len = 0;
list_for_each_entry_safe(ptr, tmp, &keyboard_log, list){
len++;
list_del(&ptr->list);
kfree(ptr);
}
printk(KERN_INFO "Captured %zu Keyboard inputs", len);
free_irq(1,&key_logger);
mutex_destroy(&lock);
printk(KERN_INFO "Drivers and Interrupts (exit)\n");

View File

@@ -45,6 +45,10 @@ ssize_t read_keyboard_misc_device(struct file *file, char __user *buf, size_t co
char min = (tmp->when.tv_sec - (sys_tz.tz_minuteswest * 60)) / 60 % 60;
char hour = (tmp->when.tv_sec - (sys_tz.tz_minuteswest * 60)) / 60 / 60 % 24;
char *buffer = kmalloc(sizeof(char) * tmp->size, GFP_KERNEL);
if (!buffer) {
mutex_unlock(&lock);
return -ENOMEM;
}
memset(buffer, 0, tmp->size);
snprintf(buffer, tmp->size, "%02d:%02d:%02d \"%s\"", hour, min, sec, tmp->key.key_name);
if (tmp->key.ascii_value) {
@@ -58,6 +62,7 @@ ssize_t read_keyboard_misc_device(struct file *file, char __user *buf, size_t co
if (copy_to_user(buf + user_offset, buffer + node_offset, tmp->size - node_offset)) {
kfree(buffer);
mutex_unlock(&lock);
return -EFAULT;
}
kfree(buffer);