The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Don57 on November 05, 2011, 06:26:26 PM

Title: fillesize
Post by: Don57 on November 05, 2011, 06:26:26 PM
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 ?
Title: Re: fillesize
Post by: jj2007 on November 05, 2011, 06:32:38 PM
GetFileSize returns two dwords.
Title: Re: fillesize
Post by: Don57 on November 05, 2011, 06:36:44 PM
Thanks
Title: Re: fillesize
Post by: jj2007 on November 05, 2011, 06:43:55 PM
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
Title: Re: fillesize
Post by: dedndave on November 05, 2011, 07:01:58 PM
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
Title: Re: fillesize
Post by: jj2007 on November 05, 2011, 07:56:42 PM
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
Title: Re: fillesize
Post by: dedndave on November 06, 2011, 12:00:19 AM
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
Title: Re: fillesize
Post by: Don57 on November 10, 2011, 03:03:31 PM
Thanks, I'll give all your suggestions a try.