OvidiuS,
PHP Code:
#include <stdint.h>
PHP Code:
#ifdef __linux__
#ifdef __amd64__ // Lin64
#define GAMEDLL_NAME "cs_amd64.so"
#else // Lin32
#define GAMEDLL_NAME "cs_i386.so"
#endif
#else // Windows
#define GAMEDLL_NAME "mp.dll"
#endif
// Define memory address type
#ifdef __amd64__
typedef uint64_t maddress;
#else
typedef uint32_t maddress;
#endif
maddress gameDllAddress;
#define GETREALADDR( Address ) (gameDllAddress + Address)
Meta_Attach:
PHP Code:
#ifdef __linux__
if (!UTIL_GetLinuxMemoryMap(&mapsFile, &errNum))
{
print_srvconsole("Error reading memory maps file. Natives not available. (file \"%s\") (error \"%s\")", mapsFile, strerror(errNum));
return(FALSE);
}
#else
gameDllAddress = (maddress)LoadLibrary(GAMEDLL_NAME);
if (!gameDllAddress)
{
print_srvconsole("Error getting handle to game DLL. Natives not available. (file \"%s\")", GAMEDLL_NAME);
return(FALSE);
}
#endif
_____________________________________________ _____________________________________________ ______________________________________
PHP Code:
#ifdef __linux__
/* Function to read from memory map file to get server binary addresses.
Returns true if file read successfully.
Why must Linux be so difficult? Bah! This whole function was quite a pain to write. */
bool UTIL_GetLinuxMemoryMap (char **file, int *err) {
// Open and read maps file
char *mapsfile = new char[MAX_PATH];
FILE *fp;
sprintf(mapsfile, "/proc/%d/maps", getpid());
fp = fopen(mapsfile, "r");
*file = mapsfile;
if (!fp) {
err = &errno;
fclose(fp);
return false;
}
char buffer[256], perm[5], dev[6], mapname[PATH_MAX];
unsigned long begin, end, inode, offset;
char serverBinCount = 0;
while (!feof(fp)) {
if (serverBinCount == 1) {
gameDllAddress = begin;
} else if (serverBinCount == 2) {
dataSectionStart = begin;
dataSectionOffset = offset;
break;
}
if (fgets(buffer, sizeof(buffer), fp) == NULL) break;
mapname[0] = '\0';
sscanf(buffer, "%lx-%lx %4s %lx %5s %ld %s", &begin, &end, perm, &offset, dev, &inode, mapname);
char* token = strtok(mapname, "/");
while (token != NULL) {
if (strcmp(token, GAMEDLL_NAME) == 0) {
serverBinCount++;
break;
}
token = strtok(NULL, "/");
}
}
if (serverBinCount == 0) {
err = &errno;
fclose(fp);
return false;
}
fclose(fp);
return true;
}
#endif
__________________