Struct exe::buffer::Buffer[][src]

pub struct Buffer { /* fields omitted */ }
Expand description

A buffer representing the PE file.

Implementations

Creates a new buffer with an optional size.

Creates a new buffer from a slice of data.

Creates a new buffer from disk data.

Get the length of the buffer.

Resize the buffer.

Get the buffer as a slice.

Get the buffer as a mutable slice.

Get the buffer as a pointer.

Get the buffer as a mutable pointer.

Append a vector of data to the buffer.

Check if the PE file is empty.

Extend the buffer with a data slice.

Convert the given offset value to a pointer in the buffer. The function is marked as unsafe because the offset isn’t validated.

Convert the given offset value to a mutable pointer in the buffer. The function is marked as unsafe because the offset isn’t validated.

Get the pointer to the end of the file. This pointer is unsafe because it points at the end of the buffer, which doesn’t contain data.

Convert a pointer to an offset. This returns Error::BadPointer if the pointer isn’t in the buffer range.

Converts a reference to an offset. Returns a Error::BadPointer error if the reference isn’t from the buffer.

Gets a reference to an object in the buffer data. This is ultimately how PE objects are created from the buffer.

use exe::buffer::Buffer;
use exe::types::{Offset, ImageDOSHeader, ImageNTHeaders32, NT_SIGNATURE};

let buffer = Buffer::from_file("test/compiled.exe").unwrap();
 
let dos_header = buffer.get_ref::<ImageDOSHeader>(Offset(0)).unwrap();
let nt_header = buffer.get_ref::<ImageNTHeaders32>(dos_header.e_lfanew).unwrap();
 
assert_eq!(nt_header.signature, NT_SIGNATURE);

Gets a mutable reference to an object in the buffer data.

Gets a slice reference of data in the buffer. This is how to get arrays in the buffer.

use exe::buffer::Buffer;
use exe::types::Offset;

let buffer = Buffer::from_file("test/compiled.exe").unwrap();
let mz = buffer.get_slice_ref::<u8>(Offset(0), 2).unwrap();
 
assert_eq!(mz, [0x4D, 0x5A]);

Gets a mutable slice reference of data in the buffer.

Get the size of a zero-terminated C-string in the data.

Gets the size of a zero-terminated UTF16 string in the data.

Get a zero-terminated C-string from the data. The thunk option is there to handle imports by name, whose null terminated value size is dependent on how long the string is (i.e., if it’s an odd length, an extra zero is appended).

use exe::buffer::Buffer;
use exe::types::{Offset, CCharString};

let buffer = Buffer::from_file("test/dll.dll").unwrap();
let dll_name = buffer.get_cstring(Offset(0x328), false, None).unwrap();

assert_eq!(dll_name.as_str(), "dll.dll");

Get a mutable zero-terminated C-string from the data.

Get a zero-terminated UTF16 string from the data.

Get a mutable zero-terminated UTF16 string from the data.

Get an ImageImportByName object at the given offset. See the documentation of ImageImportByName for an explanation of why this is needed.

Read arbitrary data from the buffer.

Read mutable arbitrary data from the buffer.

Write arbitrary data to the buffer.

Write a referenced object to the buffer.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.