From ddfbd579e3332f65ae2cf9490cca3c03d5084ea5 Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 12 Apr 2022 15:35:09 +0200 Subject: [PATCH] Peek and poke works --- ableos/src/rhai_shell/mod.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ableos/src/rhai_shell/mod.rs b/ableos/src/rhai_shell/mod.rs index 3134652..31ddc85 100644 --- a/ableos/src/rhai_shell/mod.rs +++ b/ableos/src/rhai_shell/mod.rs @@ -89,15 +89,16 @@ pub fn set_hostname(name: String) { } /// Examine a memory pointer -pub fn peek_memory(ptr: i64) -> u8 { - let ptr: usize = ptr.unsigned_abs() as _; +pub fn peek_memory(ptr: i64) -> i64 { println!(">:("); - unsafe { *(ptr as *const u8) } + unsafe { *(ptr as *const u8) as _ } } -pub fn poke_memory(ptr: i64, val: u8) { - let ptr: usize = ptr.unsigned_abs() as _; - unsafe { *(ptr as *mut u8) = val } +pub fn poke_memory(ptr: i64, val: i64) { + match val.try_into() { + Ok(val) => unsafe { *(ptr as *mut u8) = val }, + Err(_) => println!("Error: {val} cannot be converted into u8"), + } } pub fn ls() {