#resources #pe #parser #file-header #section-header #coff #directory

no-std build editpe

Resource Editor for parsing and modification of Windows Portable Executables and their resources

3 unstable releases

0.2.1 Nov 16, 2024
0.2.0 Oct 10, 2024
0.1.0 Nov 18, 2023

#95 in Build Utils

Download history 738/week @ 2024-08-21 673/week @ 2024-08-28 1053/week @ 2024-09-04 851/week @ 2024-09-11 802/week @ 2024-09-18 707/week @ 2024-09-25 913/week @ 2024-10-02 1767/week @ 2024-10-09 1425/week @ 2024-10-16 1491/week @ 2024-10-23 2089/week @ 2024-10-30 2202/week @ 2024-11-06 2332/week @ 2024-11-13 1513/week @ 2024-11-20 1569/week @ 2024-11-27 1587/week @ 2024-12-04

7,326 downloads per month
Used in 11 crates (2 directly)

BSD-2-Clause

125KB
2.5K 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 modification of portable executables
  • Resource editing including icons, manifests, version info and more
  • 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

Add editpe as a dependency. Support for converting and resizing images in other formats when setting icons is provided by the image crate.

editpe = "0.2"
image = "*" # optional

The std and images features are enabled by default and can be disabled for no-std support.

See the tests for additional usage examples.

Example: Adding an icon to an executable

use editpe::Image;

let mut image = Image::parse_file("damocles.exe")?;

// get the resource directory
let mut resources = image.resource_directory().cloned().unwrap_or_default();
// set the icon file
resources.set_main_icon_file("sword.png")?;
// set the resource directory in the image
image.set_resource_directory(resources)?;

// write an executable image with all changes applied
image.write_file("damocles.exe");

Example: Transferring resources between executables

use editpe::Image;

let image = Image::parse_file("damocles.exe")?;
// get the resource directory from the source
let resources = image.resource_directory()?;

let mut image = Image::parse_file("fortuna.exe")?;
// copy the resource directory to the target
image.set_resource_directory(resources)?;

// write an executable image with all changes applied
image.write_file("fortuna.exe");

Dependencies

~2.1–3.5MB
~59K SLoC