Ear*_*rlz 4 .net il attributes blob
因此,我试图弄清楚带有 blob 的自定义属性到底是如何工作的。二进制格式看起来非常...奇怪。
来自 ildasm 的示例
.custom instance void [mscorlib]System.Runtime.Versioning.TargetFrameworkAttribute::.ctor(string) =
( 01 00 19 57 69 6E 64 6F 77 73 50 68 6F 6E 65 2C // ...WindowsPhone,
56 65 72 73 69 6F 6E 3D 76 38 2E 30 01 00 54 0E // Version=v8.0..T.
14 46 72 61 6D 65 77 6F 72 6B 44 69 73 70 6C 61 // .FrameworkDispla
79 4E 61 6D 65 11 57 69 6E 64 6F 77 73 20 50 68 // yName.Windows Ph
6F 6E 65 20 38 2E 30 ) // one 8.0
Run Code Online (Sandbox Code Playgroud)
这是什么样的格式?我不太清楚这是否是真正的 UTF-8,为什么前两个字节是 0x01 和 0x00?此外,反编译器会将其作为属性:
[assembly: TargetFramework("WindowsPhone,Version=v8.0", FrameworkDisplayName = "Windows Phone 8.0")]
Run Code Online (Sandbox Code Playgroud)
这一切究竟是如何运作的?
ECMA 公共语言基础设施标准中规定了其格式,特别是标题为“CustomAttribute:0x0C”的第 II.22.10 节(第 216 页)。
\n它以“仅包含信息性文本”部分开头:
\n\n\n所有二进制值都以小端格式存储...
\n
并继续第 6 点:
\n\n\n\n
\n- 以下规则适用于值“blob”(\xc2\xa7II.23.3) 的整体结构:
\n\n
\n- Prolog 应为 0x0001 [错误]
\n
这就是为什么您会看到 的第一个字节[ 0x01, 0x00 ]。
文本的其余部分继续指定其余部分的布局方式,但这全部都在规范中。
\n还有深入的分析,显示它在 CLR 中的表示方式以及它如何影响属性 blob 的存储。
\n| 归档时间: |
|
| 查看次数: |
214 次 |
| 最近记录: |