-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstack.asm
165 lines (134 loc) · 5.15 KB
/
stack.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
154
155
156
157
158
159
160
161
162
163
164
165
JSONStackItemCreate PROTO :DWORD
JSONStackItemFree PROTO :DWORD
JSONStackItemGetCount PROTO :DWORD
JSONStackItemSetCount PROTO :DWORD, :DWORD
JSONStackItemIncCount PROTO :DWORD
JSONStackItemArrayIteratorName PROTO :DWORD, :DWORD
JSONStackItemsDeleteCallback PROTO :DWORD, :DWORD
JSONSTACKITEM STRUCT
szItemName DB 64 DUP (?)
dwItemCount DD ?
JSONSTACKITEM ENDS
.CODE
;-------------------------------------------------------------------------------------
; JSONStackItemCreate - Creates a JSONSTACKITEM json stack item
;-------------------------------------------------------------------------------------
JSONStackItemCreate PROC USES EBX lpszJsonItemName:DWORD
LOCAL ptrJsonStackItem:DWORD
.IF lpszJsonItemName == NULL
mov eax, NULL
ret
.ENDIF
Invoke szLen, lpszJsonItemName
.IF eax == 0
mov eax, NULL
ret
.ENDIF
Invoke GlobalAlloc, GMEM_FIXED or GMEM_ZEROINIT, SIZEOF JSONSTACKITEM
.IF eax == NULL
ret
.ENDIF
mov ptrJsonStackItem, eax
mov ebx, eax
lea eax, [ebx].JSONSTACKITEM.szItemName
Invoke lstrcpyn, eax, lpszJsonItemName, 64d
mov ebx, ptrJsonStackItem
mov [ebx].JSONSTACKITEM.dwItemCount, 0
mov eax, ptrJsonStackItem
ret
JSONStackItemCreate ENDP
;-------------------------------------------------------------------------------------
; JSONStackItemFree - Free JSONSTACKITEM item created by JSONStackItemCreate
;-------------------------------------------------------------------------------------
JSONStackItemFree PROC ptrJsonStackItem:DWORD
mov eax, ptrJsonStackItem
.IF eax != NULL
Invoke GlobalFree, eax
.ENDIF
xor eax, eax
ret
JSONStackItemFree ENDP
;-------------------------------------------------------------------------------------
; JSONStackItemIncCount - increments JSONSTACKITEM counter for use in next call to
;JSONStackItemArrayIteratorName
;-------------------------------------------------------------------------------------
JSONStackItemIncCount PROC USES EBX ptrJsonStackItem:DWORD
.IF ptrJsonStackItem == NULL
mov eax, 0
ret
.ENDIF
mov ebx, ptrJsonStackItem
mov eax, [ebx].JSONSTACKITEM.dwItemCount
inc eax
mov [ebx].JSONSTACKITEM.dwItemCount, eax
ret
JSONStackItemIncCount ENDP
;-------------------------------------------------------------------------------------
; JSONStackItemArrayIteratorName - Creates next array name: Thing[1], Thing[2], etc
;-------------------------------------------------------------------------------------
JSONStackItemArrayIteratorName PROC USES EBX ptrJsonStackItem:DWORD, lpszNameBuffer:DWORD
LOCAL dwCount:DWORD
LOCAL szCount[16]:BYTE
.IF ptrJsonStackItem == NULL
mov eax, FALSE
ret
.ENDIF
.IF lpszNameBuffer == NULL
mov eax, FALSE
ret
.ENDIF
mov ebx, ptrJsonStackItem
mov eax, [ebx].JSONSTACKITEM.dwItemCount
mov dwCount, eax
lea eax, [ebx].JSONSTACKITEM.szItemName
Invoke lstrcpyn, lpszNameBuffer, eax, 64d
Invoke dwtoa, dwCount, Addr szCount
Invoke szCatStr, lpszNameBuffer, Addr szLeftSquareBracket
Invoke szCatStr, lpszNameBuffer, Addr szCount
Invoke szCatStr, lpszNameBuffer, Addr szRightSquareBracket
mov eax, TRUE
ret
JSONStackItemArrayIteratorName ENDP
;-------------------------------------------------------------------------------------
; JSONStackItemsDeleteCallback - callback to clean up virtual stack that had array names
; Calls JSONStackItemFree to free JSONSTACKITEM items, only unique items, so we
; dont get an error trying to free memory we already freed
;-------------------------------------------------------------------------------------
JSONStackItemsDeleteCallback PROC hStack:DWORD, ptrStackItem:DWORD
.IF hStack == NULL
ret
.ENDIF
.IF ptrStackItem == NULL
ret
.ENDIF
;PrintText 'JSONStackItemsDeleteCallback'
;PrintDec hStack
;PrintDec ptrStackItem
Invoke JSONStackItemFree, ptrStackItem
ret
JSONStackItemsDeleteCallback endp
;-------------------------------------------------------------------------------------
; JSONStackItemGetCount - Function not used currently
;-------------------------------------------------------------------------------------
JSONStackItemGetCount PROC USES EBX ptrJsonStackItem:DWORD
; .IF ptrJsonStackItem == NULL
; mov eax, 0
; ret
; .ENDIF
; mov ebx, ptrJsonStackItem
; mov eax, [ebx].JSONSTACKITEM.dwItemCount
ret
JSONStackItemGetCount ENDP
;-------------------------------------------------------------------------------------
; JSONStackItemSetCount - Function not used currently
;-------------------------------------------------------------------------------------
JSONStackItemSetCount PROC USES EBX ptrJsonStackItem:DWORD, dwCountValue:DWORD
; .IF ptrJsonStackItem == NULL
; mov eax, 0
; ret
; .ENDIF
; mov ebx, ptrJsonStackItem
; mov eax, dwCountValue
; mov [ebx].JSONSTACKITEM.dwItemCount, eax
ret
JSONStackItemSetCount ENDP