-
Notifications
You must be signed in to change notification settings - Fork 3
/
File_SizeW.asm
154 lines (136 loc) · 4.09 KB
/
File_SizeW.asm
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
;==============================================================================
;
; 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 LINUX_STAT
LINUX_STAT STRUCT
st_dev QWORD ? ; linux_uword_t
st_ino QWORD ? ; linux_uword_t
st_nlink QWORD ? ; linux_uword_t
st_mode DWORD ? ; unsigned int
st_uid DWORD ? ; unsigned int
st_gid DWORD ? ; unsigned int
_pad0 DWORD ? ; unsigned int
st_rdev QWORD ? ; linux_uword_t
st_size QWORD ? ; linux_word_t
st_blksize QWORD ? ; linux_word_t
st_blocks QWORD ? ; linux_word_t
st_atime QWORD ? ; linux_uword_t
st_atime_nsec QWORD ? ; linux_uword_t
st_mtime QWORD ? ; linux_uword_t
st_mtime_nsec QWORD ? ; linux_uword_t
st_ctime QWORD ? ; linux_uword_t
st_ctime_nsec QWORD ? ; linux_uword_t
_unused QWORD 3 DUP (?); linux_word_t
LINUX_STAT ENDS
ENDIF
ENDIF
include UASM64.inc
.CODE
UASM64_ALIGN
;------------------------------------------------------------------------------
; File_SizeW
;
; This function returns the size of a file if it exists.
;
; Parameters:
;
; * lpszFileName - The zero terminated string that has the path & filename of
; the file to return the size of.
;
; Returns:
;
; If the return value is minus one (-1) then the file does not exist,
; otherwise RAX contains the size of the file in bytes.
;
; Notes:
;
; This function will return the size of a file without opening it.
;
; This function as based on the MASM32 Library function: filesizeW
;
; See Also:
;
; File_SizeA, File_ExistsA, File_ExistsW, File_FileSize
;
;------------------------------------------------------------------------------
File_SizeW PROC FRAME USES RDX RDI RSI lpszFileName:QWORD
IF @Platform EQ 1 ; Win x64
LOCAL wfd:WIN32_FIND_DATAW
ENDIF
IF @Platform EQ 3 ; Linux x64
LOCAL statbuf:LINUX_STAT
ENDIF
IF @Platform EQ 1 ; Win x64
Invoke FindFirstFileW, lpszFileName, Addr wfd
.IF rax == -1 ; INVALID_HANDLE_VALUE
ret
.ENDIF
Invoke FindClose, rax
mov rax, qword ptr wfd.nFileSizeHigh ; also reads file size low
ENDIF
IF @Platform EQ 3 ; Linux x64
mov rdi, lpszFileName
lea rsi, statbuf
mov rdx, 0
mov rax, 6 ; lstat
syscall
.IF rax == -1
ret
.ENDIF
lea rdx, statbuf
mov rax, [rdx].LINUX_STAT.st_size
ENDIF
ret
File_SizeW ENDP
END