;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;FileName: FileTime.asm
;Function: Show the last write time of file "C:/IO.SYS"
; Author: Purple Endurer
;
;Date Summary
;---------------------------------------------------------------------------
; 2006.10.28 Created and Passed!
.386
.model flat, stdcall
option casemap: none
include /masm32/ include/windows.inc
include /masm32/ include/user32.inc
include /masm32/ include/kernel32.inc
includelib /masm32/ lib/user32.lib
includelib /masm32/ lib/kernel32.lib
GetFileLastWriteTime PROTO :LPSTR, :LPSTR
SysTime2Str PROTO : DWORD, :LPSTR
; SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
.data
; SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
g_szFileSpec db "C:/IO.SYS", 0
; SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
.data?
; SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
g_buf20 db 20 dup(?)
; SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
.code
; SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
start:
invoke GetFileLastWriteTime, OFFSET g_szFileSpec, OFFSET g_buf20
.if eax==0
invoke MessageBox, NULL, OFFSET g_buf20, OFFSET g_szFileSpec, NULL
.else
invoke MessageBox, NULL, eax, OFFSET g_szFileSpec, NULL
.endif
invoke ExitProcess, NULL
;///
; Get the last write time of a file
; input: lpstrFileSpec--the pointer to the file specifier
; output: eax > 0, fail, eax = the begin addr of error message
; eax = 0, success, the time str is stored in g_buffer1
;///
GetFileLastWriteTime PROC lpstrFileSpec: LPSTR, lpstrBuf: LPSTR
LOCAL hOpenFile: HANDLE
LOCAL stFileLastWriteTime: FILETIME
LOCAL stLocalFileTime: FILETIME
LOCAL stSysTime: SYSTEMTIME
LOCAL dwResult: DWORD
invoke CreateFile, lpstrFileSpec, GENERIC_READ, FILE_SHARE_READ, NULL,/
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL
.if eax==INVALID_HANDLE_VALUE
mov eax, OFFSET g_szFailToCreateFile
.else
mov hOpenFile, eax
; BOOL GetFileTime(
; HANDLE hFile, // identifies the file
; LPFILETIME lpCreationTime, // address of creation time
; LPFILETIME lpLastAccessTime,// address of last access time
; LPFILETIME lpLastWriteTime // address of last write time
; );
invoke GetFileTime, hOpenFile, NULL, NULL, ADDR stFileLastWriteTime
.if eax == 0
mov dwResult, OFFSET g_szGetFileTimeErr
.else
; BOOL FileTimeToSystemTime(
; CONST FILETIME *lpFileTime, // pointer to file time to convert
; LPSYSTEMTIME lpSystemTime // pointer to structure to receive system time
; );
invoke FileTimeToLocalFileTime, ADDR stFileLastWriteTime, ADDR stLocalFileTime
invoke FileTimeToSystemTime, ADDR stLocalFileTime, ADDR stSysTime
.if eax==0
mov dwResult, OFFSET g_szFileTimeToSystemTimeErr
.else
invoke SysTime2Str, ADDR stSysTime, lpstrBuf
mov dwResult, 0
.endif
.endif
invoke CloseHandle, hOpenFile
mov eax, dwResult
.endif
ret
g_szFailToCreateFile db "创建文件失败!", 0
g_szGetFileTimeErr db "取文件时间失败!", 0
g_szFileTimeToSystemTimeErr db "转换时间失败!", 0
GetFileLastWriteTime ENDP
SysTime2Str PROC lpSysTime: DWORD, lpstrBuf: LPSTR
xor eax, eax
jz @F
g_szFmt4SysTime db "%d-%d-%d %d:%d:%d", 0
@@:
pushad
mov edi, lpSysTime
assume edi: ptr SYSTEMTIME
movzx eax, [ edi].wYear
movzx ebx, [ edi].wMonth
movzx ecx, [ edi].wDay
movzx edx, [ edi].wHour
movzx esi, [ edi].wMinute
movzx edi, [ edi].wSecond
assume edi: nothing
invoke wsprintf, lpstrBuf, OFFSET g_szFmt4SysTime, eax, ebx, ecx, edx, esi, edi
popad
ret
SysTime2Str ENDP
end start
;FileName: FileTime.asm
;Function: Show the last write time of file "C:/IO.SYS"
; Author: Purple Endurer
;
;Date Summary
;---------------------------------------------------------------------------
; 2006.10.28 Created and Passed!
.386
.model flat, stdcall
option casemap: none
include /masm32/ include/windows.inc
include /masm32/ include/user32.inc
include /masm32/ include/kernel32.inc
includelib /masm32/ lib/user32.lib
includelib /masm32/ lib/kernel32.lib
GetFileLastWriteTime PROTO :LPSTR, :LPSTR
SysTime2Str PROTO : DWORD, :LPSTR
; SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
.data
; SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
g_szFileSpec db "C:/IO.SYS", 0
; SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
.data?
; SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
g_buf20 db 20 dup(?)
; SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
.code
; SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
start:
invoke GetFileLastWriteTime, OFFSET g_szFileSpec, OFFSET g_buf20
.if eax==0
invoke MessageBox, NULL, OFFSET g_buf20, OFFSET g_szFileSpec, NULL
.else
invoke MessageBox, NULL, eax, OFFSET g_szFileSpec, NULL
.endif
invoke ExitProcess, NULL
;///
; Get the last write time of a file
; input: lpstrFileSpec--the pointer to the file specifier
; output: eax > 0, fail, eax = the begin addr of error message
; eax = 0, success, the time str is stored in g_buffer1
;///
GetFileLastWriteTime PROC lpstrFileSpec: LPSTR, lpstrBuf: LPSTR
LOCAL hOpenFile: HANDLE
LOCAL stFileLastWriteTime: FILETIME
LOCAL stLocalFileTime: FILETIME
LOCAL stSysTime: SYSTEMTIME
LOCAL dwResult: DWORD
invoke CreateFile, lpstrFileSpec, GENERIC_READ, FILE_SHARE_READ, NULL,/
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL
.if eax==INVALID_HANDLE_VALUE
mov eax, OFFSET g_szFailToCreateFile
.else
mov hOpenFile, eax
; BOOL GetFileTime(
; HANDLE hFile, // identifies the file
; LPFILETIME lpCreationTime, // address of creation time
; LPFILETIME lpLastAccessTime,// address of last access time
; LPFILETIME lpLastWriteTime // address of last write time
; );
invoke GetFileTime, hOpenFile, NULL, NULL, ADDR stFileLastWriteTime
.if eax == 0
mov dwResult, OFFSET g_szGetFileTimeErr
.else
; BOOL FileTimeToSystemTime(
; CONST FILETIME *lpFileTime, // pointer to file time to convert
; LPSYSTEMTIME lpSystemTime // pointer to structure to receive system time
; );
invoke FileTimeToLocalFileTime, ADDR stFileLastWriteTime, ADDR stLocalFileTime
invoke FileTimeToSystemTime, ADDR stLocalFileTime, ADDR stSysTime
.if eax==0
mov dwResult, OFFSET g_szFileTimeToSystemTimeErr
.else
invoke SysTime2Str, ADDR stSysTime, lpstrBuf
mov dwResult, 0
.endif
.endif
invoke CloseHandle, hOpenFile
mov eax, dwResult
.endif
ret
g_szFailToCreateFile db "创建文件失败!", 0
g_szGetFileTimeErr db "取文件时间失败!", 0
g_szFileTimeToSystemTimeErr db "转换时间失败!", 0
GetFileLastWriteTime ENDP
SysTime2Str PROC lpSysTime: DWORD, lpstrBuf: LPSTR
xor eax, eax
jz @F
g_szFmt4SysTime db "%d-%d-%d %d:%d:%d", 0
@@:
pushad
mov edi, lpSysTime
assume edi: ptr SYSTEMTIME
movzx eax, [ edi].wYear
movzx ebx, [ edi].wMonth
movzx ecx, [ edi].wDay
movzx edx, [ edi].wHour
movzx esi, [ edi].wMinute
movzx edi, [ edi].wSecond
assume edi: nothing
invoke wsprintf, lpstrBuf, OFFSET g_szFmt4SysTime, eax, ebx, ecx, edx, esi, edi
popad
ret
SysTime2Str ENDP
end start