Trait CodeManipulator

Source
pub trait CodeManipulator {
    // Required method
    unsafe fn write_code<const L: usize>(addr: *mut c_void, data: &[u8; L]);
}
Expand description

Manipulate memory protection in code region.

Required Methods§

Source

unsafe fn write_code<const L: usize>(addr: *mut c_void, data: &[u8; L])

Write data as code instruction to addr.

The addr is not aligned, you need to align it you self. The length is not too long, usually 5 bytes.

§Safety

This method will do best effort to make the code region writable, and then write the data into the code region. If the code region is still not writable, the data writing will become a UB. Never call this method when there are multi-threads running. Spawn threads after this method is called. This method may manipulate code region memory protection, and if other threads are executing codes in the same code page, it may lead to unexpected behaviors.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§