Skip to content

Commit c7810fa

Browse files
committed
Merge branch 'master' into engine_sdk2013
2 parents 1201b3c + 9a92f4c commit c7810fa

File tree

4 files changed

+85
-18
lines changed

4 files changed

+85
-18
lines changed

addons/source-python/data/source-python/entity_output/csgo/CBaseEntityOutput.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ srv_check = False
55

66
[function]
77
[[fire_output]]
8-
identifier_linux = _ZN17CBaseEntityOutput10FireOutputE9variant_tP11CBaseEntityS2_f
8+
# identifier_linux = _ZN17CBaseEntityOutput10FireOutputE9variant_tP11CBaseEntityS2_f
9+
identifier_linux = 55 89 E5 57 56 53 81 EC 7C 01 00 00 8B 55 08 8B 75 14
910
identifier_windows = 55 8B EC 83 2A 2A 81 EC 2A 2A 2A 2A 8B C1 53 56 57 8B 2A 2A 89 2A 2A 2A 33
1011
arguments_linux = POINTER, POINTER, POINTER, FLOAT
11-
arguments_windows = INT, INT, INT, INT, POINTER, POINTER, POINTER, FLOAT
12+
arguments_windows = INT, INT, INT, INT, POINTER, POINTER, POINTER, FLOAT

addons/source-python/data/source-python/memory/csgo/global_pointers.ini

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,40 @@
33
[CEntityFactoryDictionary]
44
binary = server
55
srv_check = False
6-
identifier_linux = _ZZ23EntityFactoryDictionaryvE15s_EntityFactory
6+
# identifier_linux = _ZZ23EntityFactoryDictionaryvE15s_EntityFactory
7+
identifier_linux = 55 89 E5 83 EC 28 80 3D 2A 2A 2A 2A 00 74 2A C9 B8 2A 2A 2A 2A C3 8D 76 00 8D BC 27 00 00 00 00 C7 04 24 2A 2A 2A 2A E8 58 52 43 00
78
identifier_windows = 56 FF 75 08 B9 2A 2A 2A 2A E8 2A 2A 2A 2A 8B C8 C7
89
offset_windows = 5
9-
level_windows = 1
10+
offset_linux = 17
11+
level = 1
1012

1113
[CGlobalEntityList]
1214
binary = server
13-
identifier_linux = gEntList
15+
srv_check = False
16+
identifier_linux = E8 2A 2A 2A 2A E8 2A 2A 2A 2A C7 2A 2A 2A 2A 2A 2A E8 2A 2A 2A 2A E8
1417
# Search the signature of OnCBaseEntityList::AddNonNetworkableEntity(IHandleEntity *)
1518
# Note: The Linux binary does not contain the gEntList pointer in that function!
1619
identifier_windows = 55 8B EC 8B 0D 2A 2A 2A 2A 53
1720
offset_windows = 101
18-
level_windows = 1
19-
srv_check = False
21+
offset_linux = 13
22+
level = 1
2023

2124
[IServer]
2225
binary = bin/engine
23-
identifier_linux = sv
26+
srv_check = False
27+
# identifier_linux = sv
28+
identifier_linux = 55 89 E5 53 83 EC 14 8B 45 0C C7 04 24 2A 2A 2A 2A
2429
identifier_windows = 55 8B EC 56 FF 2A 2A B9 2A 2A 2A 2A E8 2A 2A 2A 2A 8B
2530
offset_windows = 8
26-
level_windows = 1
27-
srv_check = False
28-
31+
offset_linux = 13
32+
level = 1
2933

3034
[CBaseTempEntity]
3135
binary = server
3236
srv_check = False
33-
identifier_linux = _ZN15CBaseTempEntity15s_pTempEntitiesE
37+
# identifier_linux = _ZN15CBaseTempEntity15s_pTempEntitiesE
38+
identifier_linux = 55 89 E5 8B 45 08 8B 55 0C C7 00 2A 2A 2A 2A 89 50 04 8B 15 2A 2A 2A 2A
3439
identifier_windows = 89 41 04 A1 2A 2A 2A 2A 89 41 08 89 0D 2A 2A 2A 2A C7
3540
offset_windows = 4
36-
level_windows = 2
37-
level_linux = 1
41+
offset_linux = 20
42+
level = 2

addons/source-python/packages/source-python/listeners/_entity_output.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@
2929
'BaseEntityOutput', GameConfigObj(
3030
SP_DATA_PATH / 'entity_output' / 'CBaseEntityOutput.ini'))
3131

32-
_fire_output = getattr(BaseEntityOutput, 'fire_output', None)
32+
try:
33+
_fire_output = getattr(BaseEntityOutput, 'fire_output', None)
34+
except ValueError:
35+
# In case the pointer wasn't found
36+
_fire_output = None
37+
3338
on_entity_output_listener_manager = (
3439
None if _fire_output is None else ListenerManager()
3540
)

src/core/modules/memory/memory_scanner.cpp

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include <fcntl.h>
3535
#include <link.h>
3636
#include <sys/mman.h>
37+
extern int PAGE_SIZE;
38+
#define PAGE_ALIGN_UP(x) ((x + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
3739
#endif
3840

3941
#include "dynload.h"
@@ -327,10 +329,8 @@ CPointer* CBinaryFile::FindPointer(object oIdentifier, int iOffset, unsigned int
327329

328330
CPointer* CBinaryFile::FindAddress(object oIdentifier)
329331
{
330-
#ifdef _WIN32
331332
if(CheckClassname(oIdentifier, "bytes"))
332333
return FindSignature(oIdentifier);
333-
#endif
334334

335335
return FindSymbol(extract<char*>(oIdentifier));
336336
}
@@ -526,8 +526,64 @@ CBinaryFile* CBinaryManager::FindBinary(char* szPath, bool bSrvCheck /* = true *
526526
ulSize = nt->OptionalHeader.SizeOfImage;
527527

528528
#elif defined(__linux__)
529-
ulSize = 0;
529+
// Copied from here. Thanks!
530+
// https://github.com/alliedmodders/sourcemod/blob/237db0504c7a59e394828446af3e8ca3d53ef647/core/logic/MemoryUtils.cpp#L486
531+
532+
Elf32_Ehdr *file;
533+
Elf32_Phdr *phdr;
534+
uint16_t phdrCount;
535+
536+
struct link_map *lm = (struct link_map*) ulAddr;
537+
ulAddr = reinterpret_cast<uintptr_t>(lm->l_addr);
538+
file = reinterpret_cast<Elf32_Ehdr *>(ulAddr);
539+
540+
/* Check ELF magic */
541+
if (memcmp(ELFMAG, file->e_ident, SELFMAG) != 0)
542+
{
543+
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "ELF magic check failed.");
544+
}
545+
546+
/* Check ELF version */
547+
if (file->e_ident[EI_VERSION] != EV_CURRENT)
548+
{
549+
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "ELF version check failed.");
550+
}
530551

552+
/* Check ELF architecture, which is 32-bit/x86 right now
553+
* Should change this for 64-bit if Valve gets their act together
554+
*/
555+
if (file->e_ident[EI_CLASS] != ELFCLASS32 || file->e_machine != EM_386 || file->e_ident[EI_DATA] != ELFDATA2LSB)
556+
{
557+
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "ELF architecture check failed.");
558+
}
559+
560+
/* For our purposes, this must be a dynamic library/shared object */
561+
if (file->e_type != ET_DYN)
562+
{
563+
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Library is not a dynamic or shared object.");
564+
}
565+
566+
phdrCount = file->e_phnum;
567+
phdr = reinterpret_cast<Elf32_Phdr *>(ulAddr + file->e_phoff);
568+
569+
for (uint16_t i = 0; i < phdrCount; i++)
570+
{
571+
Elf32_Phdr &hdr = phdr[i];
572+
573+
/* We only really care about the segment with executable code */
574+
if (hdr.p_type == PT_LOAD && hdr.p_flags == (PF_X|PF_R))
575+
{
576+
/* From glibc, elf/dl-load.c:
577+
* c->mapend = ((ph->p_vaddr + ph->p_filesz + GLRO(dl_pagesize) - 1)
578+
* & ~(GLRO(dl_pagesize) - 1));
579+
*
580+
* In glibc, the segment file size is aligned up to the nearest page size and
581+
* added to the virtual address of the segment. We just want the size here.
582+
*/
583+
ulSize = PAGE_ALIGN_UP(hdr.p_filesz);
584+
break;
585+
}
586+
}
531587
#else
532588
#error "BinaryManager::FindBinary() is not implemented on this OS"
533589
#endif

0 commit comments

Comments
 (0)