@@ -56,9 +56,10 @@ extern IVEngineServer* engine;
56
56
// -----------------------------------------------------------------------------
57
57
// BinaryFile class
58
58
// -----------------------------------------------------------------------------
59
- CBinaryFile::CBinaryFile (unsigned long ulAddr , unsigned long ulSize)
59
+ CBinaryFile::CBinaryFile (unsigned long ulModule, unsigned long ulBase , unsigned long ulSize)
60
60
{
61
- m_ulAddr = ulAddr;
61
+ m_ulModule = ulModule;
62
+ m_ulBase = ulBase;
62
63
m_ulSize = ulSize;
63
64
}
64
65
@@ -70,7 +71,7 @@ CPointer* CBinaryFile::FindSignatureRaw(object oSignature)
70
71
71
72
int iLength = len (oSignature);
72
73
73
- unsigned char * base = (unsigned char *) m_ulAddr ;
74
+ unsigned char * base = (unsigned char *) m_ulBase ;
74
75
unsigned char * end = (unsigned char *) (base + m_ulSize - iLength);
75
76
76
77
while (base < end)
@@ -151,7 +152,7 @@ bool CBinaryFile::SearchSigHooked(object oSignature, int iLength, unsigned char*
151
152
CPointer new_ptr = CPointer (pPtr->m_ulAddr + len (oSignature));
152
153
153
154
// Got another match after the first one?
154
- CPointer* pNext = new_ptr.SearchBytes (oSignature, (m_ulAddr + m_ulSize) - new_ptr.m_ulAddr );
155
+ CPointer* pNext = new_ptr.SearchBytes (oSignature, (m_ulBase + m_ulSize) - new_ptr.m_ulAddr );
155
156
bool bIsValid = pNext->IsValid ();
156
157
delete pNext;
157
158
@@ -201,10 +202,10 @@ CPointer* CBinaryFile::FindSignature(object oSignature)
201
202
CPointer* CBinaryFile::FindSymbol (char * szSymbol)
202
203
{
203
204
#ifdef _WIN32
204
- return new CPointer ((unsigned long ) GetProcAddress ((HMODULE) m_ulAddr , szSymbol));
205
+ return new CPointer ((unsigned long ) GetProcAddress ((HMODULE) m_ulModule , szSymbol));
205
206
206
207
#elif defined(__linux__)
207
- void * pResult = dlsym ((void *) m_ulAddr , szSymbol);
208
+ void * pResult = dlsym ((void *) m_ulModule , szSymbol);
208
209
if (pResult)
209
210
return new CPointer ((unsigned long ) pResult);
210
211
@@ -227,7 +228,7 @@ CPointer* CBinaryFile::FindSymbol(char* szSymbol)
227
228
uint16_t section_count;
228
229
uint32_t symbol_count;
229
230
230
- dlmap = (struct link_map *) m_ulAddr ;
231
+ dlmap = (struct link_map *) m_ulModule ;
231
232
symtab_hdr = NULL ;
232
233
strtab_hdr = NULL ;
233
234
@@ -339,31 +340,31 @@ dict CBinaryFile::GetSymbols()
339
340
{
340
341
dict result;
341
342
#ifdef _WIN32
342
- PIMAGE_DOS_HEADER dos_header = (PIMAGE_DOS_HEADER) m_ulAddr ;
343
+ PIMAGE_DOS_HEADER dos_header = (PIMAGE_DOS_HEADER) m_ulModule ;
343
344
if (dos_header->e_magic != IMAGE_DOS_SIGNATURE)
344
345
BOOST_RAISE_EXCEPTION (PyExc_ValueError, " Unable to retrieve DOS header." )
345
346
346
- PIMAGE_NT_HEADERS nt_headers = (PIMAGE_NT_HEADERS) ((BYTE *) m_ulAddr + dos_header->e_lfanew );
347
+ PIMAGE_NT_HEADERS nt_headers = (PIMAGE_NT_HEADERS) ((BYTE *) m_ulModule + dos_header->e_lfanew );
347
348
if (nt_headers->Signature != IMAGE_NT_SIGNATURE)
348
349
BOOST_RAISE_EXCEPTION (PyExc_ValueError, " Unable to retrieve NT headers." )
349
350
350
351
if (nt_headers->OptionalHeader .NumberOfRvaAndSizes <= 0 )
351
352
BOOST_RAISE_EXCEPTION (PyExc_ValueError, " Invalid number of directories in the optional header." )
352
353
353
354
PIMAGE_EXPORT_DIRECTORY exports = (PIMAGE_EXPORT_DIRECTORY) (
354
- (BYTE *) m_ulAddr
355
+ (BYTE *) m_ulModule
355
356
+ nt_headers->OptionalHeader .DataDirectory [IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress );
356
357
357
358
if (exports->AddressOfNames == NULL )
358
359
BOOST_RAISE_EXCEPTION (PyExc_ValueError, " Address of names is NULL." )
359
360
360
- BYTE** symbols = (BYTE**)(m_ulAddr + exports->AddressOfNames );
361
+ BYTE** symbols = (BYTE**)(m_ulModule + exports->AddressOfNames );
361
362
for (DWORD i=0 ; i < exports->NumberOfNames ; i++)
362
363
{
363
- const char * name = (const char *) (m_ulAddr + symbols[i]);
364
+ const char * name = (const char *) (m_ulModule + symbols[i]);
364
365
365
366
// TODO: Don't use GetProcAddress. There is probably a faster way
366
- result[name] = CPointer ((unsigned long ) GetProcAddress ((HMODULE) m_ulAddr , name));
367
+ result[name] = CPointer ((unsigned long ) GetProcAddress ((HMODULE) m_ulModule , name));
367
368
}
368
369
#elif __linux__
369
370
// TODO: Remove duplicated code. See also: FindSymbol()
@@ -379,7 +380,7 @@ dict CBinaryFile::GetSymbols()
379
380
uint16_t section_count;
380
381
uint32_t symbol_count;
381
382
382
- dlmap = (struct link_map *) m_ulAddr ;
383
+ dlmap = (struct link_map *) m_ulModule ;
383
384
symtab_hdr = NULL ;
384
385
strtab_hdr = NULL ;
385
386
@@ -482,21 +483,22 @@ CBinaryFile* CBinaryManager::FindBinary(char* szPath, bool bSrvCheck /* = true *
482
483
}
483
484
#endif
484
485
485
- unsigned long ulAddr = (unsigned long ) dlLoadLibrary (szBinaryPath.data ());
486
+ unsigned long ulModule = (unsigned long ) dlLoadLibrary (szBinaryPath.data ());
487
+ unsigned long ulBase = 0 ;
486
488
#ifdef __linux__
487
- if (!ulAddr )
489
+ if (!ulModule )
488
490
{
489
491
char szGameDir[MAX_PATH_LENGTH];
490
492
engine->GetGameDir (szGameDir, MAX_PATH_LENGTH);
491
493
492
494
// If the previous path failed, try the "bin" folder of the game.
493
495
// This will allow passing e.g. "server" to this function.
494
496
szBinaryPath = std::string (szGameDir) + " /bin/" + szBinaryPath;
495
- ulAddr = (unsigned long ) dlLoadLibrary (szBinaryPath.data ());
497
+ ulModule = (unsigned long ) dlLoadLibrary (szBinaryPath.data ());
496
498
}
497
499
#endif
498
500
499
- if (!ulAddr )
501
+ if (!ulModule )
500
502
{
501
503
szBinaryPath = " Unable to find " + szBinaryPath;
502
504
#ifdef _WIN32
@@ -510,20 +512,21 @@ CBinaryFile* CBinaryManager::FindBinary(char* szPath, bool bSrvCheck /* = true *
510
512
for (std::list<CBinaryFile *>::iterator iter=m_Binaries.begin (); iter != m_Binaries.end (); ++iter)
511
513
{
512
514
CBinaryFile* binary = *iter;
513
- if (binary->m_ulAddr == ulAddr )
515
+ if (binary->m_ulModule == ulModule )
514
516
{
515
517
// We don't need to open it several times
516
- dlFreeLibrary ((DLLib *) ulAddr );
518
+ dlFreeLibrary ((DLLib *) ulModule );
517
519
return binary;
518
520
}
519
521
}
520
522
521
523
unsigned long ulSize;
522
524
523
525
#ifdef _WIN32
524
- IMAGE_DOS_HEADER* dos = (IMAGE_DOS_HEADER *) ulAddr ;
526
+ IMAGE_DOS_HEADER* dos = (IMAGE_DOS_HEADER *) ulModule ;
525
527
IMAGE_NT_HEADERS* nt = (IMAGE_NT_HEADERS *) ((BYTE *) dos + dos->e_lfanew );
526
528
ulSize = nt->OptionalHeader .SizeOfImage ;
529
+ ulBase = ulModule;
527
530
528
531
#elif defined(__linux__)
529
532
// Copied from here. Thanks!
@@ -533,9 +536,9 @@ CBinaryFile* CBinaryManager::FindBinary(char* szPath, bool bSrvCheck /* = true *
533
536
Elf32_Phdr *phdr;
534
537
uint16_t phdrCount;
535
538
536
- struct link_map *lm = (struct link_map *) ulAddr ;
537
- ulAddr = reinterpret_cast <uintptr_t >(lm->l_addr );
538
- file = reinterpret_cast <Elf32_Ehdr *>(ulAddr );
539
+ struct link_map *lm = (struct link_map *) ulModule ;
540
+ ulBase = reinterpret_cast <uintptr_t >(lm->l_addr );
541
+ file = reinterpret_cast <Elf32_Ehdr *>(ulBase );
539
542
540
543
/* Check ELF magic */
541
544
if (memcmp (ELFMAG, file->e_ident , SELFMAG) != 0 )
@@ -564,7 +567,7 @@ CBinaryFile* CBinaryManager::FindBinary(char* szPath, bool bSrvCheck /* = true *
564
567
}
565
568
566
569
phdrCount = file->e_phnum ;
567
- phdr = reinterpret_cast <Elf32_Phdr *>(ulAddr + file->e_phoff );
570
+ phdr = reinterpret_cast <Elf32_Phdr *>(ulBase + file->e_phoff );
568
571
569
572
for (uint16_t i = 0 ; i < phdrCount; i++)
570
573
{
@@ -589,7 +592,7 @@ CBinaryFile* CBinaryManager::FindBinary(char* szPath, bool bSrvCheck /* = true *
589
592
#endif
590
593
591
594
// Create a new Binary object and add it to the list
592
- CBinaryFile* binary = new CBinaryFile (ulAddr , ulSize);
595
+ CBinaryFile* binary = new CBinaryFile (ulModule, ulBase , ulSize);
593
596
m_Binaries.push_front (binary);
594
597
return binary;
595
598
}
0 commit comments