-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFile_FileSize.asm
108 lines (99 loc) · 2.72 KB
/
File_FileSize.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
;==============================================================================
;
; 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
GetFileSizeEx PROTO hFile:QWORD, lpFileSize:QWORD
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_FileSize
;
; Get the size of an opened file.
;
; Parameters:
;
; * hFile - The handle of the opened file to get the size of.
;
; Returns:
;
; RAX contains the size of the file in bytes, or -1 if an error occurred.
;
; Notes:
;
; This function as based on the MASM32 Library function:
;
; See Also:
;
; File_SizeA, File_SizeW, File_ExistsA, File_ExistsW
;
;------------------------------------------------------------------------------
File_FileSize PROC FRAME USES RDX RDI RSI hFile:QWORD
IF @Platform EQ 1 ; Win x64
LOCAL qwFileSize:QWORD
ENDIF
IF @Platform EQ 3 ; Linux x64
LOCAL statbuf:LINUX_STAT
ENDIF
IF @Platform EQ 1 ; Win x64
Invoke GetFileSizeEx, hFile, Addr qwFileSize
.IF eax == 0
mov rax, -1
ret
.ENDIF
mov rax, qwFileSize
ENDIF
IF @Platform EQ 3 ; Linux x64
mov rdi, hFile ; fd
lea rsi, statbuf
mov rdx, 0
mov rax, 5 ; fstat
syscall
.IF rax == -1
ret
.ENDIF
lea rdx, statbuf
mov rax, [rdx].LINUX_STAT.st_size
ENDIF
ret
File_FileSize ENDP
END