From 916ca1e11f404f7e31669e8fdc78359923ac8b6e Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 16 Apr 2023 02:23:59 +0800 Subject: [PATCH] expand key injection API. this does mean your device is notably less secure if you're operating with usb serial turned on, as a host can just inject arbitrary commands into your device! --- services/keyboard/Cargo.toml | 5 +++-- services/keyboard/src/lib.rs | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/services/keyboard/Cargo.toml b/services/keyboard/Cargo.toml index 69ea7926a..1b725ed5c 100644 --- a/services/keyboard/Cargo.toml +++ b/services/keyboard/Cargo.toml @@ -29,7 +29,8 @@ hosted = ["utralib/hosted"] renode = ["utralib/renode"] dvt = [] debugprint = [] -debuginject = [] # used only if you want key injection via the UART +debuginject = [] # used only if you want direct key injection via serial or USB. Could be a security risk! rawserial = [] braille = [] -default = ["debuginject"] # "debugprint" +inject-api = [] # used by the serial feature in usb +default = ["debuginject", "inject-api"] # "debugprint" diff --git a/services/keyboard/src/lib.rs b/services/keyboard/src/lib.rs index 3a4f57290..4eadb4590 100644 --- a/services/keyboard/src/lib.rs +++ b/services/keyboard/src/lib.rs @@ -112,6 +112,16 @@ impl Keyboard { c as u32 as usize, 0, 0, 0 )).unwrap(); } + + /// This is used to shove keys into the keyboard module as if you were typing on the + /// physical keyboard. + #[cfg(feature="inject-api")] + pub fn inject_key(&self, c: char) { + send_message(self.conn, + Message::new_scalar(Opcode::InjectKey.to_usize().unwrap(), + c as u32 as usize, 0, 0, 0 + )).unwrap(); + } } use core::sync::atomic::{AtomicU32, Ordering};