pub struct AssemblyResult { /* private fields */ }Expand description
The result of a successful assembly operation.
Implementations§
Source§impl AssemblyResult
impl AssemblyResult
Sourcepub fn bytes(&self) -> &[u8] ⓘ
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]);Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
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]);Sourcepub fn len(&self) -> usize
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)Sourcepub fn is_empty(&self) -> bool
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());Sourcepub fn labels(&self) -> &[(String, u64)]
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"));Sourcepub fn label_address(&self, name: &str) -> Option<u64>
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);Sourcepub fn relocations(&self) -> &[AppliedRelocation]
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");Sourcepub fn base_address(&self) -> u64
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);Trait Implementations§
Source§impl Clone for AssemblyResult
impl Clone for AssemblyResult
Source§fn clone(&self) -> AssemblyResult
fn clone(&self) -> AssemblyResult
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for AssemblyResult
impl RefUnwindSafe for AssemblyResult
impl Send for AssemblyResult
impl Sync for AssemblyResult
impl Unpin for AssemblyResult
impl UnwindSafe for AssemblyResult
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more