-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathArray_ItemSetText.asm
131 lines (111 loc) · 3.5 KB
/
Array_ItemSetText.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
;==============================================================================
;
; 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
;SysAllocStringByteLen PROTO psz:QWORD, len:DWORD
;SysFreeString PROTO pString:QWORD
;includelib OleAut32.lib
include UASM64.inc
EXTERNDEF d_e_f_a_u_l_t__n_u_l_l_$ :QWORD
;.DATA
;d_e_f_a_u_l_t__n_u_l_l_$ DQ 0 ; default null string as placeholder
; DQ 0,0,0
.CODE
UASM64_ALIGN
;------------------------------------------------------------------------------
; Array_ItemSetText
;
; Write a zero terminated text string to an array item.
;
; Parameters:
;
; * pArray - pointer to the array.
;
; * nItemIndex - the index of the array item to set the text for.
;
; * lpszItemText - the text string to set for the specified item index.
;
; Returns:
;
; * The written text length.
; * 0 if text length or argument is zero.
; * -1 bounds error, below 1.
; * -2 bounds error, above index.
; * -3 out of memory error.
;
; Notes:
;
; This function as based on the MASM32 Library function: arrset
;
; See Also:
;
; Array_ItemAddress, Array_ItemLength, Array_ItemSetData
;
;------------------------------------------------------------------------------
Array_ItemSetText PROC FRAME USES RBX RDI RSI pArray:QWORD, nItemIndex:QWORD, lpszItemText:QWORD
LOCAL mcnt:QWORD
LOCAL len:QWORD
.IF pArray == 0
mov rax, 0
ret
.ENDIF
mov rsi, pArray ; load array adress in ESI
mov rax, [rsi] ; write member count to EAX
mov mcnt, rax ; store count in local mcnt
mov rbx, nItemIndex ; store the index in EBX
; ---------------------
; array bounds checking.
; ---------------------
.if rbx < 1
mov rax, -1 ; return -1 below bound error
jmp quit
.endif
.if rbx > mcnt
mov rax, -2 ; return -2 above bound error
jmp quit
.endif
mov rax, [rsi+rbx*8]
.if QWORD PTR [rax] != 0 ; if its not a NULL string
Invoke _Array_SysFreeString, [rsi+rbx*8]
;invoke SysFreeString, [rsi+rbx*8] ; deallocate the array member
.endif
.if lpszItemText == 0
null_string: ; reset to default null string
lea rax, d_e_f_a_u_l_t__n_u_l_l_$
mov [rsi+rbx*8], rax ; OFFSET d_e_f_a_u_l_t__n_u_l_l_$
xor rax, rax ; return zero for string length
jmp quit
.else
Invoke String_LengthA, lpszItemText
mov rdi, rax ; rv(StrLen,ptxt)
mov len, rax
test rdi, rdi
jz null_string
Invoke _Array_SysAllocStringByteLen, lpszItemText, len
;invoke SysAllocStringByteLen, lpszItemText, edi ; allocate a buffer of that length
.if rax != 0
mov [rsi+rbx*8], rax ; write new handle back to pointer array
mov rax, rdi ; return the written length
.else
mov rax, -3 ; return -3 out of memory error
jmp quit
.endif
.endif
quit:
ret
Array_ItemSetText ENDP
END