FASM - If file exists - Using GetFileAttributes - INVALID_FILE_ATTRIBUTES value?
-
03-07-2021 - |
Вопрос
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!
Решение
INVALID_FILE_ATTRIBUTES
is defined as -1 ($ffffffff), so check for that.
Другие советы
Instead of using magic numbers in code, you should use properly defined macro INVALID_FILE_ATTRIBUTES. This macro defined in kernel32.inc in INCLUDE folder of fasm installation. You can include this inc file like this
include 'c:\path\to\fasm\INCLUDE\EQUATES\KERNEL32.INC'
or you can add only high level include like
include 'c:\path\to\fasm\INCLUDE\win32a.inc' (or win32w.inc if you use unicode version of winapi)
or if you set include value in Environment section of fasmw.ini just :
include 'win32a.inc'