某些 .NET 反射方法(例如 Module.ResolveField )接受所谓的标记作为参数。这些标记只是 Int32 数字。我在反汇编程序中只看到正数标记,但是一般来说,整数也可以是负数或零。假设 CLR 代币只是正数是否安全?
最佳答案
它们实际上是无符号数字。来自 MS Partition II,第 22 节(取自 this page):
Metadata items (records in the metadata tables) are addressed by metadata tokens. Uncoded metadata tokens are 4-byte unsigned integers, which contain the metadata table index in the most significant byte and a 1-based record index in the three least-significant bytes
鉴于没有元数据表索引具有最高位设置,因此无需担心将 unsigned
int 转换为 int
时会产生溢出或负数数量。
关于.net - CLR token 可以为零或负数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21904990/