diff --git a/readme.md b/readme.md index 2167466..5f04b08 100644 --- a/readme.md +++ b/readme.md @@ -130,7 +130,7 @@ i↑ ⟶ up↑ rightalt↑ ⟶ ∅ ``` -Load uinput module (**kbct will not function but will not produce an error if the uinput module is not loaded**) +Load uinput module ```bash sudo modprobe uinput diff --git a/src/main.rs b/src/main.rs index c5f7d8b..edb3c4c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -267,7 +267,32 @@ impl EventObserver for KeyLogger { } } +fn check_uinput_loaded() -> bool { + let mut kernel_version = std::fs::read_to_string("/proc/version").unwrap(); + kernel_version = kernel_version.to_string().split(' ').nth(2).unwrap().to_string(); + + let built_in_modules = std::fs::read_to_string(String::from("/lib/modules/") + &kernel_version + &String::from("/modules.builtin")).unwrap(); + for line in built_in_modules.lines() { + if line.eq("kernel/drivers/input/misc/uinput.ko") { + info!("'uinput' is built into running kernel version: {}", kernel_version); + return true; + } + } + + let modules = std::fs::read_to_string("/proc/modules").unwrap(); + for line in modules.lines() { + if line.starts_with("uinput ") { + info!("'uinput' module is loaded"); + return true; + } + } + return false; +} + fn start_mapper_from_file_conf(config_file: String) -> Result<()> { + if !check_uinput_loaded() { + panic!("'uinput' module must be loaded OR built into the kernel"); + } let config = serde_yaml::from_str( &*std::fs::read_to_string(config_file.as_str()) .expect(&format!("Could not open file {}", config_file)))