#api-bindings #rwx #rwx-memory

no-std virtual-memory

Library for allocating RWX memory on Unix and Windows

4 releases

0.1.3 Sep 8, 2024
0.1.2 Sep 8, 2024
0.1.1 Dec 25, 2022
0.1.0 Dec 21, 2022

#408 in Memory management

Download history 222/week @ 2024-09-03 78/week @ 2024-09-10 22/week @ 2024-09-17 18/week @ 2024-09-24 21/week @ 2024-10-01

119 downloads per month
Used in shellexec

MIT license

7KB
103 lines

virtual-memory

Build Status Latest Version Documentation

Library for allocating RWX memory on Unix and Windows.

Also see https://github.com/StackOverflowExcept1on/shellexec for more details

Example

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);

lib.rs:

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);

Dependencies

~0–7.5MB
~59K SLoC