If you need to change the CPU type on a dotNet assembly for example, if the assembly needs to write to a registry key and does not work correctly on a 64b machine. Per default it’s any CPU, so the assembly will run on its native architecture.
1) disassembly
1 | > ildasm.exe /all ADotNetApp.exe /out=ADotNetApp.il |
2) change il code
Open the file ADotNetApp.il with your favorite Text editor and search for “.corflags”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | minimal corflags description: 0×1 (IL_ONLY) 0×2 (32BIT_ONLY) 0×8 (SIGNED) change from .corflags 0x00000001 to .corflags 0x00000002 or for signed assembly’s change .corflags 0x00000009 to .corflags 0x0000000A |
3) assembly 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 create 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 assembly /32BIT+ |
Check MSDN for an detailed description.
You can also use CorFlags.exe to check the CPU type of an dotNet assembly:
1 2 3 4 5 6 7 8 9 10 | C:downtestil>CorFlags.exe ADotNetApp.exe Microsoft ® .NET Framework CorFlags Conversion Tool.Copyright © Microsoft Corporation. All rights reserved. Version : v2.0.50727 CLR Header: 2.5 PE : PE32 CorFlags : 10 ILONLY : 0 32BIT : 1 Signed : 1 |