Trait Op

Source
pub trait Op: Debug {
    // Required method
    fn write_to(&self, out: impl AsMut<[u8]>) -> Result<usize>;
}
Expand description

Generic interface for operations.

This trait describes a generic interface for operations. An operation is a function that outputs some data for building a payload.

Popular operations are implemented in this crates, such as ops::Fill, ops::WriteInteger or ops::WriteBuffer.

Required Methods§

Source

fn write_to(&self, out: impl AsMut<[u8]>) -> Result<usize>

Writes the operation to a buffer.

§Errors

error::Error::OutputBufferTooSmall: the provided output buffer is too small to contain the result of the operation.

§Examples

Writes an operation to a buffer.

use shellcoder::ops::Fill;
use shellcoder::Op as _;

let mut buffer = [0u8; 10];
Fill::new(10, b'A')
    .write_to(&mut buffer)?;
assert_eq!(&buffer, b"AAAAAAAAAA");

Writes to a buffer that is too small to contain the output of the operation.

use shellcoder::ops::WriteInteger;
use shellcoder::Op as _;

let mut buffer = [0u8; 3];
let error = WriteInteger::new_be(0xdeadbeefu32)
    .write_to(&mut buffer)
    .unwrap_err();
assert!(matches!(error, Error::OutputBufferTooSmall(4)));

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§

Source§

impl Op for Advance

Source§

impl Op for Fill

Source§

impl Op for WriteBuffer<'_>

Source§

impl<I> Op for WriteInteger<I>