-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathClient.c
347 lines (283 loc) · 7.4 KB
/
Client.c
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
#include "Client.h"
#include "allocation.h"
#include <windows.h>
#include <stdio.h>
#include <WinSock.h>
#include "PE.h"
#include "Process.h"
#include <string.h>
#include "Tools.h"
#include "Hooks.h"
UOCallibrations * callibrations=0;
typedef int (__stdcall *pConnect)(SOCKET s, const struct sockaddr * name, int namelen);
typedef void (__stdcall *pConnectionLoss)();
pConnect _original_connect = 0;
pConnectionLoss _original_connection_loss_handler = 0;
void __stdcall onConnectionLoss()
{
void * thispointer;
_asm
{
mov thispointer, ecx
}
callibrations->ShowMessage(5555, 0, "connection loss");
if(_original_connection_loss_handler)
{
_asm
{
mov ecx, thispointer
}
_original_connection_loss_handler();
}
}
int __stdcall connect_hook(SOCKET s, const struct sockaddr *name, int namelen)
{
char msg[256] = {'\0'};
if(_original_connect!=0)
{
if(callibrations)
{
sprintf(msg, "Connecting to ");
sprintip(&msg[strlen(msg)], ((struct sockaddr_in *)name)->sin_addr.S_un.S_addr);
callibrations->ShowMessage(5555, 0, msg);
}
return _original_connect(s, name, namelen);
}
else
return connect(s, name, namelen);
}
unsigned int sbo(unsigned int toswap)
{
unsigned char * bytes = (unsigned char *)toswap;
unsigned char temp;
temp = bytes[0];
bytes[0] = bytes[3];
bytes[3] = temp;
temp = bytes[1];
bytes[1] = bytes[2];
bytes[2] = temp;
return *((unsigned int *)bytes);
}
int HandlePacketHook(RegisterStates * regs, void * stacktop)
{
char * pPacket = *((char **)stacktop);
unsigned int cmd;
if(pPacket!=NULL)
{
cmd = (unsigned int)(pPacket[0])&0xFF;
printf("received packet %x\n", cmd);
if( cmd == 0x4F)
{
pPacket[1] = 0;
}
/* test */
if(cmd == 0xAE)
{
unsigned int * pID;
unsigned int ID, i;
char name[30];
unsigned short * speech;
unsigned short uspeech[256];
char * cSpeech;
pID = (unsigned int *)&pPacket[3];
ID = htonl(*pID);
memset(name, 0, 30);
strncpy(name, &pPacket[18], 30);
speech = (unsigned short *)&pPacket[48];
i=0;
memset(uspeech, 0, sizeof(unsigned short)*256);
while((speech[i]!=0)&&(i<255))
{
uspeech[i] = ntohs(speech[i]);
i++;
}
cSpeech = ole2char((LPOLESTR)uspeech);
printf("%s (%u) : %s\n", name, ID, cSpeech);
clean(cSpeech);
}
}
return 1;
}
int SendPacketHook(RegisterStates * regs, void * stacktop)
{
char * pPacket = *((char **)stacktop);
unsigned int cmd;
if(pPacket!=NULL)
{
cmd = (unsigned int)(pPacket[0])&0xFF;
printf("sent packet %x\n", cmd);
/* tests */
//if(cmd == 0xAD)
// return 0;
if(cmd == 0x02)
callibrations->ShowMessage(3, 0, "walk request");
}
return 1;
}
void Client_constructor(Client * pThis)
{
_original_connect = (pConnect)SetImportHook("WSOCK32.dll", "connect", (void *)connect_hook);
if(SetRandomHook((unsigned int)(callibrations->SendPacket), 4, SendPacketHook)==0)
printf("failed to set sendpacket hook!\n");
if(SetVtblHook((void *)&(callibrations->NetworkObjectVtbl->HandlePacket), HandlePacketHook, 4))
printf("failed to set handlepacket hook!\n");
/*
_original_connection_loss_handler = callibrations->NetworkObjectVtbl->onConnectionLoss;
VirtualProtect((void *)callibrations->NetworkObjectVtbl, sizeof(NetworkObjectClassVtbl), PAGE_READWRITE, &oldprotect);
callibrations->NetworkObjectVtbl->onConnectionLoss = onConnectionLoss;
VirtualProtect((void *)callibrations->NetworkObjectVtbl, sizeof(NetworkObjectClassVtbl), oldprotect, &oldprotect);
*/
if(callibrations)
{
callibrations->ShowMessage(5555, 0, "-- UOAI enabled client --");
}
}
void Client_destructor(Client * pThis)
{
printf("client destruction\n");
}
HRESULT STDMETHODCALLTYPE GetPID(Client * pThis, unsigned int * pPID)
{
(*pPID)=GetCurrentProcessId();
return S_OK;
}
HRESULT STDMETHODCALLTYPE ClientWrite(Client * pThis, unsigned int color, unsigned int font, BSTR message)
{
char * cmessage;
cmessage=ole2char(message);
callibrations->ShowMessage(color, font, cmessage);
clean(cmessage);
SysFreeString(message);
return S_OK;
}
void closegump(void * pGump)
{
if(pGump == NULL)
return;
__asm
{
mov ecx, pGump
mov eax, [ecx]
mov edx, [eax]
push 1
call edx
}
return;
}
void __stdcall onyes(void * pThis)
{
callibrations->ShowMessage(5555, 0, "Yes!");
closegump(pThis);
return;
}
void __stdcall onno(void * pThis)
{
callibrations->ShowMessage(5555, 0, "No!");
closegump(pThis);
return;
}
typedef void (__stdcall * pYesNoGumpConstructor_wrapper)(void * pThis, char * text, pYesNoGumpCallback onYes, pYesNoGumpCallback onNo, unsigned int unknown);
typedef void (__stdcall * pShowGump_wrapper)(void * pThis, void * parent, int bUnknown);//thiscall gump->Show(parent_gump)
HRESULT STDMETHODCALLTYPE ShowYesNoGump(Client * pThis, BSTR question)
{
static pYesNoGumpCallback _onYesCallback = 0;
static pYesNoGumpCallback _onNoCallback = 0;
static pYesNoGumpConstructor_wrapper YNGump_constructor = NULL;
static pShowGump_wrapper ShowGump = NULL;
char * cquestion;
void * pgump;
if(_onYesCallback == 0)
_onYesCallback = (pYesNoGumpCallback)create_thiscall_callback((unsigned int)onyes);
if(_onNoCallback == 0)
_onNoCallback = (pYesNoGumpCallback)create_thiscall_callback((unsigned int)onno);
if(YNGump_constructor == NULL)
YNGump_constructor = (pYesNoGumpConstructor_wrapper)create_thiscall_wrapper((unsigned int)callibrations->YesNoGumpConstructor);
if(ShowGump == NULL)
ShowGump = (pShowGump_wrapper)create_thiscall_wrapper((unsigned int)callibrations->ShowGump);
/*
ync = (unsigned int)callibrations->YesNoGumpConstructor;
sg = (unsigned int)callibrations->ShowGump;
*/
if(cquestion = ole2char(question))
{
//printf("allocating...\n");
pgump = callibrations->Allocator(callibrations->YesNoGumpSize);
if(pgump!=0)
{
//printf("constructing...\n");
/*
_asm
{
push 0
push onNoCallback
push onYesCallback
push cquestion
mov ecx, pgump
call ync
}
printf("showing...\n");
_asm
{
push 0
push 0
mov ecx, pgump
call sg
}
*/
YNGump_constructor(pgump, cquestion, _onYesCallback, _onNoCallback, 0);
ShowGump(pgump, NULL, 0);
}
/*
else
printf("gump allocation failed!\n");
*/
clean(cquestion);
}
SysFreeString(question);
return S_OK;
}
HRESULT STDMETHODCALLTYPE Bark(Client * pThis, BSTR speech)
{
char * cspeech;
unsigned int pPlayer;
unsigned int pBark;
pPlayer = *((unsigned int *)callibrations->Player);
pBark = (unsigned int)callibrations->Bark;
if(cspeech = ole2char(speech))
{
_asm
{
push 0
push 0
push 0
push 5555
push cspeech
mov ecx, pPlayer
call pBark
}
clean(cspeech);
}
SysFreeString(speech);
return S_OK;
}
void SetCallibrations(UOCallibrations * callibs)
{
if(callibrations)
clean(callibrations);
callibrations=callibs;
return;
}
UOCallibrations * GetCallibrations()
{
return callibrations;
}
HRESULT STDMETHODCALLTYPE GetPlayer(Client * pThis, Item ** pPlayer)
{
(*pPlayer) = GetItemByOffset(*((unsigned int *)(callibrations->Player)));
return S_OK;
}
HRESULT STDMETHODCALLTYPE GetItems(Client * pThis, void ** pItems)
{
(*pItems) = (void *)create_itemlist(0);
return S_OK;
}