pub trait Binary {
Show 14 methods
// Provided methods
fn entrypoint(&self) -> u64 { ... }
fn imagebase(&self) -> u64 { ... }
fn is_pie(&self) -> bool { ... }
fn has_nx(&self) -> bool { ... }
fn original_size(&self) -> u64 { ... }
fn debug_info(&self) -> Option<DebugInfo<'_>> { ... }
fn disassemble(&self, address: u64, size: u64) -> InstructionsIt<'_> ⓘ { ... }
fn disassemble_symbol(&self, name: &str) -> InstructionsIt<'_> ⓘ { ... }
fn disassemble_address(&self, address: u64) -> InstructionsIt<'_> ⓘ { ... }
fn disassemble_slice(
&self,
slice: &[u8],
address: u64
) -> InstructionsIt<'_> ⓘ { ... }
fn assemble(&mut self, address: u64, asm: &str) -> Vec<u8> { ... }
fn assemble_with_config(
&mut self,
address: u64,
asm: &str,
config: &AssemblerConfig
) -> Vec<u8> { ... }
fn page_size(&self) -> u64 { ... }
fn load_debug_info(&mut self, path: &Path) -> Option<DebugInfo<'_>> { ... }
}
Expand description
Generic interface representing a binary executable.
This trait provides a unified interface across multiple binary formats such as ELF, PE, Mach-O, and others. It enables users to access binary components like headers, sections, symbols, relocations, and functions in a format-agnostic way.
Provided Methods§
fn entrypoint(&self) -> u64
fn entrypoint(&self) -> u64
Binary’s entrypoint
fn original_size(&self) -> u64
fn original_size(&self) -> u64
Original file size of the binary
fn debug_info(&self) -> Option<DebugInfo<'_>>
fn debug_info(&self) -> Option<DebugInfo<'_>>
Return the debug info if present. It can be either a
crate::pdb::DebugInfo
or crate::dwarf::DebugInfo
.
For ELF and Mach-O binaries, it returns the given DebugInfo object only if the binary embeds the DWARF debug info in the binary itself.
For PE file, this function tries to find the external PDB using
the crate::pe::debug::CodeViewPDB::filename
output (if present). One can also
use crate::pdb::load
or crate::pdb::DebugInfo::from
to get PDB debug
info.
fn disassemble(&self, address: u64, size: u64) -> InstructionsIt<'_> ⓘ
fn disassemble(&self, address: u64, size: u64) -> InstructionsIt<'_> ⓘ
Disassemble code starting at the given virtual address and with the given size.
let insts = binary.disassemble(0xacde, 100);
for inst in insts {
println!("{}", inst.to_string());
}
See also crate::assembly::Instruction
and crate::assembly::Instructions
fn disassemble_symbol(&self, name: &str) -> InstructionsIt<'_> ⓘ
fn disassemble_symbol(&self, name: &str) -> InstructionsIt<'_> ⓘ
Disassemble code for the given symbol name
let insts = binary.disassemble_symbol("__libc_start_main");
for inst in insts {
println!("{}", inst.to_string());
}
See also crate::assembly::Instruction
and crate::assembly::Instructions
fn disassemble_address(&self, address: u64) -> InstructionsIt<'_> ⓘ
fn disassemble_address(&self, address: u64) -> InstructionsIt<'_> ⓘ
Disassemble code at the given virtual address
let insts = binary.disassemble_address(0xacde);
for inst in insts {
println!("{}", inst.to_string());
}
See also crate::assembly::Instruction
and crate::assembly::Instructions
fn disassemble_slice(&self, slice: &[u8], address: u64) -> InstructionsIt<'_> ⓘ
fn disassemble_slice(&self, slice: &[u8], address: u64) -> InstructionsIt<'_> ⓘ
Disassemble code provided by the given slice at the specified address
parameter.
See also crate::assembly::Instruction
and crate::assembly::Instructions
fn assemble(&mut self, address: u64, asm: &str) -> Vec<u8>
fn assemble(&mut self, address: u64, asm: &str) -> Vec<u8>
Assemble and patch the provided assembly code at the specified address.
The generated assembly is returned by the function
let mut bin = get_binary();
let Vec<u8> bytes = bin.assemble(0x12000440, r#"
xor rax, rbx;
mov rcx, rax;
"#);
fn assemble_with_config(
&mut self,
address: u64,
asm: &str,
config: &AssemblerConfig
) -> Vec<u8>
fn assemble_with_config( &mut self, address: u64, asm: &str, config: &AssemblerConfig ) -> Vec<u8>
Same as Binary::assemble
but this function takes an extra AssemblerConfig
that
is used to configure the assembly engine: dialect, symbols definitions.
fn page_size(&self) -> u64
fn page_size(&self) -> u64
Get the default memory page size according to the architecture and the format of the current binary
fn load_debug_info(&mut self, path: &Path) -> Option<DebugInfo<'_>>
fn load_debug_info(&mut self, path: &Path) -> Option<DebugInfo<'_>>
Load and associate an external debug file (e.g., DWARF or PDB) with this binary.
This method attempts to load the debug information from the file located at the given path,
and binds it to the current binary instance. If successful, it returns the
loaded crate::DebugInfo
object.