Search code examples
winapiassemblyfile-existsfasm

FASM - If file exists - Using GetFileAttributes - INVALID_FILE_ATTRIBUTES value?


I am using GetFileAttributesA to determine if a file exists or not, in FASM. I know that if the file does not exists the return value will be INVALID_FILE_ATTRIBUTES, but I am not sure how to check for this value.

My Code:

invoke GetFileAttributes,lpFileName
cmp    eax,IDK WHAT TO CHECK FOR
je     notfound
jne    found
invoke ExitProcess,0

Seeing as the compiler does not recognize INVALID_FILE_ATTRIBUTES as a value:

cmp    eax,INVALID_FILE_ATTRIBUTES

Will not work.

Does anyone know the value for this constant, so that I can simply enter it manually?

Any help is appreciated. Thanks


After the response from Jens Björnhager, the following is the working code for anyone else interested:

invoke GetFileAttributes,lpFileName
cmp    eax,-1
je     notfound
jne    found
invoke ExitProcess,0 

Or Even:

invoke GetFileAttributes,lpFileName
cmp    eax,$ffffffff
je     notfound
jne    found
invoke ExitProcess,0 

Thanks again Jens Björnhager!


Solution

  • INVALID_FILE_ATTRIBUTES is defined as -1 ($ffffffff), so check for that.