Can't find MASM's file age

Viewed 28

My task:
"Use the GetOpenFileName function to select a file. Check if the age of the file is less than 3 days, execute it. Otherwise, display a dialog box with a question about deleting the file. If the user agrees, wipe."

Problem:
I can't get the age of the file in any way. I'm trying to compare the creationTime returned by GetFileTime with the current time returned by GetSystemTimeAsFileTime. 3 days is (3 * 24 * 60 * 60 * 10000000) 100-ns intervals (FILETIME is measured in such units). To simplify my task, I compare only the higher parts (dwHighDateTime) of FILETIME structures, the weight of the lower part is 429 seconds, less than 10 minutes.

Something like that:

invoke GetFileTime, hFile, addr ftCreate, NULL, NULL
invoke GetSystemTimeAsFileTime, addr ftNow
mov eax, ftNow.dwHighDateTime
sub eax, ftCreate.dwHighDateTime8
cmp eax, ((3 * 24 * 60 * 60 * 10000000) / 0x100000000)
jg l1

But I get this errors:

;for this: mov eax, ftNow.dwHighDateTime
Third.asm(63) : error A2006: undefined symbol : dwHighDateTime

;for this: cmp eax, ((3 * 24 * 60 * 60 * 10000000) / 0x100000000)
Third.asm(65) : error A2206: missing operator in expression

Help please with this problem.

P.S. If somebody heva another ideas to solve this problem(I mean about age of file), you can recomend it))

File.inc

include WINDOWS.inc

include user32.inc
include kernel32.inc
include comdlg32.inc

includelib user32.lib
includelib kernel32.lib
includelib comdlg32.lib

.data
    Time_title  db ' Lab_3',0
    format db 'More than 3 days. Delete file?', 0
    buf db 255 dup(0)   
    hFile dd 0
    readed dd 0
    hmem dd 0

File.asm

.386
.model flat,STDCALL
option casemap :none  ;case sensitive
include Third.inc
include RADbg.inc

Mem_Alloc PROC Buf_Size:DWORD
    add Buf_Size,4  
    invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,Buf_Size
    push eax 
    invoke GlobalLock,eax 
    pop [eax]
    add eax,4
    ret
Mem_Alloc endp

Mem_Free PROC DATA:DWORD
    mov eax,DATA
    sub eax,4   
    mov eax,[eax]   
    push eax        
    push eax
    call GlobalUnlock   
    call GlobalFree 
    ret
Mem_Free endp

.code
Begin:
    call main
    invoke ExitProcess,NULL

main proc
    LOCAL ftCreate, ftNow: FILETIME;
    ;LOCAL stUTC, stSysTime: SYSTEMTIME;

    invoke Mem_Alloc, 1000h
    mov hmem, eax
    invoke Mem_Alloc, sizeof OPENFILENAME
    mov edi, eax
    assume edi: ptr OPENFILENAME
    xor eax, eax
    mov [edi].lStructSize, sizeof OPENFILENAME
    mov [edi].lpstrFile, offset buf
    mov [edi].nMaxFile, 255
    invoke GetOpenFileName, edi
    invoke CreateFile, [edi].lpstrFile, GENERIC_READ,\
        FILE_SHARE_READ, NULL, OPEN_EXISTING,\
        FILE_ATTRIBUTE_NORMAL, NULL
    mov hFile,eax
    ;invoke GetFileTime, hFile, addr ftCreate, NULL, NULL
    ;invoke FileTimeToSystemTime, addr ftCreate, addr stSysTime
    ;invoke GetSystemTime, addr stUTC

    invoke GetFileTime, hFile, addr ftCreate, NULL, NULL
    invoke GetSystemTimeAsFileTime, addr ftNow
    mov eax, ftNow.dwHighDateTime
    sub eax, ftCreate.dwHighDateTime
    cmp eax, ((3 * 24 * 60 * 60 * 10000000) / 0x100000000)
    jg l1
    invoke ReadFile, hFile, hmem, 1000h, addr readed, 0
    invoke MessageBox, 0, hmem, addr Time_title, MB_OKCANCEL

    jmp l2

l1:
    invoke MessageBox, 0, addr format, addr Time_title, MB_OKCANCEL
    cmp eax, IDOK
    jne l2
    invoke DeleteFile, addr [edi].lpstrFile

l2:

    assume edi: dword
    invoke CloseHandle, hFile
    invoke Mem_Free, hmem
    invoke Mem_Free, edi

    ret
main endp
end Begin
0 Answers
Related