Isinst 操作码在不应返回空值时返回空值

发布于 2024-10-18 11:42:03 字数 1675 浏览 1 评论 0原文

最近,我通过将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抱着落日 2024-10-25 11:42:03

您究竟是如何做出改变的?代码本身看起来不错,我的猜测是元数据表或其他元数据信息变得混乱,因此 [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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文