Expand description
Sui is a library for embedding and extracting auxillary data from binary files.
§Examples
Embedding data in a Mach-O binary:
use libsui::Macho;
use std::fs::File;
let data = b"Hello, world!";
let exe = std::fs::read("tests/exec_mach64")?;
let mut out = File::create("tests/out")?;
Macho::from(exe)?
.write_section("__SECTION", data.to_vec())?
.build(&mut out)?;§Section name limits
Mach-O stores section names in a fixed 16-byte field, so names passed to
Macho::write_section must be at most 16 bytes long; longer names
return Error::InvalidObject. PE resource names (PortableExecutable::write_resource)
and ELF note section names (Elf::append) have no comparable 16-byte
limit.
§Packers (UPX, etc.)
Runtime packers compress the original program and decompress it back into
memory at startup, replacing the on-disk section layout with the packer’s
own envelope. Embedded sections, notes, and (in many cases) resources are
hidden inside the packed payload, so find_section will not see data
that was injected before packing.
There is no fully packer-proof embedding scheme that works the way NativeAOT does on .NET (NativeAOT owns both the producer and the runtime extractor, so it can decompress its own payload after the stub restores memory). The recommended workaround with libsui is to pack first, then inject — libsui’s writers operate on the final on-disk layout, so a resource/note/segment added after packing is not touched by the unpacker stub at startup. See the project README for per-format details.
Modules§
- apple_
codesign - intel_
mac - utils
- Utilities for detecting binary formats
Structs§
- Elf
- Macho
- Portable
Executable - A portable executable (PE)
Enums§
Functions§
- find_
section - find_
section_ in_ current_ image - Find a section in the currently loaded shared library (the image containing this code).