1 unstable release

0.1.0 Nov 18, 2023

#241 in Windows APIs

27 downloads per month
Used in wrappe

BSD-2-Clause

115KB
2K SLoC

editpe

Crates.io Docs.rs Tests & Checks

Resource editor for portable executables.

Enables cross-platform parsing and modification of Windows executables and their resources.

Features

  • Parsing and introspection of portable executables
  • Resource editing and icon replacement
  • Resource transfer between files

Compared to other resource editors like rcedit, editpe takes great care to keep the modified executable in a valid state. It does this by parsing and rebuilding the complete resource directory as well as all file and section headers, keeping existing sections intact, and leaving any additional data at the end of the file in place.

Note that packed executables (like packed with UPX) might not start with a modified resource table and might have compressed resources that can not be read. If you need a packed executable with modified resources, edit the resources first, and pack it afterwards.

Usage

Library

See the tests for additional usage examples.

Example: Icon replacement

use editpe::Image;

let data = std::fs::read(BINARY_PATH)?;
let icon = std::fs::read(ICON_PATH)?;

// parse the executable image
let mut image = Image::parse(&data)?;

// get the resource directory
let mut resources = image.resource_directory().cloned().unwrap_or_default();

// set the icon in the resource directory
resources.set_icon(&image)?;

// set the resource directory in the image
image.set_resource_directory(resources)?;

// build an executable image with all changes applied
let target = image.data();

Example: Resource transfer

use editpe::Image;

let source = std::fs::read(SOURCE_PATH)?;
let target = std::fs::read(TARGET_PATH)?;

// parse the source executable image
let image = Image::parse(&source)?;

// get the source resource directory
let resources = image.resource_directory()?;

// parse the target executable image
let mut image = Image::parse(&target)?;

// set the resource directory in the target image
image.set_resource_directory(resources)?;

// build an executable image with all changes applied
let target = image.data();

Dependencies

~15MB
~98K SLoC