Skip to content

Add support for compiling against the sdk2013 branch #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 4, 2017
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ srv_check = False

[function]
[[fire_output]]
identifier_linux = _ZN17CBaseEntityOutput10FireOutputE9variant_tP11CBaseEntityS2_f
# identifier_linux = _ZN17CBaseEntityOutput10FireOutputE9variant_tP11CBaseEntityS2_f
identifier_linux = 55 89 E5 57 56 53 81 EC 7C 01 00 00 8B 55 08 8B 75 14
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
arguments_linux = POINTER, POINTER, POINTER, FLOAT
arguments_windows = INT, INT, INT, INT, POINTER, POINTER, POINTER, FLOAT
arguments_windows = INT, INT, INT, INT, POINTER, POINTER, POINTER, FLOAT
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,40 @@
[CEntityFactoryDictionary]
binary = server
srv_check = False
identifier_linux = _ZZ23EntityFactoryDictionaryvE15s_EntityFactory
# identifier_linux = _ZZ23EntityFactoryDictionaryvE15s_EntityFactory
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
identifier_windows = 56 FF 75 08 B9 2A 2A 2A 2A E8 2A 2A 2A 2A 8B C8 C7
offset_windows = 5
level_windows = 1
offset_linux = 17
level = 1

[CGlobalEntityList]
binary = server
identifier_linux = gEntList
srv_check = False
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
# Search the signature of OnCBaseEntityList::AddNonNetworkableEntity(IHandleEntity *)
# Note: The Linux binary does not contain the gEntList pointer in that function!
identifier_windows = 55 8B EC 8B 0D 2A 2A 2A 2A 53
offset_windows = 101
level_windows = 1
srv_check = False
offset_linux = 13
level = 1

[IServer]
binary = bin/engine
identifier_linux = sv
srv_check = False
# identifier_linux = sv
identifier_linux = 55 89 E5 53 83 EC 14 8B 45 0C C7 04 24 2A 2A 2A 2A
identifier_windows = 55 8B EC 56 FF 2A 2A B9 2A 2A 2A 2A E8 2A 2A 2A 2A 8B
offset_windows = 8
level_windows = 1
srv_check = False

offset_linux = 13
level = 1

[CBaseTempEntity]
binary = server
srv_check = False
identifier_linux = _ZN15CBaseTempEntity15s_pTempEntitiesE
# identifier_linux = _ZN15CBaseTempEntity15s_pTempEntitiesE
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
identifier_windows = 89 41 04 A1 2A 2A 2A 2A 89 41 08 89 0D 2A 2A 2A 2A C7
offset_windows = 4
level_windows = 2
level_linux = 1
offset_linux = 20
level = 2
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
'BaseEntityOutput', GameConfigObj(
SP_DATA_PATH / 'entity_output' / 'CBaseEntityOutput.ini'))

_fire_output = getattr(BaseEntityOutput, 'fire_output', None)
try:
_fire_output = getattr(BaseEntityOutput, 'fire_output', None)
except ValueError:
# In case the pointer wasn't found
_fire_output = None

on_entity_output_listener_manager = (
None if _fire_output is None else ListenerManager()
)
Expand Down
62 changes: 59 additions & 3 deletions src/core/modules/memory/memory_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <fcntl.h>
#include <link.h>
#include <sys/mman.h>
extern int PAGE_SIZE;
#define PAGE_ALIGN_UP(x) ((x + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
#endif

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

CPointer* CBinaryFile::FindAddress(object oIdentifier)
{
#ifdef _WIN32
if(CheckClassname(oIdentifier, "bytes"))
return FindSignature(oIdentifier);
#endif

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

#elif defined(__linux__)
ulSize = 0;
// Copied from here. Thanks!
// https://github.com/alliedmodders/sourcemod/blob/237db0504c7a59e394828446af3e8ca3d53ef647/core/logic/MemoryUtils.cpp#L486

Elf32_Ehdr *file;
Elf32_Phdr *phdr;
uint16_t phdrCount;

struct link_map *lm = (struct link_map*) ulAddr;
ulAddr = reinterpret_cast<uintptr_t>(lm->l_addr);
file = reinterpret_cast<Elf32_Ehdr *>(ulAddr);

/* Check ELF magic */
if (memcmp(ELFMAG, file->e_ident, SELFMAG) != 0)
{
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "ELF magic check failed.");
}

/* Check ELF version */
if (file->e_ident[EI_VERSION] != EV_CURRENT)
{
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "ELF version check failed.");
}

/* Check ELF architecture, which is 32-bit/x86 right now
* Should change this for 64-bit if Valve gets their act together
*/
if (file->e_ident[EI_CLASS] != ELFCLASS32 || file->e_machine != EM_386 || file->e_ident[EI_DATA] != ELFDATA2LSB)
{
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "ELF architecture check failed.");
}

/* For our purposes, this must be a dynamic library/shared object */
if (file->e_type != ET_DYN)
{
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Library is not a dynamic or shared object.");
}

phdrCount = file->e_phnum;
phdr = reinterpret_cast<Elf32_Phdr *>(ulAddr + file->e_phoff);

for (uint16_t i = 0; i < phdrCount; i++)
{
Elf32_Phdr &hdr = phdr[i];

/* We only really care about the segment with executable code */
if (hdr.p_type == PT_LOAD && hdr.p_flags == (PF_X|PF_R))
{
/* From glibc, elf/dl-load.c:
* c->mapend = ((ph->p_vaddr + ph->p_filesz + GLRO(dl_pagesize) - 1)
* & ~(GLRO(dl_pagesize) - 1));
*
* In glibc, the segment file size is aligned up to the nearest page size and
* added to the virtual address of the segment. We just want the size here.
*/
ulSize = PAGE_ALIGN_UP(hdr.p_filesz);
break;
}
}
#else
#error "BinaryManager::FindBinary() is not implemented on this OS"
#endif
Expand Down