News:

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

fillesize

Started by Don57, November 05, 2011, 06:26:26 PM

Previous topic - Next topic

Don57

I am using filesize to compare the length of source and key files, to make sure that the key is as long as the source, but it only returns eax. Is there another register set if one of the file is longer than 4G ?

jj2007

GetFileSize returns two dwords.

Don57


jj2007

Here is a very simple app. Note the use of the stack as lpHighDword.

include \masm32\include\masm32rt.inc

.code
start:
   mov ebx, fopen("\Masm32\include\Windows.inc")
   print str$(ebx), 9, "the handle", 13, 10
   push eax  ; create lpHighDword
   invoke GetFileSize, ebx, esp
   print str$(eax), 9, "low dword", 13, 10
   pop eax  ; pop lpHighDword
   print str$(eax), 9, "high dword", 13, 10
   fclose ebx
   print str$(eax), 9, "for close"
   exit

end start

dedndave

#4
GetFileAttributesEx is faster
however, it is a little more work, as there is a structure involved
i like to create temporary space for the structure on the stack, then adjust the stack and POP the values
        xor     eax,eax
        push    eax
        push    eax
        sub     esp,sizeof WIN32_FILE_ATTRIBUTE_DATA-8
        INVOKE  GetFileAttributesEx,offset szPathFileNamei,eax,esp
        add     esp,sizeof WIN32_FILE_ATTRIBUTE_DATA-8
        pop     edx
        pop     eax

;EDX:EAX = file size


notice that, if the file does not exist, EAX = EDX = 0

jj2007

Quote from: dedndave on November 05, 2011, 07:01:58 PM
GetFileAttributesEx is faster

I like it simple: Inkey Str$("Size of Windows.inc=%i", Lof("\Masm32\include\Windows.inc"))

... but under the hood you'll find indeed GetFileAttributesEx  :wink

dedndave

#6
i modified the code above
        xor     eax,eax
        push    eax
        push    eax
        sub     esp,sizeof WIN32_FILE_ATTRIBUTE_DATA-12
        push    eax
        INVOKE  GetFileAttributesEx,offset szPathFileName,eax,esp
        pop     ecx
        add     esp,sizeof WIN32_FILE_ATTRIBUTE_DATA-12
        or      eax,eax
        pop     edx
        pop     eax

;EDX:EAX = file size
;ECX     = file attributes
;ZF      = true if error, false if success


for a list of file attribute pins...
http://msdn.microsoft.com/en-us/library/windows/desktop/gg258117(v=vs.85).aspx

Don57

Thanks, I'll give all your suggestions a try.