DateTime.Now是否有漏洞? [英] Is DateTime.Now bugged?

查看:141
本文介绍了DateTime.Now是否有漏洞?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当DaylightSavingsTime生效时,DateTime.Now没有返回给我正确的时间,AutoDST设置为false,并且未加载shell(资源管理器)。


信息


VS2008& Windows CE 5.0上的CF 3.5


本机函数GetLocalTime()返回正确的时间。


DateTime.Now返回1小时的时间因为它似乎忽略了DST。


如果我退出我的应用程序,我会发信号通知shell加载并且DateTime.Now开始正常工作。


如果未加载shell,我该怎么做才能使DateTime.Now正常工作? 目前我们不能使用ToLocalTime ToUniversalTime和其他实用程序。

解决方案

它会看到mscorelib.dll中的以下代码不是工作?


在CurrentTimeZone类中

  public  覆盖 不安全  DaylightTime    GetDaylightChanges   int  year)
{
简短 [] numArray ;
int num ;
DaylightTime 时间;
DateTime time2 ;
DateTime time3 ;
TimeSpan span ;
if < 1
{
goto Label_000C;
}
if < = 0x270f
{
goto Label_0012;
}
Label_000C
throw new ArgumentOutOfRangeException ();
Label_0012
numArray = new [ 0x11 ];
if NSLIntl CurrentTimeZone_GetDaylightChanges numArray )== null
{
goto Label_003B;
}
时间 = new DaylightTime DateTime MinValue DateTime MinValue TimeSpan );
goto Label_0099;
Label_003B
time2 = GetDayOfWeek numArray [ 1 ], numArray [ 2 ], numArray [ 3 ], numArray [ 4 ], numArray [ 5 ], numArray [ 6 ], numArray [ 7 ]);
time3 = GetDayOfWeek numArray [ 9 ], numArray [ 10 ], numArray [ 11 ], numArray [ 12 ], numArray [ 13 ], numArray [ 14 ], numArray [ 15 ]);
& span = new 时间跨度(((<一title ="System.Int64"href ="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:3.5.0.0:969db8053d3322ac/System.Int64"> long ) numArray [ 0x10 ])* 0x23c34600 L );
time = new DaylightTime time2 time3 span );
Label_0099
返回 时间;
}

 


看起来它正在击中案例0012并返回TimeSpan.Zero时它应该返回偏移量。 本机函数调用CurrentTimeZone_GetDaylightChanges要么返回非零(可能是错误条件),要么为DST填充零
范围的数组。


 


DateTime.Now is not returning to me the correct time when DaylightSavingsTime is in effect, AutoDST is set to false, and the shell (explorer) is not loaded.

Information

VS2008 & CF 3.5 on Windows CE 5.0

The native function GetLocalTime() returns the correct time.

DateTime.Now returns a time that is 1 hour off because it seems to neglect DST.

If I exit my application I then signal the shell to load and DateTime.Now begins to work properly.

What should I do to make DateTime.Now work properly when the shell is not loaded?  Currently we cannot use ToLocalTime ToUniversalTime and other utilities.

解决方案

It would see the following code in mscorelib.dll is not working?

In the CurrentTimeZone class

public override unsafe DaylightTime GetDaylightChanges(int year)
{
  short[] numArray;
  int num;
  DaylightTime time;
  DateTime time2;
  DateTime time3;
  TimeSpan span;
  if (year < 1)
  {
    goto Label_000C;
  }
  if (year <= 0x270f)
  {
    goto Label_0012;
  }
Label_000C:
  throw new ArgumentOutOfRangeException();
Label_0012:
  numArray = new short[0x11];
  if (NSLIntl.CurrentTimeZone_GetDaylightChanges(numArray) == null)
  {
    goto Label_003B;
  }
  time = new DaylightTime(DateTime.MinValue, DateTime.MinValue, TimeSpan.Zero);
  goto Label_0099;
Label_003B:
  time2 = GetDayOfWeek(year, numArray[1], numArray[2], numArray[3], numArray[4], numArray[5], numArray[6], numArray[7]);
  time3 = GetDayOfWeek(year, numArray[9], numArray[10], numArray[11], numArray[12], numArray[13], numArray[14], numArray[15]);
  &span = new TimeSpan(((long) numArray[0x10]) * 0x23c34600L);
  time = new DaylightTime(time2, time3, span);
Label_0099:
  return time;
}

 

It looks like it is hitting case 0012 and returning TimeSpan.Zero when it should return the offset.  The native function call CurrentTimeZone_GetDaylightChanges is either returning nonzero (maybe an error condition) or filling the array with a zero span for DST.

 


这篇关于DateTime.Now是否有漏洞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆