Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pe: add Terse Executable (TE) support #397

Merged
merged 2 commits into from
Apr 1, 2024

Conversation

Javagedes
Copy link
Contributor

@Javagedes Javagedes commented Mar 14, 2024

Add terse executable (TE) support to the PE module. A terse executable is a PE32/PE32+ binary with a reduced header size containing only the fields necessary for the binary to be properly executed by a Platform Initialization (PI) architecture compliant loader and executor. Terse executables are most commonly used by UEFI compliant firmware to reduce the overall size of the binary.

Only the header is replaced, and no other data is changed in a terse executable, resulting in all address values being invalid. The TE parser must take appropriate action to fix up addresses during parsing by adjusting the existing value by the difference between the stripped_size and the new size of the header.

closes #398

Copy link
Owner

@m4b m4b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this generally looks very good, thank you! i'm 50/50 on the fence about whether it should be it's own module, just so it's slightly more encapsulated, but it's such little code it may not be worth it. only minor nits, I'll give a chance to anyone else who wants to review, then i'm ok to merge this basically :)

src/pe/header.rs Outdated Show resolved Hide resolved
tests/bins/te/Readme.md Outdated Show resolved Hide resolved
tests/te.rs Show resolved Hide resolved
@Javagedes Javagedes force-pushed the add-terse-executable branch from 5946b89 to 64b0589 Compare March 18, 2024 15:37
@Javagedes
Copy link
Contributor Author

this generally looks very good, thank you! i'm 50/50 on the fence about whether it should be it's own module, just so it's slightly more encapsulated, but it's such little code it may not be worth it. only minor nits, I'll give a chance to anyone else who wants to review, then i'm ok to merge this basically :)

@m4b I'm not against moving it to it's own module if you prefer. At a minimum, it would clean up the #[cfg(feature = "te")] that I sprinkled throughout pe/mod.rs and pe/header.rs. Additionally, if more capabilities were added later, it would remove the possibility of having a bloated pe module, and the need of moving it to another module down the road.

Add terse executable (TE) support to the PE module. A terse executable
is a PE32/PE32+ binary with a reduced header size containing only the
fields necessary for the binary to be properly executed by a PI
architecture compliant loader and executor. Terse executables are most
commonly used by UEFI compliant firmware to reduce the overall size of
the binary.

Only the header is replaced, and no other data is changed in a terse
executable, resulting in all address values being invalid. The TE parser
must take appropriate action to fix up addresses during parsing by
adjusting the existing value by the difference between the
`stripped_size` and the new size of the header.
@Javagedes Javagedes force-pushed the add-terse-executable branch from 64b0589 to e4a24bf Compare March 18, 2024 15:45
@m4b m4b merged commit 47ee850 into m4b:master Apr 1, 2024
6 checks passed
@m4b
Copy link
Owner

m4b commented Apr 1, 2024

thanks @Javagedes this is great

note: non-breaking

@m4b
Copy link
Owner

m4b commented Apr 27, 2024

release in 0.8.1

ideeockus pushed a commit to ideeockus/goblin that referenced this pull request Jul 29, 2024
Add terse executable (TE) support to the PE module. A terse executable
is a PE32/PE32+ binary with a reduced header size containing only the
fields necessary for the binary to be properly executed by a PI
architecture compliant loader and executor. Terse executables are most
commonly used by UEFI compliant firmware to reduce the overall size of
the binary.

Only the header is replaced, and no other data is changed in a terse
executable, resulting in all address values being invalid. The TE parser
must take appropriate action to fix up addresses during parsing by
adjusting the existing value by the difference between the
`stripped_size` and the new size of the header.
m4b added a commit that referenced this pull request Aug 12, 2024
@m4b
Copy link
Owner

m4b commented Oct 21, 2024

released in 0.9.0, thank you for your patience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Terse Executable (TE) support to goblin
2 participants