Skip to main content

il2cpp_bridge_rs/memory/
rw.rs

1/// Reads a value of type `T` from the given memory address.
2pub unsafe fn read<T: Copy>(addr: usize) -> Result<T, String> {
3    if addr == 0 {
4        return Err("null pointer read".to_string());
5    }
6    Ok(std::ptr::read(addr as *const T))
7}
8
9/// Writes a value of type `T` to the given memory address.
10pub unsafe fn write<T: Copy>(addr: usize, value: T) -> Result<(), String> {
11    if addr == 0 {
12        return Err("null pointer write".to_string());
13    }
14    std::ptr::write(addr as *mut T, value);
15    Ok(())
16}