diff -r 25b41f83458f -r fa27b9403af3 metamod/engineinfo.cpp --- a/metamod/engineinfo.cpp Mon Apr 17 12:28:51 2006 +0000 +++ b/metamod/engineinfo.cpp Mon Apr 17 12:35:34 2006 +0000 @@ -25,17 +25,8 @@ #include // printf() #include "engineinfo.h" // me - -//+TBR -#ifdef MM_DEBUG -#include "log_meta.h" // META_LOG() +#include "log_meta.h" // META_DEV() -//#define FLDBG_PRINTF(s) dbg_logprintf s -#define FLDBG_PRINTF(s) META_LOG s -//#define FLDBG_PRINTF(s) printf s -//#define FLDBG_PRINTF(s) -#endif -//-TBR // Current mask for checking engine function addresses // in VAC protected engine dlls on Win32. This is gonna fail @@ -64,18 +55,8 @@ if ( 0 != strcmp(pC, "swds.dll") ) return false; } -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF( ("Locating module %s.", pC) ); -#endif -//-TBR HMODULE hModule = GetModuleHandle( pC ); if ( NULL == hModule ) { -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF( ("Could not get handle to module %s.", pC) ); -#endif -//-TBR return false; } @@ -87,21 +68,11 @@ m_type[size++] = *pC++; } m_type[size] = '\0'; -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF(( "Found engine dll name %s.", m_type )); -#endif -//-TBR #else /* _WIN32 */ const char* pType; -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF(( "Checking for engine name in '%s'", _pName )); -#endif -//-TBR size = strlen( _pName ); if ( size < 11 ) { @@ -144,11 +115,6 @@ } m_type[size] = '\0'; -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF(( "Found engine dso name. Architecture is %s.", m_type )); -#endif -//-TBR #endif /* _WIN32 */ @@ -184,39 +150,14 @@ // Check if we find a DOS header -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF( ("Checking for DOS header at address %p.", hModule) ); -#endif -//-TBR pDosHeader = (PIMAGE_DOS_HEADER)hModule; if ( pDosHeader->e_magic != IMAGE_DOS_SIGNATURE ) { -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF( ("DOS header magic doesn't match: 0x%x.", pDosHeader->e_magic) ); -#endif -//-TBR return INVALID_DOS_SIGN; } // Check if we find a PE header -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF( ("DOS header points to NT header at 0x%lx.", pDosHeader->e_lfanew) ); -#endif -//-TBR pNTHeader = (PIMAGE_NT_HEADERS)(pBaseAddr + pDosHeader->e_lfanew); -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF( ("Checking for NT header at %p.", pNTHeader) ); -#endif -//-TBR if ( pNTHeader->Signature != IMAGE_NT_SIGNATURE ) { -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF( ("NT header signature doesn't match: 0x%lx.", pNTHeader->Signature) ); -#endif -//-TBR return INVALID_NT_SIGN; } @@ -227,11 +168,6 @@ int EngineInfo::vac_pe_approx( enginefuncs_t* _pFuncs ) { -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF( ("==DEBUG==> Approximating engine functions address range in VAC dll from 0x%p.", _pFuncs) ); -#endif -//-TBR if ( NULL == _pFuncs ) return INVALID_ARG; @@ -260,12 +196,10 @@ } if ( invals > 0 ) { -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF( ("==DEBUG==> Found %u functions out of range 0x%08lx.", invals, c_VacDllEngineFuncsRangeMark) ); - FLDBG_PRINTF( (" Unable to determine valid function address range.") ); -#endif -//-TBR + META_DEV( "Found %d engine functions out of range 0x%08lx. " + "Unable to determine valid engine code address range.", + invals, c_VacDllEngineFuncsRangeMark ); + strncpy( m_type, "vacdll+?", c_EngineInfo__typeLen ); m_state = STATE_INVALID; return STATE_INVALID; @@ -289,19 +223,6 @@ m_state = STATE_VALID; -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF(( "==DEBUG==> Setting code range:" )); - FLDBG_PRINTF(( " pNThdr at %p, BaseOfCode = 0x%lx, end = 0x%lx, SizeOfCode = %ld 0x%lx", - _pNThdr, _pNThdr->OptionalHeader.BaseOfCode, - _pNThdr->OptionalHeader.BaseOfCode + _pNThdr->OptionalHeader.SizeOfCode, - _pNThdr->OptionalHeader.SizeOfCode, - _pNThdr->OptionalHeader.SizeOfCode - )); - FLDBG_PRINTF(( " start address = 0x%p, end address = 0x%p", - m_codeStart, m_codeEnd )); -#endif -//-TBR } @@ -334,11 +255,6 @@ // Let's find the program header for the segment that includes // the text section and return it. -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF(("%d segments", pEhdr->e_phnum)); -#endif -//-TBR pPhdr = (ElfW(Phdr) *) ((char *) pEhdr + pEhdr->e_phoff); for ( int i = 0; i < pEhdr->e_phnum; i++, pPhdr++ ) { @@ -348,24 +264,6 @@ // The text section gets loaded and has read and // execute flags set. So this must be it. -//+TBR -#ifdef MM_DEBUG -#ifdef __amd64__ - FLDBG_PRINTF(("\t\t header %2d: address=%10p size=%8ld type=%d flags=", i, - (void *) (pEhdr + pPhdr->p_vaddr), - pPhdr->p_memsz, (int)(pPhdr->p_type)) ); -#else - FLDBG_PRINTF(("\t\t header %2d: address=%10p size=%8d type=%d flags=", i, - (void *) (pEhdr + pPhdr->p_vaddr), - pPhdr->p_memsz, (int)(pPhdr->p_type)) ); -#endif - FLDBG_PRINTF(("%c%c%c", - pPhdr->p_flags & PF_R ? 'R' : ' ', - pPhdr->p_flags & PF_W ? 'W' : ' ', - pPhdr->p_flags & PF_X ? 'X' : ' ' )); - FLDBG_PRINTF(( "" )); -#endif -//-TBR set_code_range( pEhdr, pPhdr ); return 0; } @@ -383,32 +281,12 @@ { Dl_info info; -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF(( "Trying to find Program Header via dladdr." )); - FLDBG_PRINTF(( "Looking up dlinfo for %p", _pMem )); -#endif -//-TBR if ( 0 != dladdr(_pMem, &info) ) { -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF(( "Found info: " )); - FLDBG_PRINTF(( " name: %s", info.dli_fname )); - FLDBG_PRINTF(( " base: %p", info.dli_fbase )); -#endif -//-TBR // Check if this is the engine module if ( check_for_engine_module(info.dli_fname) ) { return phdr_elfhdr( info.dli_fbase ); } } -//+TBR -#ifdef MM_DEBUG - else { - FLDBG_PRINTF(( "No info found." )); - } -#endif -//-TBR return NOTFOUND; } @@ -420,11 +298,6 @@ struct r_debug* pr_debug; struct link_map* pMap; -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF(( "Trying to find Program Header via r_debug struct." )); -#endif -//-TBR // Search if we have a DT_DEBUG symbol in our DYNAMIC segment, which // ought to be set to the r_debug structure's address. @@ -436,43 +309,15 @@ } if ( DT_NULL == pDyn->d_tag ) { -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF(( "Unable to find my DT_DEBUG symbol." )); -#endif -//-TBR } else if ( NULL == pr_debug ) { -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF(( "DT_DEBUG found but is NULL." )); -#endif -//-TBR } else { -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF(( "Found DT_DEBUG symbol." )); - FLDBG_PRINTF(( "r_debug is at %p", pr_debug )); -#endif -//-TBR pMap = pr_debug->r_map; // Walk to the start of the list while ( pMap->l_prev != NULL ) pMap = pMap->l_prev; do { -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF(( "link map is at %p", pMap )); - -#ifdef __amd64__ - FLDBG_PRINTF(( "base addr = %lx", pMap->l_addr )); -#else - FLDBG_PRINTF(( "base addr = %x", pMap->l_addr )); -#endif - FLDBG_PRINTF(( "name is %s\n", pMap->l_name )); -#endif -//-TBR if ( check_for_engine_module(pMap->l_name) ) { return phdr_elfhdr( (void*)pMap->l_addr ); } @@ -492,21 +337,6 @@ m_codeEnd = pBase + _pPhdr->p_vaddr + _pPhdr->p_memsz; m_state = STATE_VALID; - -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF(( "==DEBUG==> Setting code range:" )); -#ifdef __amd64__ - FLDBG_PRINTF(( " pPhdr at %p, p_vaddr = 0x%lx, vend = 0x%lx, p_memsz = %ld", - _pPhdr, _pPhdr->p_vaddr, _pPhdr->p_vaddr + _pPhdr->p_memsz, _pPhdr->p_memsz )); -#else - FLDBG_PRINTF(( " pPhdr at %p, p_vaddr = 0x%x, vend = 0x%x, p_memsz = %d", - _pPhdr, _pPhdr->p_vaddr, _pPhdr->p_vaddr + _pPhdr->p_memsz, _pPhdr->p_memsz )); -#endif - FLDBG_PRINTF(( " start address = %p, end address = %p", - m_codeStart, m_codeEnd )); -#endif -//-TBR } @@ -519,19 +349,8 @@ // Have to do this only once. if ( NULL != m_codeStart ) { -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF(( "==DEBUG==> ---------- Engine info already initialised --" )); - FLDBG_PRINTF(( "==DEBUG==> codeStart: %p codeEnd: %p", m_codeStart, m_codeEnd )); -#endif -//-TBR return 0; } -//+TBR -#ifdef MM_DEBUG - FLDBG_PRINTF(( "==DEBUG==> ---------- Initialising engine info --" )); -#endif -//-TBR #ifdef _WIN32 @@ -558,16 +377,14 @@ } #endif /* _WIN32 */ -//+TBR -#ifdef MM_DEBUG + if ( 0 != ret ) { - FLDBG_PRINTF(( "==DEBUG==> Unable to determine functions address range!" )); + META_DEV( "Unable to determine engine code address range!" ); } else { - FLDBG_PRINTF(( "==DEBUG==> codeStart: %p codeEnd: %p", m_codeStart, m_codeEnd )); + META_DEV( "Set engine code range: start address = %p, end address = %p", + m_codeStart, m_codeEnd ); } -#endif -//-TBR return 0; }