@@ -202,6 +202,10 @@ CPointer* CBinaryFile::FindSymbol(char* szSymbol)
202
202
return new CPointer ((unsigned long ) GetProcAddress ((HMODULE) m_ulAddr, szSymbol));
203
203
204
204
#elif defined(__linux__)
205
+ void * pResult = dlsym ((void *) m_ulAddr, szSymbol);
206
+ if (pResult)
207
+ return new CPointer ((unsigned long ) pResult);
208
+
205
209
// -----------------------------------------
206
210
// We need to use mmap now that VALVe has
207
211
// made them all private!
@@ -466,14 +470,16 @@ bool str_ends_with(const char *szString, const char *szSuffix)
466
470
return strncmp (szString + stringlen - suffixlen, szSuffix, suffixlen) == 0 ;
467
471
}
468
472
469
- CBinaryFile* CBinaryManager::FindBinary (char * szPath, bool bSrvCheck /* = true */ )
473
+ CBinaryFile* CBinaryManager::FindBinary (char * szPath, bool bSrvCheck /* = true */ , bool bCheckExtension /* = true */ )
470
474
{
471
475
std::string szBinaryPath = szPath;
472
476
#ifdef __linux__
473
- if (bSrvCheck && !str_ends_with (szBinaryPath.data (), " _srv" ) && !str_ends_with (szBinaryPath.data (), " .so" ))
474
- szBinaryPath += " _srv.so" ;
475
- else if (!str_ends_with (szBinaryPath.data (), " .so" ))
476
- szBinaryPath += " .so" ;
477
+ if (bCheckExtension) {
478
+ if (bSrvCheck && !str_ends_with (szBinaryPath.data (), " _srv" ) && !str_ends_with (szBinaryPath.data (), " .so" ))
479
+ szBinaryPath += " _srv.so" ;
480
+ else if (!str_ends_with (szBinaryPath.data (), " .so" ))
481
+ szBinaryPath += " .so" ;
482
+ }
477
483
#endif
478
484
479
485
unsigned long ulAddr = (unsigned long ) dlLoadLibrary (szBinaryPath.data ());
@@ -494,7 +500,7 @@ CBinaryFile* CBinaryManager::FindBinary(char* szPath, bool bSrvCheck /* = true *
494
500
{
495
501
szBinaryPath = " Unable to find " + szBinaryPath;
496
502
#ifdef _WIN32
497
- if (!str_ends_with (szBinaryPath.data (), " .dll" ))
503
+ if (bCheckExtension && !str_ends_with (szBinaryPath.data (), " .dll" ))
498
504
szBinaryPath += " .dll" ;
499
505
#endif
500
506
BOOST_RAISE_EXCEPTION (PyExc_IOError, szBinaryPath.data ())
@@ -520,15 +526,7 @@ CBinaryFile* CBinaryManager::FindBinary(char* szPath, bool bSrvCheck /* = true *
520
526
ulSize = nt->OptionalHeader .SizeOfImage ;
521
527
522
528
#elif defined(__linux__)
523
- // TODO: Retrieve whole size
524
- struct stat buf;
525
- if (stat (szBinaryPath.data (), &buf) == -1 )
526
- {
527
- dlFreeLibrary ((DLLib *) ulAddr);
528
- szBinaryPath = " Unable to retrieve the binary size for " + szBinaryPath;
529
- BOOST_RAISE_EXCEPTION (PyExc_RuntimeError, szBinaryPath.data ())
530
- }
531
- ulSize = buf.st_size ;
529
+ ulSize = 0 ;
532
530
533
531
#else
534
532
#error "BinaryManager::FindBinary() is not implemented on this OS"
@@ -543,7 +541,7 @@ CBinaryFile* CBinaryManager::FindBinary(char* szPath, bool bSrvCheck /* = true *
543
541
// -----------------------------------------------------------------------------
544
542
// Functions
545
543
// -----------------------------------------------------------------------------
546
- CBinaryFile* FindBinary (char * szPath, bool bSrvCheck /* = true */ )
544
+ CBinaryFile* FindBinary (char * szPath, bool bSrvCheck /* = true */ , bool bCheckExtension /* = true */ )
547
545
{
548
- return s_pBinaryManager->FindBinary (szPath, bSrvCheck);
546
+ return s_pBinaryManager->FindBinary (szPath, bSrvCheck, bCheckExtension );
549
547
}
0 commit comments