Isinst 操作码在不应返回空值时返回空值
最近,我通过将 IL 代码添加到 CultureDefinition 类中的函数之一来覆盖 GAC 中的 sysglobl.dll,因此 .net 框架和 Visual Studio 直接从 GAC 加载更改后的 dll。 其功能是:
System.Globalization.CalendarId CalendarIdofCalendar(System.Globalization.Calendar)
这是来自 ildasm 工具的代码。
IL_0077: ldarg.0
IL_0078: isinst [mscorlib]System.Globalization.KoreanCalendar
IL_007d: brfalse.s IL_0081
IL_007f: ldc.i4.5
IL_0080: ret
IL_0081: ldarg.0
IL_0082: isinst [mscorlib]System.Globalization.HijriCalendar
IL_0087: brfalse.s IL_008b
IL_0089: ldc.i4.6
IL_008a: ret
添加的代码
IL_008b: ldarg.0
IL_008c: isinst [mscorlib]System.Globalization.PersianCalendar
IL_0091: brfalse.s IL_0096
IL_0093: ldc.i4.s 22
IL_0095: ret
添加代码结束
IL_0096: ldarg.0
IL_0097: isinst [mscorlib]System.Globalization.UmAlQuraCalendar
IL_009c: brfalse.s IL_00a1
IL_009e: ldc.i4.s 23
IL_00a0: ret
IL_00a1: ldstr "CustomCaledarsNotSupported"
IL_00a6: call string System.Globalization.CultureAndRegionInfoBuilder::GetResourceString(string)
IL_00ab: newobj instance void [mscorlib]System.NotSupportedException::.ctor(string)
IL_00b0: throw
会出现问题
__IL_008c: isinst [mscorlib]System.Globalization.PersianCalendar__
现在,当我传递 PersianCalendar isinst returnS null 值的实例时,该行 ,因此该函数将抛出 NotSupportedException。但如果我通过 HijriCalendar 它工作正常并且会去 线
**IL_0089: ldc.i4.6**
等。
我找不到我添加的部分不起作用的原因。
先感谢您。
recently I have overwritten sysglobl.dll in the GAC by adding IL code to one of the functions in CultureDefinition Class, so the the .net framework and visual studio load the changed dll directly from GAC.
The function is:
System.Globalization.CalendarId CalendarIdofCalendar(System.Globalization.Calendar)
here is the code from ildasm tool.
IL_0077: ldarg.0
IL_0078: isinst [mscorlib]System.Globalization.KoreanCalendar
IL_007d: brfalse.s IL_0081
IL_007f: ldc.i4.5
IL_0080: ret
IL_0081: ldarg.0
IL_0082: isinst [mscorlib]System.Globalization.HijriCalendar
IL_0087: brfalse.s IL_008b
IL_0089: ldc.i4.6
IL_008a: ret
The Added Code
IL_008b: ldarg.0
IL_008c: isinst [mscorlib]System.Globalization.PersianCalendar
IL_0091: brfalse.s IL_0096
IL_0093: ldc.i4.s 22
IL_0095: ret
End Of Added Code
IL_0096: ldarg.0
IL_0097: isinst [mscorlib]System.Globalization.UmAlQuraCalendar
IL_009c: brfalse.s IL_00a1
IL_009e: ldc.i4.s 23
IL_00a0: ret
IL_00a1: ldstr "CustomCaledarsNotSupported"
IL_00a6: call string System.Globalization.CultureAndRegionInfoBuilder::GetResourceString(string)
IL_00ab: newobj instance void [mscorlib]System.NotSupportedException::.ctor(string)
IL_00b0: throw
now here is the problem at line
__IL_008c: isinst [mscorlib]System.Globalization.PersianCalendar__
when i pass an instance of PersianCalendar isinst returnS null value so the function will throw NotSupportedException. but if i pass HijriCalendar it work fine and will go to
line
**IL_0089: ldc.i4.6**
and so on.
i cannot find the reason why the part i have added wont works.
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您究竟是如何做出改变的?代码本身看起来不错,我的猜测是元数据表或其他元数据信息变得混乱,因此
[mscorlib]System.Globalization.PersianCalendar
令牌实际上并不指代它应该指的内容,或者实际的程序集没有被正确调用。How exactly are you making the change? The code itself looks good, my guess is that the metadata tables or other metadata info are getting confused so the
[mscorlib]System.Globalization.PersianCalendar
token doesn't actually refer to what it should, or that the actual assembly isn't getting called appropriately.