@@ -55,28 +55,80 @@ namespace NetMessage
55
55
56
56
#if defined SYSTEM_WINDOWS
57
57
58
+ #if defined ARCHITECTURE_X86_OLD
59
+
58
60
static const uintptr_t CLC_CmdKeyValues_offset = 916 ;
59
61
60
62
static const uintptr_t SVC_CreateStringTable_offset = 691 ;
61
63
62
64
static const uintptr_t SVC_CmdKeyValues_offset = 1935 ;
63
65
66
+ #elif defined ARCHITECTURE_X86
67
+
68
+ static const uintptr_t CLC_CmdKeyValues_offset = 950 ;
69
+
70
+ static const uintptr_t SVC_CreateStringTable_offset = 708 ;
71
+
72
+ static const uintptr_t SVC_CmdKeyValues_offset = 2100 ;
73
+
74
+ #elif defined ARCHITECTURE_X86_64
75
+
76
+ static const uintptr_t CLC_CmdKeyValues_offset = 1037 ;
77
+
78
+ static const uintptr_t SVC_CreateStringTable_offset = 773 ;
79
+
80
+ static const uintptr_t SVC_CmdKeyValues_offset = 2443 ;
81
+
82
+ #endif
83
+
64
84
#elif defined SYSTEM_LINUX
65
85
86
+ #if defined ARCHITECTURE_X86_OLD
87
+
66
88
static const uintptr_t CLC_CmdKeyValues_offset = 716 ;
67
89
68
90
static const uintptr_t SVC_CreateStringTable_offset = 571 ;
69
91
70
92
static const uintptr_t SVC_CmdKeyValues_offset = 1691 ;
71
93
94
+ #elif defined ARCHITECTURE_X86
95
+
96
+ static const uintptr_t CLC_CmdKeyValues_offset = 743 ;
97
+
98
+ static const uintptr_t SVC_CreateStringTable_offset = 567 ;
99
+
100
+ static const uintptr_t SVC_CmdKeyValues_offset = 1707 ;
101
+
102
+ #elif defined ARCHITECTURE_X86_64
103
+
104
+ static const uintptr_t CLC_CmdKeyValues_offset = 901 ;
105
+
106
+ static const uintptr_t SVC_CreateStringTable_offset = 676 ;
107
+
108
+ static const uintptr_t SVC_CmdKeyValues_offset = 1998 ;
109
+
110
+ #endif
111
+
72
112
#elif defined SYSTEM_MACOSX
73
113
74
- static const uintptr_t CLC_CmdKeyValues_offset = 1002 ;
114
+ #if defined ARCHITECTURE_X86
115
+
116
+ static const uintptr_t CLC_CmdKeyValues_offset = 1031 ;
75
117
76
118
static const uintptr_t SVC_CreateStringTable_offset = 675 ;
77
119
78
120
static const uintptr_t SVC_CmdKeyValues_offset = 2112 ;
79
121
122
+ #elif defined ARCHITECTURE_X86_64
123
+
124
+ static const uintptr_t CLC_CmdKeyValues_offset = 1012 ;
125
+
126
+ static const uintptr_t SVC_CreateStringTable_offset = 707 ;
127
+
128
+ static const uintptr_t SVC_CmdKeyValues_offset = 2301 ;
129
+
130
+ #endif
131
+
80
132
#endif
81
133
82
134
struct Container
@@ -309,6 +361,12 @@ namespace NetMessage
309
361
310
362
|| instruction.opcode == 0xC2
311
363
364
+ #if defined ARCHITECTURE_X86_64
365
+
366
+ || ( instruction.len == 7 && instruction.opcode == 0xFF )
367
+
368
+ #endif
369
+
312
370
#elif defined SYSTEM_LINUX
313
371
314
372
|| instruction.opcode == 0x5D
@@ -318,40 +376,102 @@ namespace NetMessage
318
376
;
319
377
}
320
378
321
- inline bool IsMoveInstruction ( uint8_t opcode )
322
- {
323
-
324
- #if defined SYSTEM_WINDOWS || defined SYSTEM_LINUX
379
+ #if defined SYSTEM_WINDOWS
325
380
326
- return opcode == 0xC7 ;
381
+ inline bool IsPossibleVTable ( const hdes &instruction, const uintptr_t funcCode, void ***vtable )
382
+ {
327
383
328
- #elif defined SYSTEM_MACOSX
384
+ #if defined ARCHITECTURE_X86_64
329
385
330
- return opcode == 0x8B ;
386
+ if ( instruction.len == 7 &&
387
+ instruction.opcode == 0x8D &&
388
+ ( instruction.flags & F_DISP32 ) != 0 &&
389
+ instruction.disp .disp32 >= 10000 )
390
+ {
391
+ *vtable = reinterpret_cast <void **>( funcCode + instruction.len + instruction.disp .disp32 );
392
+ return true ;
393
+ }
331
394
332
395
#endif
333
396
397
+ if ( instruction.len == 6 &&
398
+ instruction.opcode == 0xC7 &&
399
+ ( instruction.flags & F_IMM32 ) != 0 &&
400
+ instruction.imm .imm32 >= 10000 )
401
+ {
402
+ *vtable = reinterpret_cast <void **>( hde_getimm ( instruction ) );
403
+ return true ;
404
+ }
405
+
406
+ return false ;
334
407
}
335
408
336
- inline bool IsPossibleVTable ( const hdes &instruction )
409
+ #elif defined SYSTEM_LINUX
410
+
411
+ inline bool IsPossibleVTable ( const hdes &instruction, const uintptr_t funcCode, void ***vtable )
337
412
{
338
413
339
- #if defined SYSTEM_LINUX
414
+ #if defined ARCHITECTURE_X86_64
340
415
341
416
if ( instruction.len == 7 &&
342
- IsMoveInstruction ( instruction.opcode ) &&
417
+ instruction.opcode == 0x8B &&
418
+ instruction.flags & F_DISP32 &&
419
+ instruction.disp .disp32 >= 10000 )
420
+ {
421
+ const uintptr_t address = *reinterpret_cast <const uintptr_t *>( funcCode + instruction.len + instruction.disp .disp32 );
422
+ *vtable = reinterpret_cast <void **>( address + 16 );
423
+ return true ;
424
+ }
425
+
426
+ if ( instruction.len == 7 &&
427
+ instruction.opcode == 0x8D &&
428
+ ( instruction.flags & F_DISP32 ) != 0 &&
429
+ instruction.disp .disp32 >= 10000 )
430
+ {
431
+ *vtable = reinterpret_cast <void **>( funcCode + instruction.len + instruction.disp .disp32 );
432
+ return true ;
433
+ }
434
+
435
+ #elif defined ARCHITECTURE_X86
436
+
437
+ if ( instruction.opcode == 0xC7 &&
438
+ ( instruction.flags & F_IMM32 ) != 0 &&
439
+ instruction.imm .imm32 >= 10000 &&
440
+ ( instruction.len == 6 || instruction.len == 7 ) )
441
+ {
442
+ *vtable = reinterpret_cast <void **>( hde_getimm ( instruction ) );
443
+ return true ;
444
+ }
445
+
446
+ #endif
447
+
448
+ return false ;
449
+ }
450
+
451
+ #elif defined SYSTEM_MACOSX
452
+
453
+ inline bool IsPossibleVTable ( const hdes &instruction, const uintptr_t , void ***vtable )
454
+ {
455
+ if ( instruction.len == 6 &&
456
+ instruction.opcode == 0x8B &&
343
457
( instruction.flags & F_IMM32 ) != 0 &&
344
458
instruction.imm .imm32 >= 10000 )
459
+ {
460
+ *vtable = reinterpret_cast <void **>( hde_getimm ( instruction ) );
345
461
return true ;
462
+ }
463
+
464
+ return false ;
465
+ }
346
466
347
467
#endif
348
468
349
- return instruction. len == 6 &&
350
- IsMoveInstruction ( instruction. opcode ) &&
351
- ( instruction. flags & F_IMM32 ) != 0 ;
469
+ inline const void * AdvancePointer ( const void *pointer, uint32_t offset )
470
+ {
471
+ return reinterpret_cast < const void *>( reinterpret_cast < uintptr_t >( pointer ) + offset ) ;
352
472
}
353
473
354
- static void ResolveMessagesFromFunctionCode ( GarrysMod::Lua::ILuaBase *LUA, const uint8_t *funcCode )
474
+ static void ResolveMessagesFromFunctionCode ( GarrysMod::Lua::ILuaBase *LUA, const void *funcCode )
355
475
{
356
476
CNetMessage *msg = new ( std::nothrow ) CNetMessage;
357
477
if ( msg == nullptr )
@@ -363,31 +483,33 @@ namespace NetMessage
363
483
for (
364
484
uint32_t len = hde_disasm ( funcCode, hs );
365
485
!IsEndOfFunction ( hs );
366
- funcCode += len, len = hde_disasm ( funcCode, hs )
367
- )
368
- if ( IsPossibleVTable ( hs ) )
486
+ funcCode = AdvancePointer ( funcCode, len ), len = hde_disasm ( funcCode, hs )
487
+ )
488
+ {
489
+ void **vtable = nullptr ;
490
+ if ( IsPossibleVTable ( hs, reinterpret_cast <uintptr_t >( funcCode ), &vtable ) )
369
491
{
370
- void **vtable = reinterpret_cast <void **>( hde_getimm ( hs ) );
371
492
msg->InstallVTable ( vtable );
372
493
373
494
const char *name = msg->GetName ( );
374
495
if ( netmessages_vtables.find ( name ) == netmessages_vtables.end ( ) )
375
496
netmessages_vtables[name] = vtable;
376
497
}
498
+ }
377
499
378
500
msg->InstallVTable ( msgvtable );
379
501
delete msg;
380
502
}
381
503
382
504
void PreInitialize ( GarrysMod::Lua::ILuaBase *LUA )
383
505
{
384
- auto CBaseClient_ConnectionStart =
385
- reinterpret_cast <const uint8_t *>( FunctionPointers::CBaseClient_ConnectionStart ( ) );
506
+ const void * CBaseClient_ConnectionStart =
507
+ reinterpret_cast <const void *>( FunctionPointers::CBaseClient_ConnectionStart ( ) );
386
508
if ( CBaseClient_ConnectionStart == nullptr )
387
509
LUA->ThrowError ( " failed to locate CBaseClient::ConnectionStart" );
388
510
389
- auto CBaseClientState_ConnectionStart =
390
- reinterpret_cast <const uint8_t *>( FunctionPointers::CBaseClientState_ConnectionStart ( ) );
511
+ const void * CBaseClientState_ConnectionStart =
512
+ reinterpret_cast <const void *>( FunctionPointers::CBaseClientState_ConnectionStart ( ) );
391
513
if ( CBaseClientState_ConnectionStart == nullptr )
392
514
LUA->ThrowError ( " failed to locate CBaseClientState::ConnectionStart" );
393
515
@@ -399,22 +521,22 @@ namespace NetMessage
399
521
CBaseClientState_ConnectionStart
400
522
) + SVC_CreateStringTable_offset;
401
523
ResolveMessagesFromFunctionCode ( LUA, reinterpret_cast <const uint8_t *>(
402
- SVC_CreateStringTable + sizeof ( uintptr_t ) +
403
- *reinterpret_cast <intptr_t *>( SVC_CreateStringTable )
524
+ SVC_CreateStringTable + sizeof ( int32_t ) +
525
+ *reinterpret_cast <int32_t *>( SVC_CreateStringTable )
404
526
) );
405
527
406
528
uintptr_t SVC_CmdKeyValues = reinterpret_cast <uintptr_t >(
407
529
CBaseClientState_ConnectionStart
408
530
) + SVC_CmdKeyValues_offset;
409
531
ResolveMessagesFromFunctionCode ( LUA, reinterpret_cast <const uint8_t *>(
410
- SVC_CmdKeyValues + sizeof ( uintptr_t ) + *reinterpret_cast <intptr_t *>( SVC_CmdKeyValues )
532
+ SVC_CmdKeyValues + sizeof ( int32_t ) + *reinterpret_cast <int32_t *>( SVC_CmdKeyValues )
411
533
) );
412
534
413
535
uintptr_t CLC_CmdKeyValues = reinterpret_cast <uintptr_t >(
414
536
CBaseClient_ConnectionStart
415
537
) + CLC_CmdKeyValues_offset;
416
538
ResolveMessagesFromFunctionCode ( LUA, reinterpret_cast <const uint8_t *>(
417
- CLC_CmdKeyValues + sizeof ( uintptr_t ) + *reinterpret_cast <intptr_t *>( CLC_CmdKeyValues )
539
+ CLC_CmdKeyValues + sizeof ( int32_t ) + *reinterpret_cast <int32_t *>( CLC_CmdKeyValues )
418
540
) );
419
541
}
420
542
0 commit comments