Skip to content

Fix FileManager.isExecutableFile for emulated x86 processes on ARM systems #1246

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

Merged
merged 1 commit into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ extension _FileManagerImpl {
func isExecutableFile(atPath path: String) -> Bool {
#if os(Windows)
return (try? path.withNTPathRepresentation {
var dwBinaryType: DWORD = 0
return GetBinaryTypeW($0, &dwBinaryType)
// Use SHGetFileInfo instead of GetBinaryType because the latter returns the wrong answer for x86 binaries running under emulation on ARM systems.
return (SHGetFileInfoW($0, 0, nil, 0, SHGFI_EXETYPE) & 0xFFFF) != 0
}) ?? false
#else
_fileAccessibleForMode(path, X_OK)
Expand Down
4 changes: 4 additions & 0 deletions Sources/FoundationEssentials/WinSDK+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ package var RRF_RT_REG_SZ: DWORD {
DWORD(WinSDK.RRF_RT_REG_SZ)
}

package var SHGFI_EXETYPE: UINT {
UINT(WinSDK.SHGFI_EXETYPE)
}

package var SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE: DWORD {
DWORD(WinSDK.SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE)
}
Expand Down