Read section file data in whole 0x200-byte sectors, as Windows does #110
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/111"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by danielradosa on 2026-11-21T16:17:59Z.
Change
pe_map_imagecopiedmin(SizeOfRawData, VirtualSize)bytes starting exactly atPointerToRawData.LoadLibraryExWreads raw section data in whole0x200-byte file sectors instead. It roundsPointerToRawDatadown andPointerToRawData + SizeOfRawDataup to a multiple of0x200, copies that range up to the section's virtual size, and leaves bytes past the end of the file zero.pe_mapnow reads the same range. APointerToRawDataof zero still maps nothing. Refs #46.This builds on #107. The first two commits belong to #107; this PR's change is the last commit, which extends the
cpu_native_sectiontest from #107.Verification
cpu_native_sectioncompares every section of the register probe betweenLoadLibraryExWandpe_map, on the original and on six patched copies. Each rounding case is also checked to differ from an exact read of the header fields, so the test fails ifpe_mapgoes back to reading exactly atPointerToRawData.pe_mapfrom #107.rsrcPointerToRawData0.rdatastart inside a sector (PointerToRawData+ 0x10).rdatastart in the first sector (PointerToRawData0x100).rdataraw size below a sector (SizeOfRawData0x10).rdataraw data crossing a sector (start + 0x1f0,SizeOfRawData0x20).rsrcrounded end past the file (VirtualSize0x200,SizeOfRawData0x1f0, file 0x10 bytes shorter)In every differing case, the section
pe_mapmapped equals the exact read. Windows 11 build 26300.9974, MSVC 19.51.36256, Python 3.14.4:Full suite on this branch: 74 passed, 2 skipped (
bvh_wave64_*, capability skips on an RTX 4060 and WARP), 0 failed.Evidence and follow-up
Exploratory runs, not part of the test, separated the sector size from
FileAlignment. WithFileAlignmentpatched to0x400or0x1000, Windows still rounded the start down to0x200. For a raw size below one sector, Windows read to the next0x200boundary withFileAlignment0x400, but with0x1000it read further, at least to the0x219-byte virtual size of.rdata. The end rule forFileAlignment0x1000and above is open for another contributor.The rounding cases patch
.rdata. In.rsrc, a rounded start can put other data where the resource directory should be, andLoadLibraryExWthen fails withERROR_BAD_EXE_FORMAT.Also open:
pe_maprejects a section whose declared raw data runs past the end of the file ("section outside image"), whileLoadLibraryExWmaps it and zero-fills the missing bytes. Examples:.pdatawithPointerToRawData0xe00 in a 0xe00-byte file, or.rdataat 0xc00 with a 0x219-byte virtual size and 0x200 bytes left in the file. This PR does not change that.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T16:18:15Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
b67071aℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.