I am wondering, what is some good code to check the size of a file??
Posted on 2001-05-03 11:35:00 by Mr. Ying
invoke GetFileSize,hFile,0 hFile is the handle returned by CreateFile. eax will have the size of the file after successfull call to GetFileSize. This message was edited by JimmyClif, on 5/3/2001 11:49:08 AM
Posted on 2001-05-03 11:48:00 by JimmyClif
Ok, how would you write it though to where it would check a certain file, and if the file wasn't a certain size it would give an error message?
Posted on 2001-05-03 16:24:00 by Mr. Ying
Ahoy, The file size (low-order doubleword of the file size) is returned in EAX after API 'GetFileSize'. ? bye Test
Posted on 2001-05-03 16:37:00 by Test Department
ok, tell me if I am on the right track here. I would probly do it something like this.... .data filename db "filename.exe" szDisplayName db "title" .const sizeoffile equ 31423425 .code invoke Getfilesize,sizeoffile,address filename,eax,null je eax,eax messagebox: szText tbMsg1,"file not correct size, aborting" invoke MessageBox,hWin,ADDR tbMsg1, ADDR szDisplayName,MB_OK I know this example won't compile correctly; but how can I fix it to where it checks the file size and then goes to a message box if the file is not the correct size?
Posted on 2001-05-03 18:46:00 by Mr. Ying
Hi, some more hints: CreateFileA PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD GetFileSize PROTO :DWORD,:DWORD ;------------------------------------------------------------------------------ ; API "CreateFileA" creates or opens a file. ; It returns a handle that can be used to access the object. ;------------------------------------------------------------------------------ push 0h ;hTemplateFile, push 80h ;dwFlagsAndAttributes, 80h=normal push 3h ;dwCreationDistribution,OPEN_EXISTING push 0h ;lpSecurityAttributes, push 0h ;dwShareMode, push 80000000h ;dwDesiredAccess,GENERIC_READ push OFFSET LoadFileName ;lpFileName,pointer to filename call CreateFileA ;- API Function - mov LoadFileHandle,eax ;store handle in variable ;------------------------------------------------------------------------------ ; API "GetFileSize" retrieves the size, in bytes, of the specified file. ;------------------------------------------------------------------------------ push 0h ;lpFileSizeHigh, highword file size push LoadFileHandle ;hFile, handle of file to get size of call GetFileSize ;- API Function - mov LoadFileSize,eax ;store size in variable The return value in EAX is the low-order doubleword of the file size. The lpFileSizeHigh parameter points to the variable where the high-order word of the file size is returned. Set it to NULL if not used. Now you can compare EAX with the filesize you define as a constant. If you use the invoke syntax you must pass the API parameter in reverse order, for example : invoke Getfilesize,LoadFileHandle,0h Test
Posted on 2001-05-04 05:06:00 by Test Department
You can save yourself a lot of messing around by using the API call FindFirstFile(). The easiest way is to use the library function in the MASM32 library called "filesize" where you just pass the name of a file and it will return its length if it exists or -1 if it does not exist. Regards, hutch@pbq.com.au
Posted on 2001-05-04 05:14:00 by hutch--
Man, all of this assembly language stuff can get real confusing. I'll go practice some of the things you've shown me untill I get it right........
Posted on 2001-05-05 10:49:00 by Mr. Ying