Skip to main content

AssemblyResult

Struct AssemblyResult 

Source
pub struct AssemblyResult { /* private fields */ }
Expand description

The result of a successful assembly operation.

Implementations§

Source§

impl AssemblyResult

Source

pub fn bytes(&self) -> &[u8]

Get the assembled bytes.

§Examples
use asm_rs::{Assembler, Arch};

let mut asm = Assembler::new(Arch::X86_64);
asm.emit("nop")?;
let result = asm.finish()?;
assert_eq!(result.bytes(), &[0x90]);
Source

pub fn into_bytes(self) -> Vec<u8>

Consume and return the bytes.

§Examples
use asm_rs::{Assembler, Arch};

let mut asm = Assembler::new(Arch::X86_64);
asm.emit("ret")?;
let bytes = asm.finish()?.into_bytes();
assert_eq!(bytes, vec![0xC3]);
Source

pub fn len(&self) -> usize

Get the byte count.

§Examples
use asm_rs::{Assembler, Arch};

let mut asm = Assembler::new(Arch::X86_64);
asm.emit("nop\nret")?;
let result = asm.finish()?;
assert_eq!(result.len(), 2); // nop(1) + ret(1)
Source

pub fn is_empty(&self) -> bool

Whether the result is empty.

§Examples
use asm_rs::{Assembler, Arch};

let result = Assembler::new(Arch::X86_64).finish()?;
assert!(result.is_empty());
Source

pub fn labels(&self) -> &[(String, u64)]

Get label addresses (name, absolute address).

§Examples
use asm_rs::{Assembler, Arch};

let mut asm = Assembler::new(Arch::X86_64);
asm.emit("start: nop\nend: ret")?;
let result = asm.finish()?;
let labels = result.labels();
assert!(labels.iter().any(|(name, _)| name == "start"));
assert!(labels.iter().any(|(name, _)| name == "end"));
Source

pub fn label_address(&self, name: &str) -> Option<u64>

Look up a label address by name.

§Examples
use asm_rs::{Assembler, Arch};

let mut asm = Assembler::new(Arch::X86_64);
asm.emit("start: nop\nnop\nend: ret")?;
let result = asm.finish()?;
assert_eq!(result.label_address("start"), Some(0));
assert_eq!(result.label_address("end"), Some(2));
assert_eq!(result.label_address("missing"), None);
Source

pub fn relocations(&self) -> &[AppliedRelocation]

Get the applied relocations — where label references were patched.

§Examples
use asm_rs::{Assembler, Arch};

let mut asm = Assembler::new(Arch::X86_64);
asm.emit("target: jmp target")?;
let result = asm.finish()?;
let relocs = result.relocations();
assert!(!relocs.is_empty());
assert_eq!(relocs[0].label, "target");
Source

pub fn base_address(&self) -> u64

Get the base address used during assembly.

§Examples
use asm_rs::{Assembler, Arch};

let mut asm = Assembler::new(Arch::X86_64);
asm.base_address(0x1000);
asm.emit("nop")?;
let result = asm.finish()?;
assert_eq!(result.base_address(), 0x1000);
Source

pub fn listing(&self) -> String

Produce a human-readable listing of address, hex bytes.

Labels are shown on their own line with their resolved address. Machine code is shown in rows of up to 8 bytes each.

§Example output
00000000                  entry:
00000000  55              push rbp
00000001  4889E5          mov rbp, rsp

Trait Implementations§

Source§

impl Clone for AssemblyResult

Source§

fn clone(&self) -> AssemblyResult

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AssemblyResult

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.