Click here to Skip to main content
15,860,859 members
Articles / Programming Languages / C#

Determine Platform Affinity 32 bit, 64 bit or Any CPU for a Managed .NET PE

Rate me:
Please Sign up or sign in to vote.
4.67/5 (2 votes)
18 Dec 2016CPOL1 min read 14.5K   2   1
How to check platform affinity for a managed .NET process executable (PE)

In my earlier post, I discussed how PEs in .NET can target different platforms and the subtle differences between them.
In this post, I’ll discuss how one can determine the platform (architecture) that a managed .NET PE targets.

For this, we’ll use a tool called CorFlags which come automatically installed with Visual Studio IDE. We’ll use the Visual Studio Developer Command Prompt to use this tool.

Syntax

C#
CorFlags.exe assembly [options]

For more details on the options, refer to the MSDN link.

Now, based on the way in which the PE has been compiled, we can determine the platform affinity as follows:

CPU ArchitecturePE32BITREQ32BITPREF
x86(32-bit)PE3210
x64(64-bit)PE32+00
Any CPUPE3200
Any CPU 32-bit preferredPE3201

The default case in Visual Studio IDE is Any CPU with 32-bit preferred.
Hence, if we run CorFlags tool in this case, we’ll get…

<code>E:\Dev\Projects\TestApp\TestApp\bin\Debug>corflags TestApp.exe
Microsoft (R) .NET Framework CorFlags Conversion Tool.  Version  4.6.1055.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Version   : v4.0.30319
CLR Header: 2.5
PE        : PE32
CorFlags  : 0x20003
ILONLY    : 1
32BITREQ  : 0
32BITPREF : 1
Signed    : 0
</code>

As can be seen above, this is the case whereby the exe targets the default option of Any CPU with 32-bit preferred.

Similarly, as shown in the table, we can determine the platform affinity for other managed DLLs too.

Hope this was useful!

Abbreviations

PE: Process Executables (EXEs and DLLs)

References

The post Determine platform affinity 32 bit, 64 bit or Any CPU for a managed .NET PE appeared first on Sundeep Kamath's blog.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
Questionildsam Pin
R.D.H.21-Dec-16 5:46
R.D.H.21-Dec-16 5:46 
One can also run ildasm on the assembly and then examine the manifest. The corflags is dumped out and annotated to show, for example, "ILONLY" or whether the assembly is 32 or 64 bit only.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.