> module
std::re
Xur's reverse engineering standard library module
std::re is a toolkit for binary analysis, live process interaction, machine code disassembly, and .NET assembly manipulation. Each part is backed by a dedicated Rust crate and lives in a submodule: std::re::pe, std::re::elf (binary files, via pewter), std::re::proc (live processes, via procodile), std::re::asm::x86 (machine code, via iced-x86), and std::re::dotnet, with its il2cpp and runtime submodules (.NET, via hao). Each has its own page; see SEE ALSO.
std::re itself holds AnyImage, which reads a PE or ELF file the way a loader would map it, and the demangling functions (see xur.std(7)).
> functions
Demangle a C++ symbol name: tries the Itanium scheme (GCC/Clang), then MSVC. None if it is neither.
Demangle an Itanium (GCC/Clang) name, one starting with _Z. None if it isn't a valid Itanium symbol.
> types
An AnyImage is a PE or ELF file read by virtual address, as it will be once loaded at its preferred base and relocated. Its reads take virtual addresses and return None for addresses nothing maps. It can also be edited in place and written back out, the same way for either format.
A PE or ELF image, as detected by [`AnyImage::load`].
| AnyImage::Elf(ElfImage) | |
| AnyImage::Pe(PeImage) |
Read the file at path and detect whether it is PE or ELF.
Append a loaded section holding data and return its virtual address. perms is "ro" (read-only data), "rw" (writable data) or "rx" (code); case is ignored.
For an ELF, the file as an elf::ElfFile (see xur.std.re.elf(7)); None for PE.
For a PE, an editable copy as a pe::ImageDef (see xur.std.re.pe(7)); None for ELF.
The NUL-terminated string at vaddr, decoded as UTF-8 with invalid bytes replaced.
The (start,\end) virtual-address ranges where data lives: a PE's non-code sections, or an ELF's non-executable loaded segments.
The exported symbols: a PE's export table, or an ELF's defined dynamic functions and objects. Each Export has a name, an ordinal (PE only) and a location, which is an ExportLocation (an address, or a PE forwarder such as "NTDLL.RtlAllocateHeap").
any_image.is_64() -> boolWhether pointers are 64-bit.
any_image.machine() -> Option<ImageFileMachine>The target machine as a PE machine type, or None for an ELF machine PE has no name for.
The pointer-sized value at vaddr, as it will be after relocation.
The indexth pointer of an array at base: the pointer at base\+\index\*\pointer_size().
count consecutive pointers from vaddr, or None if any of them is unmapped.
Serialize the image with its edits. A PE is rebuilt (header sizes, section offsets and checksum recomputed); an ELF keeps its layout, with patches applied and new sections appended.
A symbol exported by an image.
| name | Option<str> | `None` for a PE export by ordinal only. |
| ordinal | Option<u32> | The PE ordinal. ELF symbols have none. |
| location | ExportLocation |
> examples
use std::io;
use std::re::AnyImage;
fn main() -> Result<(), str> {
let image = AnyImage::open("/bin/ls")?;
io::println("{} {}-bit", image.format(), image.pointer_size() * 8);
for export in image.exports()? {
if let Some(name) = export.name {
io::println("{}", name);
}
}
Ok(())
}use std::fs;
use std::re::AnyImage;
fn main() -> Result<(), str> {
let image = AnyImage::open("game.dll")?;
let vaddr = image.add_section(".patch", b"\\x90\\xc3", "rx")?;
fs::write_bytes("game_patched.dll", image.write()?);
Ok(())
}