Trait shellcoder::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)));

Object Safety§

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>