Skip to main content

Crate libsui

Crate libsui 

Source
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
PortableExecutable
A portable executable (PE)

Enums§

Error

Functions§

find_section
find_section_in_current_image
Find a section in the currently loaded shared library (the image containing this code).