CorFlags on cloud

1-click AWS Deployment    1-click Azure Deployment

Overview

The CorFlags Conversion tool allows you to configure the CorFlags section of the header of a portable executable image.

This tool is automatically installed with Visual Studio and with the Windows SDK. To run the tool, we recommend that you use the Visual Studio Command Prompt or the Windows SDK Command Prompt (CMD Shell). These utilities enable you to run the tool easily, without navigating to the installation folder. For more information, see Visual Studio and Windows SDK Command Prompts.

CorFlags.exe (CorFlags Conversion Tool)

The CorFlags Conversion tool allows you to configure the CorFlags section of the header of a portable executable image.

This tool is automatically installed with Visual Studio. To run the tool, use the Developer Command Prompt for Visual Studio (or the Visual Studio Command Prompt in Windows 7).

Syntax

CorFlags.exe assembly [options]  

Parameters

TABLE 1
Required parameter Description
assembly The name of the assembly for which to configure the CorFlags.
TABLE 2
Option Description
-32BIT[REQ]+ Sets the 32BITREQUIRED flag.
-32BIT[REQ]- Clears the 32BITREQUIRED flag.
-32BITPREF+ Sets the 32BITPREFERRED flag. The app runs as a 32-bit process even on 64-bit platforms. Set this flag only on EXE files. If the flag is set on a DLL, the DLL fails to load in 64-bit processes, and a BadImageFormatException exception is thrown. An EXE file with this flag can be loaded into a 64-bit process.

New in the .NET Framework 4.5.

-32BITPREF- Clears the 32BITPREFERRED flag.

New in the .NET Framework 4.5.

-? Displays command syntax and options for the tool.
-Force Forces an update even if the assembly is strong-named. Important: If you update a strong-named assembly, you must sign it again before executing its code.
-help Displays command syntax and options for the tool.
-ILONLY+ Sets the ILONLY flag.
-ILONLY- Clears the ILONLY flag.
-nologo Suppresses the Microsoft startup banner display.
-RevertCLRHeader Reverts the CLR header version to 2.0.
-UpgradeCLRHeader Upgrades the CLR header version to 2.5. Note: Assemblies must have a CLR header version of 2.5 or greater to run natively.

 

xCorFlags.exe (CorFlags Conversion Tool)

The CorFlags Conversion tool allows you to configure the CorFlags section of the header of a portable executable image.

This is a cross-platform version of the Microsoft CorFlags tool that is included in the .Net Framework SDK installations.

  • MSDN Documentation for CorFlag.exe

This xplat version strives to be argument option and output compatible (using /nologo) with the Microsoft version.

*Note: Platform independent argument prefixes can be used: ‘/’ or ‘-’ *

Usage:

Mono/.NET Framework CorFlags Conversion Tool.  Version  0.9.5643.21314
Copyright (c) SushiHangover.  All rights reserved.

Windows Usage: xCorflags.exe Assembly [options]
 X-Plat Usage: mono xcorflags.exe Assembly [options]

If no options are specified, the flags for the given image are displayed.

     Options: (/ or - prefixed
     /ILONLY+ /ILONLY-       Sets/clears the ILONLY flag
     /32BITREQ+ /32BITREQ-   Sets/clears the bits indicating 32-bit x86 only
     /32BITPREF+ /32BITPREF- Sets/clears the bits indicating 32-bit preferred
     /UpgradeCLRHeader       Upgrade the CLR Header to version 2.5
     /RevertCLRHeader        Revert the CLR Header to version 2.0
     /Force                  Force an assembly update even if the image is
         strong name signed.
         WARNING: Updating a strong name signed assembly
         will require the assembly to be resigned before
         it will execute properly.
     /nologo                 Prevents corflags from displaying logo

Output:

When running with the nologo option, the output should be compatible with Microsoft’s version, a nice to have for those who already are used the output to CorFlags.exe or those that have existing scripts.

mono ./CorFlags.exe /nologo CorFlags.exe
Version   : v4.0.30319
CLR Header: 2.5
PE        : PE32
CorFlags  : 0x3
ILONLY    : 1
32BITREQ  : 1
32BITPREF : 0
Signed    : 0

Without using the nologo argument:

mono ./CorFlags.exe CorFlags.exe SudoKnights.exe
Mono/.NET Framework CorFlags Conversion Tool.  Version  0.9.5643.21314
Copyright (c) SushiHangover.  All rights reserved.

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

versus:

PS> .\CorFlags.exe .\Test\x64\Release\ExeForTesting.exe
Microsoft (R) .NET Framework CorFlags Conversion Tool.  Version  4.0.30319.17929
Copyright (c) Microsoft Corporation.  All rights reserved.

Version   : v4.0.30319
CLR Header: 2.5
PE        : PE32+
CorFlags  : 0x1
ILONLY    : 1
32BITREQ  : 0
32BITPREF : 0
Signed    : 0

Built and tested using Mono 4.0.1 on:

  • Windows
  • OS-X
  • Linux

How to learn processor achitecture of an assembly ?

Powershell:

[reflection.assemblyname]::GetAssemblyName("${pwd}\Microsoft.SharePoint.dll") | fl

https://msdn.microsoft.com/tr-tr/library/system.reflection.processorarchitecture(v=vs.110).aspx

Amd64 A 64-bit AMD processor only.
Arm An ARM processor.
IA64 A 64-bit Intel processor only.
MSIL Neutral with respect to processor and bits-per-word. (AnyCPU)
None An unknown or unspecified combination of processor and bits-per-word.
X86 A 32-bit Intel processor, either native or in the Windows on Windows environment on a 64-bit platform (WOW64).


Or Corflags.exe

https://docs.microsoft.com/en-us/dotnet/framework/tools/corflags-exe-corflags-conversion-tool

CPU Architecture           PE      32BITREQ   32BITPREF
 ------------------------   -----   --------   ---------
 x86 (32-bit)               PE32           1           0
 x64 (64-bit)               PE32+          0           0
 Any CPU                    PE32           0           0
 Any CPU 32-Bit Preferred   PE32           0           1

Mono sets the CorFlags with mcs/mcs/assembly.cs :

anycpu (default) compiles your assembly to run on any platform. Your application runs as a 64-bit process whenever possible and falls back to 32-bit when only that mode is available. anycpu32bitpreferred compiles your assembly to run on any platform. Your application runs in 32-bit mode on systems that support both 64-bit and 32-bit applications. You can specify this option only for projects that target the .NET Framework 4.5. ARM compiles your assembly to run on a computer that has an Advanced RISC Machine (ARM) processor. x64 compiles your assembly to be run by the 64-bit common language runtime on a computer that supports the AMD64 or EM64T instruction set. x86 compiles your assembly to be run by the 32-bit, x86-compatible common language runtime. Itanium compiles your assembly to be run by the 64-bit common language runtime on a computer with an Itanium processor.

//These combine to specify the assembly types. Here is how they would look like for: // // anycpu: PE = PE32 and 32BIT = 0 // x86: PE = PE32 and 32BIT = 1 // 64-bit: PE = PE32+ and 32BIT = 0

PS> .\CorFlags.exe .\Test\anycpu\Release\DllForTesting.dll Microsoft (R) .NET Framework CorFlags Conversion Tool. Version 4.0.30319.17929 Copyright (c) Microsoft Corporation. All rights reserved.

Version : v4.0.30319 CLR Header: 2.5 PE : PE32 CorFlags : 0x1 ILONLY : 1 32BITREQ : 0 32BITPREF : 0 Signed : 0 PS> .\CorFlags.exe .\Test\anycpu\Release\ExeForTesting.exe Microsoft (R) .NET Framework CorFlags Conversion Tool. Version 4.0.30319.17929 Copyright (c) Microsoft Corporation. All rights reserved.

Version : v4.0.30319 CLR Header: 2.5 PE : PE32 CorFlags : 0x1 ILONLY : 1 32BITREQ : 0 32BITPREF : 0 Signed : 0 PS> .\CorFlags.exe .\Test\itanium\Release\DllForTesting.dll Microsoft (R) .NET Framework CorFlags Conversion Tool. Version 4.0.30319.17929 Copyright (c) Microsoft Corporation. All rights reserved.

Version : v4.0.30319 CLR Header: 2.5 PE : PE32+ CorFlags : 0x1 ILONLY : 1 32BITREQ : 0 32BITPREF : 0 Signed : 0 PS> .\CorFlags.exe .\Test\itanium\Release\ExeForTesting.exe Microsoft (R) .NET Framework CorFlags Conversion Tool. Version 4.0.30319.17929 Copyright (c) Microsoft Corporation. All rights reserved.

Version : v4.0.30319 CLR Header: 2.5 PE : PE32+ CorFlags : 0x1 ILONLY : 1 32BITREQ : 0 32BITPREF : 0 Signed : 0 PS> .\CorFlags.exe .\Test\x64\Release\DllForTesting.dll Microsoft (R) .NET Framework CorFlags Conversion Tool. Version 4.0.30319.17929 Copyright (c) Microsoft Corporation. All rights reserved.

Version : v4.0.30319 CLR Header: 2.5 PE : PE32+ CorFlags : 0x1 ILONLY : 1 32BITREQ : 0 32BITPREF : 0 Signed : 0 PS> .\CorFlags.exe .\Test\x64\Release\ExeForTesting.exe Microsoft (R) .NET Framework CorFlags Conversion Tool. Version 4.0.30319.17929 Copyright (c) Microsoft Corporation. All rights reserved.

Version : v4.0.30319 CLR Header: 2.5 PE : PE32+ CorFlags : 0x1 ILONLY : 1 32BITREQ : 0 32BITPREF : 0 Signed : 0 PS> .\CorFlags.exe .\Test\anycpu32bitpreferred\Release\DllForTesting.dll Microsoft (R) .NET Framework CorFlags Conversion Tool. Version 4.0.30319.17929 Copyright (c) Microsoft Corporation. All rights reserved.

Version : v4.0.30319 CLR Header: 2.5 PE : PE32 CorFlags : 0x1 ILONLY : 1 32BITREQ : 0 32BITPREF : 0 Signed : 0 PS>

If the assembly contains only pure MSIL the “ilonly” flag will be present. For mixed-mode assemblies the “contains native” flag will be present instead. The flag “32bits” means that it will run as a native 32-bit app on 32-bit systems and run as a native 32-bit app within the WoW64 subsystem 64-bit systems. Platform independent assemblies will have the “32/64” flag instead.

For AnyCPU assemblies : PE = PE32, 32BIT = 0, and ILONLY = 1

For x86 assemblies : PE = PE32 and 32BIT = 1

For x64 assmblies : PE = PE32+ and 32BIT=0

If ILONLY = 0 that means the assembly has unmanaged codes as well (so it cannot be anycpu).

There is no way (for now) to demand execution in a 64-bit process because this thing is not controled by a metadata flag. Rather it’s controled at compile time and compiler has to emit PE32+ compatible code.

corflags.exe /32BIT+ testme.exe

Now, this assembly would always execute under WoW64 (emulated 32-bit environment on a 64-bit box). In a case where this execution would not be possible – ie. run against an ia64 box – one would get a BadImageFormatException exception.

http://blogs.msdn.com/b/dsvc/archive/2008/06/28/x86-x64-ia64-any-cpu.aspx

C:\Users\Robert\Desktop>CorFlags.exe foo.exe Microsoft (R) .NET Framework CorFlags Conversion Tool. Version 4.0.30319.17929 Copyright (c) Microsoft Corporation. All rights reserved.

corflags : error CF002 : Could not open file for reading

Usage for corflags.exe

In my blog post, i covered about two new Environment property in .Net C# 4.0 – Is64BitOperatingSystem vs Is64BitProcess
Generally it is highly recommended that developers use the compiler options to specify the platform on which to run.

However, after it has been compiled, or maybe you don’t have access to the code, etc…
For that case we have an SDK tool called corflags.exe. Corflags allows you to modify some of the loading characteristics of a managed app.

1
2
3
4
5
6
7
8
9
10
11
12
//Target platform Any.
C:\corflags test.exe
Microsoft (R) .NET Framework CorFlags Conversion Tool.  Version  4.0.30319.1
Copyright (c) Microsoft Corporation.  All rights reserved.
Version   : v4.0.30319
CLR Header: 2.5
PE        : PE32
CorFlags  : 1
ILONLY    : 1
32BIT     : 0
Signed    : 0

Here are a couple of examples of Corflags.exe usage:

Scenario: you have an application foo.exe which was compiled “any cpu” with a Whidbey compiler, but you want to force it to run as a 32-bit application even on 64-bit machines.

Run: corflags.exe /32BIT+ foo.exe

Result: foo.exe is now marked as if it was compiled /platform:x86

Scenario: you have an Everett (.Net 1.1) application bar.exe which you would like to enable to run on 64-bit.

Run: corflags /UpgradeCLRHeader bar.exe

Result: bar.exe now looks like a Whidbey (.Net 2.0) “any cpu” application and will load under the 64-bit 2.0 runtime on a 64-bit OS. It is still Everett compatible however and will run as a 32-bit 1.1 application on a 32-bit OS.

 

How to use Corflags tool of Visual Studio to check 32/64 bit of dll ?

Corflags is the inbuilt tool of Visual Studio which is used to find out the type of .dll i.e 32 bit, 64 bit or any CPU. This tool is available in Visual studio 2005 onward. i.e. VS 2005/2008/2010/2013

These are the following steps to check in Visual Studio

Step1 : Go to visual Studio command prompt like this

Step1

Step 2: Make Sure that Corflags is working in your system

Type the Corflags in Command Prompt like this

Step2

Step 3: Go to the file Location of DLL and type the syntax like this in below image
Corflags AjaxToolKit.dll

Corflag11

 

Features

Major Features of CorFlags

You may see multiple command prompts, depending on the version of Visual Studio and any additional SDKs you’ve installed. For example, 64-bit versions of Visual Studio provide both 32-bit and 64-bit command prompts. (The 32-bit and 64-bit versions of most tools are identical; however, a few tools make changes specific to 32-bit and 64-bit environments.) If the steps below don’t work, you can try Manually locating the files on your machine or Running command prompt from inside Visual Studio.

 

videos

ECS V5 on Windows 7 64 bit

 

CorFlags on cloud

Related Posts