-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFile_CreateW.asm
92 lines (83 loc) · 2.16 KB
/
File_CreateW.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
;==============================================================================
;
; 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
CreateFileW PROTO lpFileName:QWORD, dwDesiredAccess:DWORD, dwShareMode:DWORD, lpSecurityAttributes:QWORD, dwCreationDisposition:DWORD, dwFlagsAndAttributes:DWORD, hTemplateFile:QWORD
; IFNDEF INVALID_HANDLE_VALUE
; INVALID_HANDLE_VALUE EQU -1
; ENDIF
IFNDEF GENERIC_READ
GENERIC_READ EQU 80000000h
ENDIF
IFNDEF GENERIC_WRITE
GENERIC_WRITE EQU 40000000h
ENDIF
IFNDEF CREATE_ALWAYS
CREATE_ALWAYS EQU 2
ENDIF
IFNDEF FILE_ATTRIBUTE_NORMAL
FILE_ATTRIBUTE_NORMAL EQU 00000080h
ENDIF
includelib kernel32.lib
ENDIF
IF @Platform EQ 3 ; Linux x64
IFNDEF O_RDWR
O_RDWR EQU 00000002h
ENDIF
IFNDEF O_CREAT
O_CREAT EQU 00000100h
ENDIF
ENDIF
include UASM64.inc
.CODE
UASM64_ALIGN
;------------------------------------------------------------------------------
; File_CreateW
;
; Create a new file with read / write access and return the file handle. This
; is the Unicode version of File_Create, File_CreateA is the Ansi version.
;
; Parameters:
;
; * lpszFilename - Parameter details.
;
; Returns:
;
; A file handle if successful or INVALID_HANDLE_VALUE if an error occurred.
;
; Notes:
;
; This function as based on the MASM32 Library macro: fcreateW
;
; See Also:
;
; File_CreateA, File_OpenA, File_OpenW, File_Close, File_Read, File_Write
;
;------------------------------------------------------------------------------
File_CreateW PROC FRAME USES RDX RDI RSI lpszFilename:QWORD
IF @Platform EQ 1 ; Win x64
Invoke CreateFileW, lpszFilename, GENERIC_READ or GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
ENDIF
IF @Platform EQ 3 ; Linux x64
mov rdi, lpszFilename
mov rsi, O_RDWR or O_CREAT ; flags
mov rdx, 0 ; mode
mov rax, 2 ; open
syscall
ENDIF
ret
File_CreateW ENDP
END