-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathArray_Helper.asm
135 lines (121 loc) · 2.9 KB
/
Array_Helper.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
;==============================================================================
;
; 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
_Array_SysAllocStringByteLen PROTO psz:QWORD, len:QWORD
_Array_SysFreeString PROTO pString:QWORD
include UASM64.inc
.CODE
UASM64_ALIGN
;------------------------------------------------------------------------------
; _Array_SysAllocStringByteLen
;
; Internal function used by array functions to emulate a 64bit version of
; a SysAllocStringByteLen function with QWORD size length at start of the BSTR
; structure.
;
; Parameters:
;
; * psz - The string to copy.
;
; * len - The number of bytes to copy.
;
; Returns:
;
; Pointer to the BSTR string, or 0 if an error occurred.
;
; Notes:
;
; This function as based on the MASM32 Library function:
;
; See Also:
;
; _Array_SysFreeString
;
;------------------------------------------------------------------------------
_Array_SysAllocStringByteLen PROC FRAME USES RCX RDX RDI RSI psz:QWORD, len:QWORD
LOCAL pBSTR:QWORD
LOCAL pBSTR_String:QWORD
LOCAL qwBSTR_Size:QWORD
.IF psz == 0 || len == 0
mov rax, 0
ret
.ENDIF
mov rax, len
add rax, 12d ; 8 for length at start and 4 for null ending
mov qwBSTR_Size, rax
Invoke Memory_Alloc, qwBSTR_Size
.IF rax != 0
mov pBSTR, rax
mov rcx, pBSTR
mov rax, len
mov [rcx], rax
add rcx, 8
mov pBSTR_String, rcx
IF @Platform EQ 1 ; Win x64
Invoke Memory_Copy, psz, pBSTR_String, len
ENDIF
IF @Platform EQ 3 ; Linux x64
mov rdi, psz
mov rsi, pBSTR_String
mov rdx, len
call Memory_Copy
ENDIF
mov rax, pBSTR_String
.ENDIF
ret
_Array_SysAllocStringByteLen ENDP
UASM64_ALIGN
;------------------------------------------------------------------------------
; _Array_SysFreeString
;
; Internal function used by array functions to emulate a 64bit version of
; SysFreeString functions.
;
; Parameters:
;
; * pString - The previously allocated string.
;
; Returns:
;
; TRUE if successful, or FALSE otherwise.
;
; Notes:
;
; This function as based on the MASM32 Library function:
;
; See Also:
;
; _Array_SysFreeString
;
;------------------------------------------------------------------------------
_Array_SysFreeString PROC FRAME USES RBX pString:QWORD
LOCAL pBSTR:QWORD
.IF pString == 0
mov rax, 0
ret
.ENDIF
mov rbx, pString
sub rbx, 8
mov pBSTR, rbx
mov rax, [rbx]
.IF rax != 0 ; check there is a length value
mov rax, 0 ; null it
mov [rbx], rax
Invoke Memory_Free, pBSTR
.ENDIF
ret
_Array_SysFreeString ENDP
END