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!
This commit is contained in:
bunnie 2023-04-16 02:23:59 +08:00
parent 5a10bb8fd8
commit 916ca1e11f
2 changed files with 13 additions and 2 deletions

View file

@ -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"

View file

@ -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};