-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Repo restructure, PE header parsing, fix Linux DynLibs
- Loading branch information
Showing
23 changed files
with
1,230 additions
and
549 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
py ../configure.py --mms-path "C:/Users/johnm/Documents/GitHub/metamod-source" --sm-path "C:/Users/johnm/Documents/GitHub/sourcemod" --sdks none --enable-optimize | ||
ambuild | ||
@echo off | ||
SET arg=%1 | ||
|
||
:: Change these if building yourself | ||
SET mms_path="C:/Users/johnm/Documents/GitHub/metamod-source" | ||
SET sm_path="C:/Users/johnm/Documents/GitHub/sourcemod" | ||
|
||
:: Allow passing a debug flag for debug builds | ||
SET pyflag=--enable-optimize | ||
IF "%arg%"=="--debug" SET pyflag=--enable-debug | ||
|
||
py ../configure.py --mms-path %mms_path% --sm-path %sm_path% --sdks none %pyflag% | ||
ambuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
python3 ../configure.py --mms-path "/mnt/c/Users/johnm/Documents/GitHub/metamod-source" --sm-path "/mnt/c/Users/johnm/Documents/GitHub/sourcemod" --enable-optimize | ||
# Change these if building yourself | ||
mms_path="/mnt/c/Users/johnm/Documents/GitHub/metamod-source" | ||
sm_path="/mnt/c/Users/johnm/Documents/GitHub/sourcemod" | ||
|
||
py_arg="--enable-optimize" | ||
if [ "$1" == "--debug" ]; then | ||
py_arg="--enable-debug" | ||
fi | ||
|
||
python3 ../configure.py --mms-path $mms_path --sm-path $sm_path $py_arg | ||
ambuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
docker build -f ../Dockerfile -t sm-mem ../ | ||
dockerflag="" | ||
if [ "$1" == "--debug" ]; then | ||
dockerflag="--build-arg BUILD_MODE=debug" | ||
fi | ||
|
||
docker build $dockerflag -f ../Dockerfile -t sm-mem ../ | ||
container_id=$(docker create sm-mem) | ||
docker cp "${container_id}:/project/package/package" . | ||
docker rm ${container_id} | ||
docker image prune -f | ||
docker image prune -f |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#include "extension.h" | ||
#include "dynlib.h" | ||
|
||
#ifdef PLATFORM_WINDOWS | ||
#include <Windows.h> | ||
#endif | ||
|
||
#include <sstream> | ||
#include <fstream> | ||
|
||
// https://stackoverflow.com/questions/874134/find-out-if-string-ends-with-another-string-in-c | ||
static bool endswith(const std::string &str, const char *suffix, unsigned suffixLen) | ||
{ | ||
return str.size() >= suffixLen && str.compare(str.size() - suffixLen, suffixLen, suffix, suffixLen) == 0; | ||
} | ||
|
||
DynLib::DynLib(const std::string &name) | ||
: m_Name(name) | ||
{ | ||
#ifdef PLATFORM_WINDOWS | ||
m_Handle = LoadLibraryA(m_Name.c_str()); | ||
if (m_Handle == nullptr) | ||
{ | ||
// Try and fix up the name | ||
if (!endswith(m_Name, ".dll", 4)) | ||
{ | ||
m_Name += ".dll"; | ||
m_Handle = LoadLibraryA(m_Name.c_str()); | ||
} | ||
} | ||
|
||
m_BaseAddress = (void *)m_Handle; | ||
#elif defined PLATFORM_POSIX | ||
m_Handle = dlopen(m_Name.c_str(), RTLD_LAZY); | ||
if (m_Handle == nullptr) | ||
{ | ||
// Try and fix up the name | ||
if (!endswith(m_Name, ".so", 3)) | ||
{ | ||
m_Name += ".so"; | ||
m_Handle = dlopen(m_Name.c_str(), RTLD_LAZY); | ||
} | ||
} | ||
|
||
if (m_Handle != nullptr) | ||
{ | ||
m_BaseAddress = LoadBaseAddress(m_Name); | ||
// Name is not full path | ||
if (m_BaseAddress == nullptr) | ||
{ | ||
char abspath[260]; | ||
char *rpath = realpath(m_Name.c_str(), abspath); | ||
if (rpath != nullptr) | ||
{ | ||
m_Name = rpath; | ||
m_BaseAddress = LoadBaseAddress(m_Name); | ||
} | ||
} | ||
} | ||
#endif | ||
} | ||
|
||
DynLib::~DynLib() | ||
{ | ||
if (m_Handle != nullptr) | ||
{ | ||
#ifdef PLATFORM_WINDOWS | ||
FreeLibrary(m_Handle); | ||
#elif defined PLATFORM_POSIX | ||
dlclose(m_Handle); | ||
#endif | ||
} | ||
} | ||
|
||
void *DynLib::ResolveSymbol(const char *sym) | ||
{ | ||
return memutils->ResolveSymbol((void *)m_Handle, sym); | ||
} | ||
|
||
void *DynLib::FindPattern(const char *pattern, size_t len) | ||
{ | ||
return memutils->FindPattern(m_BaseAddress, pattern, len); | ||
} | ||
|
||
std::string DynLib::ErrorMessage() | ||
{ | ||
#ifdef PLATFORM_WINDOWS | ||
std::stringstream ss; | ||
ss << std::hex << GetLastError(); | ||
return "0x" + ss.str(); | ||
#elif defined PLATFORM_POSIX | ||
const char *err = dlerror(); | ||
return err ? err : ""; | ||
#endif | ||
} | ||
|
||
void *DynLib::LoadBaseAddress(const std::string &name) | ||
{ | ||
std::ifstream maps("/proc/self/maps"); | ||
std::string line; | ||
void *startAddr = nullptr; | ||
while (std::getline(maps, line)) | ||
{ | ||
if (line.find(name) != std::string::npos) | ||
{ | ||
std::stringstream ss(line); | ||
char dash; | ||
ss >> std::hex >> startAddr >> dash; | ||
break; | ||
} | ||
} | ||
return startAddr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.