Crate virtual_memory

source ·
Expand description

Library for allocating RWX memory on Unix and Windows

use virtual_memory::*;

let buf = &[
    //mov eax, 1337
    0xb8, 0x39, 0x05, 0x00, 0x00,
    //ret
    0xc3,
];

let mut memory = VirtualMemory::new(buf.len()).expect("failed to allocate rwx memory");
memory.copy_from_slice(buf);

let f: extern "C" fn() -> u32 = unsafe { std::mem::transmute(memory.as_ptr()) };
assert_eq!(f(), 1337);

Structs

Wraps OS-specific functionality related to allocation RWX memory

Enums

Describes possible errors, currently it’s only memory allocation error

Type Definitions

Custom Result type that is used by this crate