mirror of
https://github.com/alliedmodders/metamod-source.git
synced 2025-01-19 08:52:34 +01:00
Replace fscanf with faster parsing #2
This commit is contained in:
parent
62f21ea058
commit
f2d9d3e9e5
@ -262,9 +262,10 @@ namespace SourceHook
|
||||
{
|
||||
#if SH_SYS == SH_SYS_LINUX
|
||||
// On linux, first check /proc/self/maps
|
||||
long lower = reinterpret_cast<long>(addr);
|
||||
long upper = lower + len;
|
||||
unsigned long lower = reinterpret_cast<unsigned long>(addr);
|
||||
unsigned long upper = lower + len;
|
||||
|
||||
bool bFound = false;
|
||||
FILE *pF = fopen("/proc/self/maps", "r");
|
||||
if (pF)
|
||||
{
|
||||
@ -272,27 +273,23 @@ namespace SourceHook
|
||||
// Format:
|
||||
// lower upper prot stuff path
|
||||
// 08048000-0804c000 r-xp 00000000 03:03 1010107 /bin/cat
|
||||
long rlower, rupper;
|
||||
while (fscanf(pF, "%lx-%lx", &rlower, &rupper) != EOF)
|
||||
{
|
||||
unsigned long rlower, rupper;
|
||||
char *buffer = NULL;
|
||||
size_t bufsize = 0;
|
||||
while (getline(&buffer, &bufsize, pF) != -1) {
|
||||
char *addr_split;
|
||||
rlower = strtoul(buffer, &addr_split, 16);
|
||||
rupper = strtoul(&addr_split[1], NULL, 16);
|
||||
// Check whether we're IN THERE!
|
||||
if (lower >= rlower && upper <= rupper)
|
||||
{
|
||||
fclose(pF);
|
||||
return true;
|
||||
}
|
||||
// Read to end of line
|
||||
int c;
|
||||
while ((c = fgetc(pF)) != '\n')
|
||||
{
|
||||
if (c == EOF)
|
||||
bFound = true;
|
||||
break;
|
||||
}
|
||||
if (c == EOF)
|
||||
break;
|
||||
}
|
||||
free(buffer);
|
||||
fclose(pF);
|
||||
return false;
|
||||
return bFound;
|
||||
}
|
||||
pF = fopen("/proc/curproc/map", "r");
|
||||
if (pF)
|
||||
|
Loading…
x
Reference in New Issue
Block a user