region

Travis build status Appveyor build status crates.io version Language (Rust)

A Rust library for dealing with memory regions.

It is implemented using platform specific APIs (e.g VirtualQuery, VirtualLock, mprotect, mlock).

Documentation

https://docs.rs/region

Installation

Add this to your Cargo.toml:

toml [dependencies] region = "0.0.6"

and this to your crate root:

rust extern crate region;

Example

```rust // Assembly (x86) for returning an integer (5) let ret5 = [0xB8, 0x05, 0x00, 0x00, 0x00, 0xC3]; let mut view = View::new(ret5.as_ptr(), ret5.len()).unwrap();

view.execwithprot(Protection::ReadWriteExecute, || { // Within this closure the memory is read, write & executable let x: extern "C" fn() -> i32 = unsafe { std::mem::transmute(ret5.asptr()) }; asserteq!(x(), 5); }).unwrap();

// The protection flags have been restored asserteq!(view.getprot(), Some(Protection::Read)); ```

Platforms

This library has (so far) support for Windows, Linux & macOS.