nabijaczleweli / rust-embed-resource

A Cargo build script library to handle compilation and inclusion of Windows resources, in the most resilient fashion imaginable
MIT License
173 stars 29 forks source link

MSVC on ARM #26

Closed nabijaczleweli closed 1 year ago

nabijaczleweli commented 3 years ago

As of present, src/windows_msvc.rs has an enum Arch { X86, X64 }, and picks the latter iff $TARGET starts with x86_64.

I don't own an aarch64 platform, but if there is someone who does, it'd be lovely if they could figure out what the ??? in {HKLM\SOFTWARE\Microsoft\Windows Kits\Installed Roots}\bin\*\???\*.exe (find_windows_10_kits_tool()) is or send a PR :)

tobywf commented 3 years ago

When I installed the Windows SDKs on a Windows Server 2019 VM (x64), I happened to get these directories:

C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\arm
C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\arm64
C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64
C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x86

I'm really not sure of arm - it doesn't include the standard resource executables like mc.exe and rc.exe. But arm64 does include both of these. So at least for ARM 64-bits it would seem like it is arm64. I'm happy to help further if I can, but don't personally have a use case for ARM or Windows ARM platform.

sempervictus commented 2 years ago

IIRC there are now ARM instances up on AWS which could proof this out a bit. Our own clouds are all x86_64 for now, but if/when we do get ARM metal into the fray i'll be happy to give you a slice to get this closed

EDIT: i'm scaffolding out a Meterpreter/Mettle replacement in Rust, hence trolling your repos for handy morsels.

micolous commented 1 year ago

I've got a Windows 11 arm64 machine (Windows ARM Dev Kit 2023) with the VS toolchain installed.

rc.exe is in these paths:

PS C:\Program Files (x86)\Windows Kits\10> ls .\bin\10.0.22621.0\*\rc.exe

    Directory: C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\arm64

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          2022-10-19    22:11          33240 rc.exe

    Directory: C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          2022-10-19    21:15          50656 rc.exe

    Directory: C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x86

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          2022-10-19    19:52          29160 rc.exe

Each of those binaries is native to the respective CPU (dumpbin /headers). Windows 11 on arm64 can run all of them, and Windows 10 can run arm64 and x86.

I have an arm folder in there as well, but it doesn't have an rc.exe, and doesn't have as many tools:

PS C:\Program Files (x86)\Windows Kits\10> ls .\bin\10.0.22621.0\arm\

    Directory: C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\arm

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----          2022-11-03    17:47                1033
d----          2022-11-03    17:47                AccChecker
d----          2022-11-03    17:47                AppAnalysis
d----          2022-11-03    17:47                PInvoke
d----          2022-11-03    17:47                ucrt
d----          2022-11-03    17:47                UIAVerify
-a---          2022-10-19    20:28         173544 accevent.exe
-a---          2022-10-19    14:33          79336 computerhardwareids.exe
-a---          2022-10-07    15:53           4714 config.mftx
-a---          2022-10-19    20:28        1219088 cppwinrt.exe
-a---          2022-10-07    16:05          50128 DeployUtil.exe
-a---          2022-10-19    20:28          42512 dgssexwithfilehandlelib.dll
-a---          2022-10-19    20:28         181776 dxcapsviewer.exe
-a---          2022-10-19    20:28          58888 event.dll
-a---          2022-10-19    20:28         497152 filetypeverifier.exe
-a---          2022-10-19    14:33         144872 filtdump.exe
-a---          2022-10-19    14:32         124392 filtreg.exe
-a---          2022-10-19    14:33          56296 ftquery.exe
-a---          2022-10-19    14:33         218608 ifilttst.exe
-a---          2022-10-07    16:01           1181 IFiltTst.Ini
-a---          2022-10-19    20:28         280088 inspect.exe
-a---          2022-10-19    14:33          46056 interop.searchapi.dll
-a---          2022-10-19    14:33          50152 interop.taskscheduler.dll
-a---          2022-10-19    20:28         198160 iviewers.dll
-a---          2022-10-19    20:26          28664 mbidgenerator.exe
-a---          2022-10-19    20:28         173528 mergemod.dll
-a---          2022-10-19    14:33         583144 mfdetours.dll
-a---          2022-10-19    14:33         312824 mftrace.exe
-a---          2022-10-19    14:33         169464 microsoft.win32.search.query.dll
-a---          2022-10-07    15:55            238 Microsoft.Windows.Build.Signing.mssign32.dll.manifest
-a---          2022-10-19    20:28          83464 MsiCert.exe
-a---          2022-10-19    20:28         161296 MsiDb.exe
-a---          2022-10-19    20:28          79376 MsiFiler.exe
-a---          2022-10-19    20:28          99800 MsiInfo.exe
-a---          2022-10-19    20:28          75288 Msimerg.exe
-a---          2022-10-19    20:28          75240 MsiMsp.exe
-a---          2022-10-19    20:28          83432 msisip.dll
-a---          2022-10-19    20:28          75280 MsiTran.exe
-a---          2022-10-19    20:27         108024 mssign32.dll
-a---          2022-10-19    14:33          75240 provisioningtesthelper.dll
-a---          2022-10-19    14:33          14671 ProvisioningTestHelper.psd1
-a---          2022-10-19    20:27         386544 signtool.exe
-a---          2022-10-07    15:55            968 signtool.exe.manifest
-a---          2022-10-19    20:28         251416 tedutil.dll
-a---          2022-10-19    20:28         177680 topoedit.exe
-a---          2022-10-19    14:29         128528 tracelog.exe
-a---          2022-10-19    20:28         349720 WiLogUtl.exe
-a---          2022-10-19    14:32         275960 wintrust.dll
-a---          2022-10-19    14:33         107992 wstraceutil.exe

The arm directory there is for 32-bit ARM Windows systems, which aren't made anymore. All the Windows 11 on ARM stuff is for arm64.

For completeness, the registry entries are:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots]
"{B2AD0351-DFF5-E3E1-8BBA-4989171AECFA}"="Application Verifier arm64 External Package (DesktopEditions) arm64"
"KitsRoot10"="C:\\Program Files (x86)\\Windows Kits\\10\\"
"{792F70BE-2506-D2DE-9186-7B6F32491B36}"="Application Verifier arm64 External Package (OnecoreUAP) arm64"
"AppVerifierArm64AutomationRoot"="C:\\Program Files\\Application Verifier\\"
"{DCC3D21A-5987-CAD4-99B6-D533D2B2D4FC}"="Universal CRT Tools arm64 arm64"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots\10.0.22621.0]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots\10.0.22621.0\Installed Options]
"OptionId.UWPManaged"=dword:00000001
"OptionId.AvrfExternal"=dword:00000001
nabijaczleweli commented 1 year ago

hm. smells to me like this is the same format find_windows_10_kits_tool() understands if it also sought "arm64"; can you try the current master branch (at least 3f15f68171effcdeab310108f64e60e45f1fafae)?

micolous commented 1 year ago

Thanks!

At the time I wrote that comment, I hadn't actually built it on arm64 yet, but it turns out embedding a manifest currently works with and without this patch (because of binary emulation).

However, I think that the logic in 3f15f68 is wrong, and would fail to build arm64 binaries with MSVC on an x86 or x86_64 system, but I don't have a x86 or x86_64 Windows machine in front of me to test at the moment.

For MSVC's rc.exe what matters is the architecture of the host rather the target; so if arm64/rc.exe is an arm64 binary like my machine:

# Use "Developer Command Prompt for VS 2022 / VS Build Tools" to set the PATH properly
C:\Program Files\Microsoft Visual Studio\2022\Preview> dumpbin /headers "C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\arm64\rc.exe"
Microsoft (R) COFF/PE Dumper Version 14.35.32019.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Dump of file C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\arm64\rc.exe

PE signature found

File Type: EXECUTABLE IMAGE

FILE HEADER VALUES
            AA64 machine (ARM64) <---
               6 number of sections
        9921E31C time date stamp
               0 file pointer to symbol table
               0 number of symbols
              F0 size of optional header
              22 characteristics
                   Executable
                   Application can handle large (>2GB) addresses

then I think building with cargo build --target aarch64-pc-windows-msvc would fail on x86 and x86_64. Likewise building for x86_64 would fail on an x86 Windows machine (but there aren't many of these around anymore).

nabijaczleweli commented 1 year ago

AppVeyor doesn't appear to have aarch64 targets, no. dc5b96e552c30d9d5ba4a991cf998b5454d56d94 makes it so we try to find rc.exe for $HOST, not $TARGET, instead. I unfortunately don't really have a way to test this, so

micolous commented 1 year ago

I've started a branch which will try to build on GitHub Actions, which should have all the ARM64 build tools available (micolous:aarch-ci).

I'm home again, so can test building on an x86_64 host... the tests appear to work locally (with https://github.com/nabijaczleweli/rust-embed-resource/commit/dc5b96e552c30d9d5ba4a991cf998b5454d56d94) building an arm64 binary on an x86_64 host, just need to fix up my CI scripts.

nabijaczleweli commented 1 year ago

Thanks for the testing so far – released as v2.2.0.