News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Calulating date & time in Kernel mode

Started by shlomok, May 02, 2012, 08:28:44 PM

Previous topic - Next topic

shlomok

Hi,
I managed to resolve my BSODs ... here is a working version:


getCurrentDateAndTime PROC uses eax ebx ecx edx
LOCAL systemTime :LARGE_INTEGER ;Union 2x32 bit words, 1 64 bit word
LOCAL localTime :LARGE_INTEGER
LOCAL nowTF :TIME_FIELDS ;A structure of 16 bit integer locations

invoke DbgPrint,$CTA0("BlockerKmdDriver::getCurrentDateAndTime ...\n")

;The KeQuerySystemTime routine obtains the current system time.
;(System time is a count of 100-nanosecond intervals since January 1, 1601)
invoke KeQuerySystemTime, addr systemTime    
;The ExSystemTimeToLocalTime routine converts a GMT system time value
;to the LOCAL system time for the current time zone.
invoke ExSystemTimeToLocalTime, addr systemTime, addr localTime
invoke RtlTimeToTimeFields ,addr localTime,addr nowTF

;Refer to typedef struct TIME_FIELDS
    movzx eax, nowTF.Day
    movzx ecx, nowTF.Month
    movzx edx, nowTF.Year
    invoke DbgPrint, $CTA0("BlockerKmdDriver::Date is %d.%02d.%04d\n"), eax, ecx, edx
   
    movzx eax, nowTF.Hour
    movzx ebx, nowTF.Minute
    movzx ecx, nowTF.Second
    movzx edx, nowTF.Milliseconds
    invoke DbgPrint, $CTA0("BlockerKmdDriver::Time is %d.%02d.%02d.%04d\n"), eax, ebx, ecx, edx   

ret
getCurrentDateAndTime ENDP



This is the output:


BlockerKmdDriver::Date is 2.05.2012
BlockerKmdDriver::Time is 23.27.49.0937



Comments are welcomed,

S.