If you need to change the CPU type on a dot­Net assem­bly for exam­ple, if the assem­bly needs to write to a reg­istry key and does not work cor­rectly on a 64b machine. Per default it’s any CPU, so the assem­bly will run on its native architecture.

1) dis­as­sem­bly

1
> ildasm.exe /all ADotNetApp.exe /out=ADotNetApp.il

2) change il code
Open the file ADotNetApp.il with your favorite Text edi­tor and search for “.corflags”.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
min­i­mal cor­flags descrip­tion:
0×1 (IL_ONLY)
0×2 (32BIT_ONLY)
0×8 (SIGNED)

change from
.cor­flags 0x00000001
to
.cor­flags 0x00000002

or for signed assembly’s
change
.cor­flags 0x00000009
to
.cor­flags 0x0000000A

3) assem­bly it

1
> ilasm.exe /RESOURCE=ADotNetApp.res ADotNetApp.il

or for signed assembly’s use

1
> ilasm.exe /RESOURCE=ADotNetApp.res ADotNetApp.il /key=keypair001.snk

Hint, to cre­ate a Key pair use this command:

1
> sn –k keypair001.snk

Or long story short, you may also use the CorFlags.exe tool:

1
> CorFlags.exe assem­bly /32BIT+

Check MSDN for an detailed description.

You can also use CorFlags.exe to check the CPU type of an dot­Net assembly:

1
2
3
4
5
6
7
8
9
10
C:downtestil>CorFlags.exe ADotNetApp.exe
Microsoft ® .NET Frame­work Cor­Flags Con­ver­sion Tool.Copyright © Microsoft Cor­po­ra­tion.  All rights reserved.

Ver­sion   : v2.0.50727
CLR Header: 2.5
PE        : PE32
Cor­Flags  : 10
ILONLY    : 0
32BIT     : 1
Signed    : 1