-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWrapperFunctions.bas
More file actions
350 lines (292 loc) · 7.83 KB
/
WrapperFunctions.bas
File metadata and controls
350 lines (292 loc) · 7.83 KB
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
'====================
'==Helper Functions==
'====================
Sub OpenLBNetDLL
open "LBNet.dll" for DLL as #LBNet
a = InitLBNet()
End Sub
Sub CloseLBNetDLL
a = EndLBNet()
close #LBNet
End Sub
Function InitLBNet()
CallDLL #LBNet, "InitLBNet",_
InitLBNet as long
End Function
Function EndLBNet()
CallDLL #LBNet, "EndLBNet",_
EndLBNet as long
End Function
Function CreateTLSContext()
CallDLL #LBNet, "CreateTLSContext",_
CreateTLSContext as ulong
End Function
Function DestroyTLSContext(hTLS)
CallDLL #LBNet, "DestroyTLSContext",_
hTLS as ulong,_
DestroyTLSContext as long
End Function
Function BeginTLSClientNoValidation(hTLS)
CallDLL #LBNet, "BeginTLSClientNoValidation",_
hTLS as ulong,_
BeginTLSClientNoValidation as long
End Function
Function BeginTLSClient(hTLS)
CallDLL #LBNet, "BeginTLSClient",_
hTLS as ulong,_
BeginTLSClient as long
End Function
Function IsSocketInvalid(sock)
CallDLL #LBNet, "IsSocketInvalid",_
sock as ulong,_
IsSocketInvalid as long
End Function
Function BeginTLSServer(hTLS, serverName$)
CallDLL #LBNet, "BeginTLSServer",_
hTLS as ulong,_
serverName$ as ptr,_
BeginTLSServer as long
End Function
Function SetTLSSocket(hTLS, sock)
CallDLL #LBNet, "SetTLSSocket",_
hTLS as ulong,_
sock as long,_
SetTLSSock as long
End Function
Function PerformClientHandshake(hTLS, serverName$)
CallDLL #LBNet, "PerformClientHandshake",_
hTLS as ulong,_
serverName$ as ptr,_
PerformClientHandshake as long
End Function
Function PerformServerHandshake(hTLS, doInitialRead, initBuf$, initBufSize)
CallDLL #LBNet, "PerformServerHandshake",_
hTLS as ulong,_
doInitialRead as long,_
initBuf$ as ptr,_
initBufSize as long,_
PerformServerHandshake as long
End Function
Function CreateListenSocket(pService$)
CallDLL #LBNet, "CreateListenSocket",_
pService$ as ptr,_
CreateListenSocket as ulong
End Function
Function AcceptConnection(ServerSocket)
CallDLL #LBNet, "AcceptConnection",_
ServerSocket as ulong,_
AcceptConnection as ulong
End Function
Function IsReadAvailable(socket, msTimeout)
CallDLL #LBNet, "IsReadAvailable",_
socket as ulong,_
msTimeout as long,_
IsReadAvailable as long
End Function
Function IsTLSReadAvailable(hTLS, msTimeout)
CallDLL #LBNet, "IsTLSReadAvailable",_
hTLS as ulong,_
msTimeout as long,_
IsTLSReadAvailable as long
End Function
Function PingHost(host$, packetSize, byref status, byref msResponse, msTimeout)
struct a, b as long
struct c, d as long
a.b.struct = status
c.d.struct = msResponse
CallDLL #LBNet, "PingHost",_
host$ as ptr,_
packetSize as long,_
a as struct,_
c as struct,_
msTimeout as long,_
PingHost as long
status = a.b.struct
msResponse = c.d.struct
End Function
Function Connect(host$, srv$, msTimeout)
CallDLL #LBNet, "Connect",_
host$ as ptr,_
srv$ as ptr,_
msTimeout as long,_
Connect as long
End Function
Function ConnectFrom(host$, srv$, msTimeout, localSrv$)
CallDLL #LBNet, "ConnectFrom",_
host$ as ptr,_
srv$ as ptr,_
msTimeout as long,_
localSrv$ as ptr,_
ConnectFrom as long
End Function
Function CloseSocket(sock)
CallDLL #LBNet, "CloseSocket",_
sock as long,_
CloseSocket as long
End Function
Function GetError()
CallDLL #LBNet, "GetError",_
GetError as long
if GetError < 0 then
GetError = (abs(GetError) XOR hexdec("FFFFFFFF")) + 1
end if
End Function
Function Send(sock, msg$, msgLen)
CallDLL #LBNet, "Send",_
sock as long,_
msg$ as ptr,_
msgLen as long,_
Send as long
End Function
Function EncryptSend(hTLS, msg$, msgLen)
CallDLL #LBNet, "EncryptSend",_
hTLS as ulong,_
msg$ as ptr,_
msgLen as long,_
EncryptSend as long
End Function
Function Receive(sock, byref buf$, bufLen)
CallDLL #LBNet, "Receive",_
sock as long,_
buf$ as ptr,_
bufLen as long,_
Receive as long
End Function
Function DecryptReceive(hTLS, byref buf$, bufLen)
CallDLL #LBNet, "DecryptReceive",_
hTLS as ulong,_
buf$ as ptr,_
bufLen as long,_
DecryptReceive as long
End Function
Function EndTLSClientSession(hTLS)
CallDLL #LBNet, "EndTLSClientSession",_
hTLS as ulong,_
EndTLSClientSession as long
End Function
Function UDPConnect(host$, srv$, msTimeout)
CallDLL #LBNet, "UDPConnect",_
host$ as ptr,_
srv$ as ptr,_
msTimeout as long,_
UDPConnect as long
End Function
Function UDPConnectFrom(host$, srv$, msTimeout, localSrv$)
CallDLL #LBNet, "UDPConnectFrom",_
host$ as ptr,_
srv$ as ptr,_
msTimeout as long,_
localSrv$ as ptr,_
UDPConnectFrom as long
End Function
Function UDPSend(udpSock, buf$, bufLen)
CallDLL #LBNet, "UDPSend",_
udpSock as long,_
buf$ as ptr,_
bufLen as long,_
0 as long,_
UDPSend as long
End Function
Function UDPSendTo(udpSock, buf$, bufLen, udpInfo$)
CallDLL #LBNet, "UDPSend",_
udpSock as long,_
buf$ as ptr,_
bufLen as long,_
udpInfo$ as ptr,_
UDPSendTo as long
End Function
Function UDPClose(udpSock)
CallDLL #LBNet, "UDPClose",_
udpSock as long,_
UDPClose as long
End Function
Function UDPGetInfoSize()
CallDLL #LBNet, "UDPGetInfoSize",_
UDPGetInfoSize as long
End Function
Function UDPReceive(udpSock, byref buf$, bufLen)
CallDLL #LBNet, "UDPReceive",_
udpSock as long,_
buf$ as ptr,_
bufLen as long,_
0 as long,_
UDPReceive as long
End Function
Function UDPReceiveFrom(udpSock, byref buf$, bufLen, byref udpFrom$)
udpFrom$ = space$(UDPGetInfoSize())
CallDLL #LBNet, "UDPReceive",_
udpSock as long,_
buf$ as ptr,_
bufLen as long,_
udpFrom$ as ptr,_
UDPReceiveFrom as long
End Function
Function UDPIsReadAvailable(udpSock, msTimeout)
CallDLL #LBNet, "UDPIsReadAvailable",_
udpSock as long,_
msTimeout as long,_
UDPIsReadAvailable as long
End Function
Function UDPCreateListenSocket(pService$)
CallDLL #LBNet, "UDPCreateListenSocket",_
pService$ as ptr,_
UDPCreateListenSocket as long
End Function
Function UDPEnableBroadcast(udpSock)
CallDLL #LBNet, "UDPEnableBroadcast",_
udpSock as long,_
UDPEnableBroadcast as long
End Function
Function UDPGetRemoteIP$(udpInfo$)
UDPGetRemoteIP$ = ""
CallDLL #LBNet, "UDPGetRemoteIP",_
udpInfo$ as ptr,_
ret as ulong
If ret <> 0 then UDPGetRemoteIP$ = winstring(ret)
End Function
Function UDPGetRemotePort(udpInfo$)
CallDLL #LBNet, "UDPGetRemotePort",_
udpInfo$ as ptr,_
UDPGetRemotePort as long
End Function
Function UDPSetRemoteIP(byref udpInfo$, newIP$, family)
tempInfo$ = udpInfo$
CallDLL #LBNet, "UDPSetRemoteIP",_
tempInfo$ as ptr,_
newIP$ as ptr,_
family as long,_
UDPSetRemoteIP as long
If UDPSetRemoteIP = 1 then
udpInfo$ = tempInfo$
End If
End Function
Function UDPSetRemotePort(byref udpInfo$, port)
tempInfo$ = udpInfo$
CallDLL #LBNet, "UDPSetRemotePort",_
tempInfo$ as ptr,_
port as ushort,_
UDPSetRemotePort as long
udpInfo$ = tempInfo$
End Function
Function CreateListenSocketOnAddress(pAddress$, pService$)
CallDLL #LBNet, "CreateListenSocketOnAddress",_
pAddress$ as ptr,_
pService$ as ptr,_
CreateListenSocketOnAddress as ulong
End Function
Function UDPCreateListenSocketOnAddress(pAddress$, pService$)
CallDLL #LBNet, "UDPCreateListenSocketOnAddress",_
pAddress$ as ptr,_
pService$ as ptr,_
UDPCreateListenSocketOnAddress as long
End Function
Function GetErrorText$(errnum)
bufSize = 1024
buf$ = space$(bufSize)
CallDLL #kernel32, "FormatMessageA",_
_FORMAT_MESSAGE_FROM_SYSTEM as long,_
0 as long, errnum as long, 0 as long,_
buf$ as ptr, bufSize as long, 0 as long,_
ret as long
GetErrorText$ = left$(buf$, ret)
End Function