-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFile_ExistsW.asm
More file actions
139 lines (120 loc) · 3.25 KB
/
File_ExistsW.asm
File metadata and controls
139 lines (120 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
;==============================================================================
;
; UASM64 Library
;
; https://github.com/mrfearless/UASM64-Library
;
;==============================================================================
.686
.MMX
.XMM
.x64
option casemap : none
IF @Platform EQ 1
option win64 : 11
ENDIF
option frame : auto
IF @Platform EQ 1 ; Win x64
FindFirstFileW PROTO lpFileName:QWORD, lpFindFileData:QWORD
FindClose PROTO hFindFile:QWORD
;IFNDEF INVALID_HANDLE_VALUE
;INVALID_HANDLE_VALUE EQU -1
;ENDIF
IFNDEF MAX_PATH
MAX_PATH EQU 260
ENDIF
IFNDEF WCHAR
WCHAR typedef WORD
ENDIF
IFNDEF FILETIME
FILETIME STRUCT
dwLowDateTime DWORD ?
dwHighDateTime DWORD ?
FILETIME ENDS
ENDIF
IFNDEF WIN32_FIND_DATAW
WIN32_FIND_DATAW STRUCT 8
dwFileAttributes DWORD ?
ftCreationTime FILETIME <>
ftLastAccessTime FILETIME <>
ftLastWriteTime FILETIME <>
nFileSizeHigh DWORD ?
nFileSizeLow DWORD ?
dwReserved0 DWORD ?
dwReserved1 DWORD ?
cFileName WCHAR MAX_PATH DUP (?)
cAlternateFileName WCHAR 14 DUP (?)
dwFileType DWORD ? ; Obsolete. Do not use.
dwCreatorType DWORD ? ; Obsolete. Do not use.
wFinderFlags WORD ? ; Obsolete. Do not use.
WIN32_FIND_DATAW ENDS
ENDIF
includelib kernel32.lib
ENDIF
IF @Platform EQ 3 ; Linux x64
IFNDEF O_RDONLY
O_RDONLY EQU 00000000h
ENDIF
ENDIF
include UASM64.inc
.CODE
UASM64_ALIGN
;------------------------------------------------------------------------------
; File_ExistsW
;
; This function tests if a file exists at the path and file name in the zero
; terminated string.This is the Unicode version of File_Exists, File_ExistsA is
; the Ansi version.
;
; Parameters:
;
; * lpszFileName - The zero terminated string that has the path & filename of
; the file to test if it exists.
;
; Returns:
;
; If the return value in RAX is 0, the file does not exist, if it is 1, then it
; does exist.
;
; Notes:
;
; This function as based on the MASM32 Library function: existW
;
; See Also:
;
; File_ExistsA, File_SizeA, File_SizeW
;
;------------------------------------------------------------------------------
File_ExistsW PROC FRAME lpszFileName:QWORD
IF @Platform EQ 1 ; Win x64
LOCAL wfd:WIN32_FIND_DATAW
ENDIF
IF @Platform EQ 1 ; Win x64
Invoke FindFirstFileW, lpszFileName, Addr wfd
.IF rax == -1 ; INVALID_HANDLE_VALUE
mov rax, 0 ; 0 = NOT exist
.ELSE
Invoke FindClose, rax
mov rax, 1 ; 1 = exist
.ENDIF
ENDIF
IF @Platform EQ 3 ; Linux x64
mov rdi, lpszFileName
mov rsi, O_RDONLY ; flags
mov rdx, 0 ; mode
mov rax, 2 ; open
syscall
.IF rax == -1 ; file does not exist
mov rax, 0
ret
.ENDIF
mov rdi, rax ; hFile ; fd
mov rsi, 0
mov rdx, 0
mov rax, 3 ; close
syscall
mov rax, 1 ; file exists
ENDIF
ret
File_ExistsW ENDP
END