summaryrefslogtreecommitdiff
path: root/asm/rich4_crt_mthread.asm
blob: 26e66b7e44b0e4dfd8fe406c27a79cd4b8b9d5b8 (plain)
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
global __AllocInitThreadData
global __NTAddThread
global __NTRemoveThread
global __NTThreadFini

extern __imp__GetLastError@0
extern __imp__CloseHandle@4
extern __imp__SetLastError@4
extern __imp__TlsAlloc@0
extern __imp__TlsFree@4
extern __imp__TlsGetValue@4
extern __imp__TlsSetValue@8
extern clib_free
extern fcn_0045c836
extern fcn_0045e8ca
extern __GetThreadData
extern __InitThreadData
extern lib_calloc
extern __ReallocThreadData
extern ref_00488f78
extern ref_00488f7c
extern ref_00499954
extern _RWD_osbuild
extern _RWD_osmajor
extern __ThreadDataSize
extern __TlsIndex


section .text

__MultipleThread:
push ebx
push esi
call dword [cs:__imp__GetLastError@0]  ; ucall: call dword cs:[0x4623ac]
mov edx, dword [__TlsIndex]  ; mov edx, dword [0x488f48]
push edx
mov esi, eax
call dword [cs:__imp__TlsGetValue@4]  ; ucall: call dword cs:[0x46241c]
mov ebx, eax
test eax, eax
jne short loc_0045a223  ; jne 0x45a223
call __GetThreadData  ; call 0x45c6be
jmp short loc_0045a22e  ; jmp 0x45a22e

loc_0045a223:
cmp byte [eax + 0x53], 0
je short loc_0045a230  ; je 0x45a230
call __ReallocThreadData  ; call 0x45c6f5

loc_0045a22e:
mov ebx, eax

loc_0045a230:
push esi
call dword [cs:__imp__SetLastError@4]  ; ucall: call dword cs:[0x462408]
mov eax, ebx
pop esi
pop ebx
ret

__AllocInitThreadData:
push ebx
mov ebx, dword [esp + 8]
test ebx, ebx
jne short loc_0045a26d  ; jne 0x45a26d
mov edx, dword [__ThreadDataSize]  ; mov edx, dword [0x4894b0]
push edx
push 1
call lib_calloc  ; call 0x45c62e
add esp, 8
mov ebx, eax
test eax, eax
je short loc_0045a26d  ; je 0x45a26d
mov edx, dword [__ThreadDataSize]  ; mov edx, dword [0x4894b0]
mov byte [eax + 0x52], 1
mov dword [eax + 0xf0], edx

loc_0045a26d:
push ebx
call __InitThreadData  ; call 0x45c8d7
add esp, 4
mov eax, ebx
pop ebx
ret

__NTThreadInit:
call dword [cs:__imp__TlsAlloc@0]  ; ucall: call dword cs:[0x462414]
mov dx, word [_RWD_osbuild]  ; mov dx, word [0x489355]
mov dword [__TlsIndex], eax  ; mov dword [0x488f48], eax
cmp dx, 0x8000
jb short loc_0045a2bb  ; jb 0x45a2bb
cmp byte [_RWD_osmajor], 4  ; cmp byte [0x489353], 4
jae short loc_0045a2bb  ; jae 0x45a2bb

loc_0045a29d:
mov edx, dword [__TlsIndex]  ; mov edx, dword [0x488f48]
cmp edx, 0xffffffff
je short loc_0045a2bb  ; je 0x45a2bb
cmp edx, 2
ja short loc_0045a2bb  ; ja 0x45a2bb
call dword [cs:__imp__TlsAlloc@0]  ; ucall: call dword cs:[0x462414]
mov dword [__TlsIndex], eax  ; mov dword [0x488f48], eax
jmp short loc_0045a29d  ; jmp 0x45a29d

loc_0045a2bb:
cmp dword [__TlsIndex], 0xffffffff  ; cmp dword [0x488f48], 0xffffffff
setne al
and eax, 0xff
ret

__NTAddThread:
push ebx
push esi
cmp dword [__TlsIndex], 0xffffffff  ; cmp dword [0x488f48], 0xffffffff
jne short loc_0045a2db  ; jne 0x45a2db

loc_0045a2d6:
xor eax, eax
pop esi
pop ebx
ret

loc_0045a2db:
mov ebx, dword [esp + 0xc]
push ebx
call __AllocInitThreadData  ; call 0x45a23d
mov ebx, eax
add esp, 4
test eax, eax
je short loc_0045a321  ; je 0x45a321
push eax
mov ecx, dword [eax + 0xda]
push ecx
call __AddThreadData  ; call 0x45c7ca
add esp, 8
test eax, eax
jne short loc_0045a30d  ; jne 0x45a30d
push ebx
call clib_free  ; call 0x456e11
add esp, 4
jmp short loc_0045a2d6  ; jmp 0x45a2d6

loc_0045a30d:
push ebx
mov esi, dword [__TlsIndex]  ; mov esi, dword [0x488f48]
push esi
call dword [cs:__imp__TlsSetValue@8]  ; ucall: call dword cs:[0x462420]
mov eax, 1

loc_0045a321:
pop esi
pop ebx
ret

__NTRemoveThread:
push ebx
push esi
mov edx, dword [__TlsIndex]  ; mov edx, dword [0x488f48]
cmp edx, 0xffffffff
je short loc_0045a375  ; je 0x45a375
push edx
call dword [cs:__imp__TlsGetValue@4]  ; ucall: call dword cs:[0x46241c]
test eax, eax
je short loc_0045a375  ; je 0x45a375
mov ecx, dword [eax + 0xda]
push ecx
mov ebx, dword [eax + 0xde]
call fcn_0045c836  ; call 0x45c836
add esp, 4
push 0
mov esi, dword [__TlsIndex]  ; mov esi, dword [0x488f48]
push esi
call dword [cs:__imp__TlsSetValue@8]  ; ucall: call dword cs:[0x462420]
test ebx, ebx
je short loc_0045a375  ; je 0x45a375
cmp dword [esp + 0xc], 0
je short loc_0045a375  ; je 0x45a375
push ebx
call dword [cs:__imp__CloseHandle@4]  ; ucall: call dword cs:[0x462348]

loc_0045a375:
pop esi
pop ebx
ret

__ThreadExit:
push 1
call __NTRemoveThread  ; call 0x45a324
add esp, 4

__NTThreadFini:
mov edx, dword [__TlsIndex]  ; mov edx, dword [0x488f48]
cmp edx, 0xffffffff
je short loc_0045a39f  ; je 0x45a39f
push edx
call dword [cs:__imp__TlsFree@4]  ; ucall: call dword cs:[0x462418]
mov dword [__TlsIndex], 0xffffffff  ; mov dword [0x488f48], 0xffffffff

loc_0045a39f:
ret

	;; trdlist.c

__AddThreadData:
push ebx
push esi
push edi
mov edi, dword [esp + 0x14]
call dword [ref_00488f78]  ; ucall: call dword [0x488f78]
push 0x10
mov esi, 1
push esi
call lib_calloc  ; call 0x45c62e
mov ebx, eax
add esp, 8
test eax, eax
je short loc_0045c828  ; je 0x45c828
push edi
call fcn_0045e8ca  ; call 0x45e8ca
add esp, 4
test eax, eax
je short loc_0045c807  ; je 0x45c807
push ebx
call clib_free  ; call 0x456e11
xor esi, esi
add esp, 4
jmp short loc_0045c82a  ; jmp 0x45c82a

loc_0045c807:
mov eax, dword [esp + 0x10]
mov dword [ebx + 8], edi
mov dword [ebx + 4], eax
xor eax, eax
mov al, byte [edi + 0x52]
mov dword [ebx + 0xc], eax
mov eax, dword [ref_00499954]  ; mov eax, dword [0x499954]
mov dword [ref_00499954], ebx  ; mov dword [0x499954], ebx
mov dword [ebx], eax
jmp short loc_0045c82a  ; jmp 0x45c82a

loc_0045c828:
xor esi, esi

loc_0045c82a:
call dword [ref_00488f7c]  ; ucall: call dword [0x488f7c]
mov eax, esi
pop edi
pop esi
pop ebx
ret