且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

DateTime.Now是否有漏洞?

更新时间:2023-01-28 09:25:56

它会看到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 时间跨度((( 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.