-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix: Windows resource editing PE checksum and structure issues #21851
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
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This PR implements native Windows resource editing in Zig, replacing the previous rescle C++ implementation. Users can now customize Windows executables when using 'bun build --compile' with the following new options: - --windows-icon <path> Set custom executable icon - --windows-title <str> Set executable title/product name - --windows-publisher <str> Set company/publisher name - --windows-version <str> Set version (e.g. "1.2.3.4") - --windows-description <str> Set executable description - --windows-hide-console Hide console window (already existed) Example: ```bash bun build --compile \ --target=bun-windows-x64 \ --windows-icon=app.ico \ --windows-title="My Application" \ --windows-publisher="My Company" \ --windows-version="2.1.0.0" \ --windows-description="A powerful application built with Bun" \ index.ts ``` Implementation details: - Pure Zig implementation in windows_resources.zig - Removes C++ rescle dependency - Creates WindowsSettings struct to organize all Windows options - Supports cross-platform compilation (build Windows exe from Linux/macOS) - Fixed alignment issues using safe memory operations - Comprehensive test coverage in test/bundler/windows-resources-compile.test.ts This allows full customization of Windows executable metadata without external dependencies. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Implement VS_VERSIONINFO string table support with proper UTF-16LE encoding - Add icon embedding support (RT_ICON, RT_GROUP_ICON resources) - Add hide console window option - Fix resource table offset calculations to prevent integer overflow - Use bun.strings functions for proper UTF-8 to UTF-16 conversion - Add proper 32-bit alignment throughout VS_VERSIONINFO structure Co-authored-by: Claude <[email protected]>
- Add proper PE checksum calculation and update after modifications - Fix resource directory structure bugs that caused malformed resources - Fix icon and version resource nesting levels - Fix resource data entry offset calculations - Remove incorrect high bit setting for data entries This should resolve executables being rejected by Windows after resource modifications. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Collaborator
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR fixes critical bugs in the Windows resource editing feature that caused Windows to refuse to execute compiled binaries with embedded resources.
Issues Fixed
1. Missing PE Checksum Updates
2. Resource Directory Structure Bugs
Several bugs in the resource building logic were causing malformed resource directories:
total_table_size + total_data_entriestototal_table_size + (total_data_entries * @sizeOf(ResourceDataEntry))data_entries.* += @sizeOf(ResourceDataEntry)todata_entries.* += 1(count entries, not their byte size)3. Icon and Version Resource Structure
Testing
The fixes address the core issues identified in the existing Windows resources tests. The changes ensure:
Root Cause Analysis
The original implementation had several structural issues:
These issues combined to create executables that appeared to have correct metadata when examined with tools, but were rejected by Windows due to structural integrity problems.
🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]