Разрядность .NET сборок.

?????? ????? ????????? ????? ??? ??????????? ??????????? ??????????? ?????? ??????????, ??? ? ???? .NET «??? ?????? ??-???????».

??? ?????? ????????? ?????????? ???????????. ?????????? Visual C++ ?????????? ???? /clr ??? ???????? ??????????? ????? ???? ? .NET ??????:

  • /clr - ????????? ????????? ??????????? ? ????????????? ???;
  • /clr:pure – ?????????, ??? ?????? ????? ????????? ?????? ??????????? ???;
  • /clr:safe – ???? ??? ??????, ??? /clr:pure, ???????? ?????? ??????????? ???.

? ????? ?????? ??????????? ?????????? ??????? ??? ????? ??, ??? ??????????? ??? ?? ??????????? ????? ??????????? ?? ????? ????????? (x86, amd64 ? ia64), ? ?? ????? ??? ????????????? ??? ???????????? ??? ??????????? ??????????. ?.?. ????? ?? ???? ???????, ??? ??????, ????????? ? /clr:pure ??? /clr:safe, ????? ???????????? ?? ????? ?????????. ?? ????? ???? ??? ?? ?????? ???, ? ??? ? ? ???????? ????.

?????. ??????, ?????????? ??????????? ???, ????? ???????? ?? «??????????» ??????? ?? ???????? «COM Descriptor Directory». ??????? “link /dump /headers” ?????????? ?? ? ????? ?????? ?????????? ? «PE Optional Header»:

 OPTIONAL HEADER VALUES
             10B magic # (PE32)
            8.00 linker version

            ...

               0 loader flags
              10 number of directories
               0 [       0] RVA [size] of Export Directory
            87C4 [      64] RVA [size] of Import Directory
            A000 [     6A8] RVA [size] of Resource Directory
               0 [       0] RVA [size] of Exception Directory
               0 [       0] RVA [size] of Certificates Directory
            B000 [     190] RVA [size] of Base Relocation Directory
            3100 [      1C] RVA [size] of Debug Directory
               0 [       0] RVA [size] of Architecture Directory
               0 [       0] RVA [size] of Global Pointer Directory
               0 [       0] RVA [size] of Thread Storage Directory
            3188 [      40] RVA [size] of Load Configuration Directory
               0 [       0] RVA [size] of Bound Import Directory
            3000 [      A8] RVA [size] of Import Address Table Directory
               0 [       0] RVA [size] of Delay Import Directory
            311C [      48] RVA [size] of COM Descriptor Directory
               0 [       0] RVA [size] of Reserved Directory

???????? ?? ????????, ??? ?????????? ?? ????? ????????? ? COM. ????????? ? ???????, ???????? ???????? ? ??? ??????, ????? CLR ??? ?????? ??????? ???????????????. ?????????? ???? ??????????, ???, ?? ??????? ????, ????? ?? ???????????, ????? ?????????? ? ??????? ??????? CorFlags.exe ?? .NET SDK.

 > CorFlags.exe clr_rabbit.exe
Microsoft (R) .NET Framework CorFlags Conversion Tool.  Version  2.0.50727.42
Copyright (c) Microsoft Corporation.  All rights reserved.

Version   : v2.0.50727
CLR Header: 2.5
PE        : PE32
CorFlags  : 0
ILONLY    : 0
32BIT     : 0
Signed    : 0

??? ????? ???????????? ????? ILONLY (?????? ??????????? ???) ? 32BIT (32-? ?????? ???), ????????? ??? ??????????????? ??????? ? ???????????? ??????.

? ?????????? ?????????????? x86 ? amd64 ???????? ???????????? “Hello World” ??? ???? ???? ???????? ????? /clr ? ?????????? ??? ?????????. ?????????? ??? ????? ????????:

???????????? PE ????????? ???? ILONLY ???? 32BIT ??????????? ???????? ? 32-? ?????? ??????? ??????????? ???????? ? 64-? ?????? ???????
x86, /clr x86 0 0 32 32
x86, /clr:pure x86 1 1 32 32
x86, /clr:safe x86 1 0 32 64
amd64, /clr x64 0 0 - 64
amd64, /clr:pure x64 1 0 - 64
amd64, /clr:safe x86 1 0 32 64

?????? ????? ??????? ??? ????? ??????:

  • ???? /clr ?????? ??????????? ?????????? ?????? ? ???????????? ?????????, ??? ??? ????? ?????? ???????? ????????????? ???.
  • ?? ?????? ?? ??, ??? ?????? ????????? ? /clr:pure ???????? ?????? ??????????? ???, ????? ?????? ???????? ? ???????????? ????????? ?? ????? ?????? ??? ??????????. 32-? ?????? ??????? ?? ?????? ????????? ?????? "amd64, /clr:pure", ? 64-? ?????? ????? ????????? ?????? "x86, /clr:pure" ? Wow64. ????????? ? ???????, ??????? ??? ? ???, ??? ????? ?????? ????? ?????????? ? ?????????????? ???? ?? ?????? ???????.
  • ?????? ??????, ???????????????? ? /clr:safe ??-?????????? ??????????. ?????????, ??? ??? ??? ? PE ?????????? ?????? ????? ??????????? x86 ? ???????? ??????? ?????????.

Cross-posted from blog.not-a-kernel-guy.com.