Skip to content

FileManager.isExecutableFile fails for wow64 processes #860

@jakepetroules

Description

@jakepetroules

The following code, if compiled as an x86_64 process and run on an arm64 system, will claim that the command shell binary is not executable. This is because GetBinaryTypeW returns ERROR_BAD_EXE_FORMAT for emulated processes.

This is not necessarily a bug in Foundation, but a quirk in the Win32 APIs. It seems worth documenting this caveat, at least.

import Foundation
import WinSDK

let fm = FileManager()
let path = "C:\\Windows\\system32\\cmd.exe"
print("\(path) isExecutable = \(fm.isExecutableFile(atPath: path))") // false

var dwBinaryType: DWORD = .max
let ret = path.withCString(encodedAs: UTF16.self) { ptr in
    GetBinaryTypeW(ptr, &dwBinaryType)
}
let err = GetLastError()
print("\(ret) \(dwBinaryType) \(err)")

// err == ERROR_BAD_EXE_FORMAT

Metadata

Metadata

Assignees

Labels

windowsIssue regarding compiling/running on Windows

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions