1.1 --- a/metamod/engineinfo.cpp Mon Apr 17 12:28:51 2006 +0000
1.2 +++ b/metamod/engineinfo.cpp Mon Apr 17 12:35:34 2006 +0000
1.3 @@ -25,17 +25,8 @@
1.4 #include <stdio.h> // printf()
1.5
1.6 #include "engineinfo.h" // me
1.7 -
1.8 -//+TBR
1.9 -#ifdef MM_DEBUG
1.10 -#include "log_meta.h" // META_LOG()
1.11 +#include "log_meta.h" // META_DEV()
1.12
1.13 -//#define FLDBG_PRINTF(s) dbg_logprintf s
1.14 -#define FLDBG_PRINTF(s) META_LOG s
1.15 -//#define FLDBG_PRINTF(s) printf s
1.16 -//#define FLDBG_PRINTF(s)
1.17 -#endif
1.18 -//-TBR
1.19
1.20 // Current mask for checking engine function addresses
1.21 // in VAC protected engine dlls on Win32. This is gonna fail
1.22 @@ -64,18 +55,8 @@
1.23 if ( 0 != strcmp(pC, "swds.dll") ) return false;
1.24 }
1.25
1.26 -//+TBR
1.27 -#ifdef MM_DEBUG
1.28 - FLDBG_PRINTF( ("Locating module %s.", pC) );
1.29 -#endif
1.30 -//-TBR
1.31 HMODULE hModule = GetModuleHandle( pC );
1.32 if ( NULL == hModule ) {
1.33 -//+TBR
1.34 -#ifdef MM_DEBUG
1.35 - FLDBG_PRINTF( ("Could not get handle to module %s.", pC) );
1.36 -#endif
1.37 -//-TBR
1.38 return false;
1.39 }
1.40
1.41 @@ -87,21 +68,11 @@
1.42 m_type[size++] = *pC++;
1.43 }
1.44 m_type[size] = '\0';
1.45 -//+TBR
1.46 -#ifdef MM_DEBUG
1.47 - FLDBG_PRINTF(( "Found engine dll name %s.", m_type ));
1.48 -#endif
1.49 -//-TBR
1.50
1.51 #else /* _WIN32 */
1.52
1.53 const char* pType;
1.54
1.55 -//+TBR
1.56 -#ifdef MM_DEBUG
1.57 - FLDBG_PRINTF(( "Checking for engine name in '%s'", _pName ));
1.58 -#endif
1.59 -//-TBR
1.60
1.61 size = strlen( _pName );
1.62 if ( size < 11 ) {
1.63 @@ -144,11 +115,6 @@
1.64 }
1.65 m_type[size] = '\0';
1.66
1.67 -//+TBR
1.68 -#ifdef MM_DEBUG
1.69 - FLDBG_PRINTF(( "Found engine dso name. Architecture is %s.", m_type ));
1.70 -#endif
1.71 -//-TBR
1.72
1.73 #endif /* _WIN32 */
1.74
1.75 @@ -184,39 +150,14 @@
1.76
1.77
1.78 // Check if we find a DOS header
1.79 -//+TBR
1.80 -#ifdef MM_DEBUG
1.81 - FLDBG_PRINTF( ("Checking for DOS header at address %p.", hModule) );
1.82 -#endif
1.83 -//-TBR
1.84 pDosHeader = (PIMAGE_DOS_HEADER)hModule;
1.85 if ( pDosHeader->e_magic != IMAGE_DOS_SIGNATURE ) {
1.86 -//+TBR
1.87 -#ifdef MM_DEBUG
1.88 - FLDBG_PRINTF( ("DOS header magic doesn't match: 0x%x.", pDosHeader->e_magic) );
1.89 -#endif
1.90 -//-TBR
1.91 return INVALID_DOS_SIGN;
1.92 }
1.93
1.94 // Check if we find a PE header
1.95 -//+TBR
1.96 -#ifdef MM_DEBUG
1.97 - FLDBG_PRINTF( ("DOS header points to NT header at 0x%lx.", pDosHeader->e_lfanew) );
1.98 -#endif
1.99 -//-TBR
1.100 pNTHeader = (PIMAGE_NT_HEADERS)(pBaseAddr + pDosHeader->e_lfanew);
1.101 -//+TBR
1.102 -#ifdef MM_DEBUG
1.103 - FLDBG_PRINTF( ("Checking for NT header at %p.", pNTHeader) );
1.104 -#endif
1.105 -//-TBR
1.106 if ( pNTHeader->Signature != IMAGE_NT_SIGNATURE ) {
1.107 -//+TBR
1.108 -#ifdef MM_DEBUG
1.109 - FLDBG_PRINTF( ("NT header signature doesn't match: 0x%lx.", pNTHeader->Signature) );
1.110 -#endif
1.111 -//-TBR
1.112 return INVALID_NT_SIGN;
1.113 }
1.114
1.115 @@ -227,11 +168,6 @@
1.116
1.117 int EngineInfo::vac_pe_approx( enginefuncs_t* _pFuncs )
1.118 {
1.119 -//+TBR
1.120 -#ifdef MM_DEBUG
1.121 - FLDBG_PRINTF( ("==DEBUG==> Approximating engine functions address range in VAC dll from 0x%p.", _pFuncs) );
1.122 -#endif
1.123 -//-TBR
1.124
1.125 if ( NULL == _pFuncs ) return INVALID_ARG;
1.126
1.127 @@ -260,12 +196,10 @@
1.128 }
1.129
1.130 if ( invals > 0 ) {
1.131 -//+TBR
1.132 -#ifdef MM_DEBUG
1.133 - FLDBG_PRINTF( ("==DEBUG==> Found %u functions out of range 0x%08lx.", invals, c_VacDllEngineFuncsRangeMark) );
1.134 - FLDBG_PRINTF( (" Unable to determine valid function address range.") );
1.135 -#endif
1.136 -//-TBR
1.137 + META_DEV( "Found %d engine functions out of range 0x%08lx. "
1.138 + "Unable to determine valid engine code address range.",
1.139 + invals, c_VacDllEngineFuncsRangeMark );
1.140 +
1.141 strncpy( m_type, "vacdll+?", c_EngineInfo__typeLen );
1.142 m_state = STATE_INVALID;
1.143 return STATE_INVALID;
1.144 @@ -289,19 +223,6 @@
1.145
1.146 m_state = STATE_VALID;
1.147
1.148 -//+TBR
1.149 -#ifdef MM_DEBUG
1.150 - FLDBG_PRINTF(( "==DEBUG==> Setting code range:" ));
1.151 - FLDBG_PRINTF(( " pNThdr at %p, BaseOfCode = 0x%lx, end = 0x%lx, SizeOfCode = %ld 0x%lx",
1.152 - _pNThdr, _pNThdr->OptionalHeader.BaseOfCode,
1.153 - _pNThdr->OptionalHeader.BaseOfCode + _pNThdr->OptionalHeader.SizeOfCode,
1.154 - _pNThdr->OptionalHeader.SizeOfCode,
1.155 - _pNThdr->OptionalHeader.SizeOfCode
1.156 - ));
1.157 - FLDBG_PRINTF(( " start address = 0x%p, end address = 0x%p",
1.158 - m_codeStart, m_codeEnd ));
1.159 -#endif
1.160 -//-TBR
1.161 }
1.162
1.163
1.164 @@ -334,11 +255,6 @@
1.165 // Let's find the program header for the segment that includes
1.166 // the text section and return it.
1.167
1.168 -//+TBR
1.169 -#ifdef MM_DEBUG
1.170 - FLDBG_PRINTF(("%d segments", pEhdr->e_phnum));
1.171 -#endif
1.172 -//-TBR
1.173 pPhdr = (ElfW(Phdr) *) ((char *) pEhdr + pEhdr->e_phoff);
1.174 for ( int i = 0; i < pEhdr->e_phnum; i++, pPhdr++ ) {
1.175
1.176 @@ -348,24 +264,6 @@
1.177
1.178 // The text section gets loaded and has read and
1.179 // execute flags set. So this must be it.
1.180 -//+TBR
1.181 -#ifdef MM_DEBUG
1.182 -#ifdef __amd64__
1.183 - FLDBG_PRINTF(("\t\t header %2d: address=%10p size=%8ld type=%d flags=", i,
1.184 - (void *) (pEhdr + pPhdr->p_vaddr),
1.185 - pPhdr->p_memsz, (int)(pPhdr->p_type)) );
1.186 -#else
1.187 - FLDBG_PRINTF(("\t\t header %2d: address=%10p size=%8d type=%d flags=", i,
1.188 - (void *) (pEhdr + pPhdr->p_vaddr),
1.189 - pPhdr->p_memsz, (int)(pPhdr->p_type)) );
1.190 -#endif
1.191 - FLDBG_PRINTF(("%c%c%c",
1.192 - pPhdr->p_flags & PF_R ? 'R' : ' ',
1.193 - pPhdr->p_flags & PF_W ? 'W' : ' ',
1.194 - pPhdr->p_flags & PF_X ? 'X' : ' ' ));
1.195 - FLDBG_PRINTF(( "" ));
1.196 -#endif
1.197 -//-TBR
1.198 set_code_range( pEhdr, pPhdr );
1.199 return 0;
1.200 }
1.201 @@ -383,32 +281,12 @@
1.202 {
1.203 Dl_info info;
1.204
1.205 -//+TBR
1.206 -#ifdef MM_DEBUG
1.207 - FLDBG_PRINTF(( "Trying to find Program Header via dladdr." ));
1.208 - FLDBG_PRINTF(( "Looking up dlinfo for %p", _pMem ));
1.209 -#endif
1.210 -//-TBR
1.211 if ( 0 != dladdr(_pMem, &info) ) {
1.212 -//+TBR
1.213 -#ifdef MM_DEBUG
1.214 - FLDBG_PRINTF(( "Found info: " ));
1.215 - FLDBG_PRINTF(( " name: %s", info.dli_fname ));
1.216 - FLDBG_PRINTF(( " base: %p", info.dli_fbase ));
1.217 -#endif
1.218 -//-TBR
1.219 // Check if this is the engine module
1.220 if ( check_for_engine_module(info.dli_fname) ) {
1.221 return phdr_elfhdr( info.dli_fbase );
1.222 }
1.223 }
1.224 -//+TBR
1.225 -#ifdef MM_DEBUG
1.226 - else {
1.227 - FLDBG_PRINTF(( "No info found." ));
1.228 - }
1.229 -#endif
1.230 -//-TBR
1.231
1.232 return NOTFOUND;
1.233 }
1.234 @@ -420,11 +298,6 @@
1.235 struct r_debug* pr_debug;
1.236 struct link_map* pMap;
1.237
1.238 -//+TBR
1.239 -#ifdef MM_DEBUG
1.240 - FLDBG_PRINTF(( "Trying to find Program Header via r_debug struct." ));
1.241 -#endif
1.242 -//-TBR
1.243
1.244 // Search if we have a DT_DEBUG symbol in our DYNAMIC segment, which
1.245 // ought to be set to the r_debug structure's address.
1.246 @@ -436,43 +309,15 @@
1.247 }
1.248
1.249 if ( DT_NULL == pDyn->d_tag ) {
1.250 -//+TBR
1.251 -#ifdef MM_DEBUG
1.252 - FLDBG_PRINTF(( "Unable to find my DT_DEBUG symbol." ));
1.253 -#endif
1.254 -//-TBR
1.255 }
1.256 else if ( NULL == pr_debug ) {
1.257 -//+TBR
1.258 -#ifdef MM_DEBUG
1.259 - FLDBG_PRINTF(( "DT_DEBUG found but is NULL." ));
1.260 -#endif
1.261 -//-TBR
1.262 }
1.263 else {
1.264 -//+TBR
1.265 -#ifdef MM_DEBUG
1.266 - FLDBG_PRINTF(( "Found DT_DEBUG symbol." ));
1.267 - FLDBG_PRINTF(( "r_debug is at %p", pr_debug ));
1.268 -#endif
1.269 -//-TBR
1.270 pMap = pr_debug->r_map;
1.271
1.272 // Walk to the start of the list
1.273 while ( pMap->l_prev != NULL ) pMap = pMap->l_prev;
1.274 do {
1.275 -//+TBR
1.276 -#ifdef MM_DEBUG
1.277 - FLDBG_PRINTF(( "link map is at %p", pMap ));
1.278 -
1.279 -#ifdef __amd64__
1.280 - FLDBG_PRINTF(( "base addr = %lx", pMap->l_addr ));
1.281 -#else
1.282 - FLDBG_PRINTF(( "base addr = %x", pMap->l_addr ));
1.283 -#endif
1.284 - FLDBG_PRINTF(( "name is %s\n", pMap->l_name ));
1.285 -#endif
1.286 -//-TBR
1.287 if ( check_for_engine_module(pMap->l_name) ) {
1.288 return phdr_elfhdr( (void*)pMap->l_addr );
1.289 }
1.290 @@ -492,21 +337,6 @@
1.291 m_codeEnd = pBase + _pPhdr->p_vaddr + _pPhdr->p_memsz;
1.292
1.293 m_state = STATE_VALID;
1.294 -
1.295 -//+TBR
1.296 -#ifdef MM_DEBUG
1.297 - FLDBG_PRINTF(( "==DEBUG==> Setting code range:" ));
1.298 -#ifdef __amd64__
1.299 - FLDBG_PRINTF(( " pPhdr at %p, p_vaddr = 0x%lx, vend = 0x%lx, p_memsz = %ld",
1.300 - _pPhdr, _pPhdr->p_vaddr, _pPhdr->p_vaddr + _pPhdr->p_memsz, _pPhdr->p_memsz ));
1.301 -#else
1.302 - FLDBG_PRINTF(( " pPhdr at %p, p_vaddr = 0x%x, vend = 0x%x, p_memsz = %d",
1.303 - _pPhdr, _pPhdr->p_vaddr, _pPhdr->p_vaddr + _pPhdr->p_memsz, _pPhdr->p_memsz ));
1.304 -#endif
1.305 - FLDBG_PRINTF(( " start address = %p, end address = %p",
1.306 - m_codeStart, m_codeEnd ));
1.307 -#endif
1.308 -//-TBR
1.309 }
1.310
1.311
1.312 @@ -519,19 +349,8 @@
1.313
1.314 // Have to do this only once.
1.315 if ( NULL != m_codeStart ) {
1.316 -//+TBR
1.317 -#ifdef MM_DEBUG
1.318 - FLDBG_PRINTF(( "==DEBUG==> ---------- Engine info already initialised --" ));
1.319 - FLDBG_PRINTF(( "==DEBUG==> codeStart: %p codeEnd: %p", m_codeStart, m_codeEnd ));
1.320 -#endif
1.321 -//-TBR
1.322 return 0;
1.323 }
1.324 -//+TBR
1.325 -#ifdef MM_DEBUG
1.326 - FLDBG_PRINTF(( "==DEBUG==> ---------- Initialising engine info --" ));
1.327 -#endif
1.328 -//-TBR
1.329
1.330 #ifdef _WIN32
1.331
1.332 @@ -558,16 +377,14 @@
1.333 }
1.334
1.335 #endif /* _WIN32 */
1.336 -//+TBR
1.337 -#ifdef MM_DEBUG
1.338 +
1.339 if ( 0 != ret ) {
1.340 - FLDBG_PRINTF(( "==DEBUG==> Unable to determine functions address range!" ));
1.341 + META_DEV( "Unable to determine engine code address range!" );
1.342 }
1.343 else {
1.344 - FLDBG_PRINTF(( "==DEBUG==> codeStart: %p codeEnd: %p", m_codeStart, m_codeEnd ));
1.345 + META_DEV( "Set engine code range: start address = %p, end address = %p",
1.346 + m_codeStart, m_codeEnd );
1.347 }
1.348 -#endif
1.349 -//-TBR
1.350
1.351 return 0;
1.352 }