void CCodeProcessor::ProcessModules( const char *root, const char *rootmodule )
{
	m_nFilesProcessed++;

	// Reset header list per module
	m_nHeaderCount = 0;
	m_nModuleCount = 0;

	int numheaders = 0;
	int maxdepth = 0;
	int skippedfiles = 0;

	bool canstart = false;

	if ( strstr( root, "tf2_hud" ) )
	{
		canstart = true;
	}
	if ( !canstart )
	{
		vprint( 0, "skipping %s\n", rootmodule );
		return;
	}
	ProcessModule( false, 0, maxdepth, numheaders, skippedfiles, root, root, rootmodule );
}
void CCodeProcessor::ProcessModules( const char *srcroot, const char *root, const char *rootmodule )
{
	m_nFilesProcessed++;

	// Reset header list per module
	m_Headers.RemoveAll();

	int numheaders = 0;
	int maxdepth = 0;
	int skippedfiles = 0;
	ProcessModule( false, 0, maxdepth, numheaders, skippedfiles, srcroot, root, root, rootmodule );
}
Beispiel #3
0
void GetKernelModulePaths(PVOID* modules, DWORD count, std::vector<ProcessModule>& procModules)
{
	for(DWORD i = 0; i < count; ++i)
	{
		// for each driver get its filename and convert it into a "normal" windows path
		WCHAR modPath[MAX_PATH] = {0};
		if(GetDeviceDriverFileName(modules[i], modPath, MAX_PATH))
		{
			std::wstring dosPath = NTPathToDosPath(modPath);
			procModules.push_back(ProcessModule(modules[i], dosPath));
		}
	}
}
Beispiel #4
0
void GetUserModulePaths(HANDLE hProc, HMODULE* modules, DWORD count, std::vector<ProcessModule>& procModules)
{
	for(DWORD i = 0; i < count; ++i)
	{
		WCHAR modPath[MAX_PATH] = {0};
		GetModuleFileNameEx(hProc, modules[i], modPath, MAX_PATH);
		std::wstring truePath = modPath;
		// certain processes have exes that are loaded with a relative path
		// (smss and csrss) seem to be the main culprits
		if(modPath[0] == L'\\')
		{
			truePath = NTPathToDosPath(truePath.c_str());
		}
		procModules.push_back(ProcessModule(modules[i], truePath));
	}
}
Beispiel #5
0
static void
RunTests(const char *exePath)
{
    if (!(exePath && *exePath))
        return;

    //
    // load test modules
    //
    char *p = strrchr(exePath, kPathSep);
    if (p == NULL) {
        LOG(("unexpected exe path\n"));
        return;
    }

    int baseLen = p - exePath;
    int finalLen = baseLen + 1 + sizeof(kTestsDirectory);

    // build full path to ipc modules
    char *modulesDir = (char*) malloc(finalLen);
    memcpy(modulesDir, exePath, baseLen);
    modulesDir[baseLen] = kPathSep;
    memcpy(modulesDir + baseLen + 1, kTestsDirectory, sizeof(kTestsDirectory));

    LOG(("loading libraries in %s\n", modulesDir));
    // 
    // scan directory for IPC modules
    //
    PRDir *dir = PR_OpenDir(modulesDir);
    if (dir) {
        PRDirEntry *ent;
        while ((ent = PR_ReadDir(dir, PR_SKIP_BOTH)) != NULL) {
            // 
            // locate extension, and check if dynamic library
            //
            char *p = strrchr(ent->name, '.');
            if (p && PL_strcasecmp(p, MOZ_DLL_SUFFIX) == 0)
                ProcessModule(modulesDir, ent->name);
        }
        PR_CloseDir(dir);
    }

    free(modulesDir);
}
void CCodeProcessor::ProcessModule( bool forcequiet, int depth, int& maxdepth, int& numheaders, int& skippedfiles, 
	const char *srcroot, const char *baseroot, const char *root, const char *module )
{
	char filename[ 256 ];

	if ( depth > maxdepth )
	{
		maxdepth = depth;
	}
	int filelength;
	char *buffer = NULL;
		
	// Always skip these particular modules/headers
	if ( SkipFile( module ) )
	{
		CODE_MODULE module;
		module.skipped = true;

		m_Modules.Insert( filename, module );

		skippedfiles++;
		return;
	}

	if ( !LoadFile( &buffer, filename, module, forcequiet, depth, filelength, numheaders, skippedfiles,
		srcroot, root, baseroot ) )
	{
		CODE_MODULE module;
		module.skipped = true;
		m_Modules.Insert( filename, module );
		skippedfiles++;
		return;
	}

	assert( buffer );

	m_nBytesProcessed += filelength;

	CODE_MODULE m;
	m.skipped = false;
	m_Modules.Insert( filename, m );

	if ( !forcequiet )
	{
		strcpy( m_szCurrentCPP, filename );
	}

	AddHeader( depth, filename, m_szCurrentCPP );

	bool onclient = !strnicmp( m_szBaseEntityClass, "C_", 2 ) ? true : false;

	// Parse tokens looking for #include directives or class starts
	char *current = buffer;

	current = CC_ParseToken( current );
	while ( 1 )
	{
		// No more tokens
		if ( !current )
			break;

		if ( !stricmp( com_token, "#include" ) )
		{
			current = CC_ParseToken( current );
			if ( strlen( com_token ) > 0 &&
				com_token[ 0 ] != '<' )
			{
				//vprint( "#include %s\n", com_token );
				m_nHeadersProcessed++;
				numheaders++;
				ProcessModule( true, depth + 1, maxdepth, numheaders, skippedfiles, srcroot, baseroot, root, com_token );
			}
		}
		else if ( !stricmp( com_token, "class" ) ||
			 !stricmp( com_token, "struct" ) )
		{
			current = CC_ParseToken( current );
			if ( strlen( com_token ) > 0 )
			{
				//vprint( depth, "class %s\n", com_token );

				CClass *cl = AddClass( com_token );

				// Now see if there's a base class
				current = CC_ParseToken( current );
				if ( !stricmp( com_token, ":" ) )
				{
					// Parse out public and then classname an
					current = CC_ParseToken( current );
					if ( !stricmp( com_token, "public" ) )
					{
						current = CC_ParseToken( current );
						if ( strlen( com_token ) > 0 )
						{
							cl->SetBaseClass( com_token );

							do
							{
								current = CC_ParseToken( current );
							} while ( strlen( com_token ) && stricmp( com_token, "{" ) );

							if ( !stricmp( com_token, "{" ) )
							{
								current = cl->ParseClassDeclaration( current );
							}
						}
					}
				}
				else if ( !stricmp( com_token, "{" ) )
				{
					current = cl->ParseClassDeclaration( current );
				}
			}
		}
		else if ( !strnicmp( com_token, "PREDICTABLE_CLASS", strlen( "PREDICTABLE_CLASS" ) ) )
		{
			char prefix[ 32 ];
			prefix[ 0 ] = 0;
			int type = 0;
			int bases = 1;
			int usebase = 0;

			if ( !stricmp( com_token, "PREDICTABLE_CLASS_ALIASED" ) )
			{
				type = 2;
				bases = 2;
				if ( onclient )
				{
					strcpy( prefix, "C_" );
				}
				else
				{
					strcpy( prefix, "C" );
					usebase = 1;
				}
			}
			else if ( !stricmp( com_token, "PREDICTABLE_CLASS_SHARED" ) )
			{
				type = 1;
				bases = 1;
			}
			else if ( !stricmp( com_token, "PREDICTABLE_CLASS" ) )
			{
				type = 0;
				bases = 1;
				if ( onclient )
				{
					strcpy( prefix, "C_" );
				}
				else
				{
					strcpy( prefix, "C" );
				}
			}
			else if ( !stricmp( com_token, "PREDICTABLE_CLASS_ALIASED_PREFIXED" ) )
			{
				// Nothing
			}
			else
			{
				vprint( 0, "PREDICTABLE_CLASS of unknown type!!! %s\n", com_token );
			}

			// parse the (
			current = CC_ParseToken( current );
			if ( !strcmp( com_token, "(" ) )
			{
				// Now the classname
				current = CC_ParseToken( current );
				if ( strlen( com_token ) > 0 )
				{
					//vprint( depth, "class %s\n", com_token );

					CClass *cl = AddClass( com_token );

					// Now see if there's a base class
					current = CC_ParseToken( current );
					if ( !stricmp( com_token, "," ) )
					{
						// Parse out public and then classname an
						current = CC_ParseToken( current );
						if ( strlen( com_token ) > 0 )
						{
							char basename[ 256 ];
							sprintf( basename, "%s%s", prefix, com_token );

							bool valid = true;

							if ( bases == 2 )
							{
								valid = false;

								current = CC_ParseToken( current );
								if ( !stricmp( com_token, "," ) )
								{
									current = CC_ParseToken( current );
									if ( strlen( com_token ) > 0 )
									{
										valid = true;
										if ( usebase == 1 )
										{
											sprintf( basename, "%s%s", prefix, com_token );
										}
									}
								}
							}

							if ( valid )
							{
								cl->SetBaseClass( basename );
								strcpy( cl->m_szTypedefBaseClass, basename );
							}
							
							do
							{
								current = CC_ParseToken( current );
							} while ( strlen( com_token ) && stricmp( com_token, ")" ) );

							if ( !stricmp( com_token, ")" ) )
							{
								current = cl->ParseClassDeclaration( current );
							}
						}
					}
					else if ( !stricmp( com_token, ")" ) )
					{
						current = cl->ParseClassDeclaration( current );
					}
				}
			}
		}
		else if ( !strcmp( com_token, "TYPEDESCRIPTION" ) || 
			    !strcmp( com_token, "typedescription_t" ) )
		{
			current = ParseTypeDescription( current, false );
		}
		else if ( !strcmp( com_token, "BEGIN_DATADESC" ) ||
				  !strcmp( com_token, "BEGIN_DATADESC_NO_BASE" ) ||
				  !strcmp( com_token, "BEGIN_SIMPLE_DATADESC" ) )
		{
			current = ParseTypeDescription( current, true );
		}
		else if ( !strcmp( com_token, "BEGIN_PREDICTION_DATA" ) ||
			!strcmp( com_token, "BEGIN_EMBEDDED_PREDDESC" ) )
		{
			current = ParsePredictionTypeDescription( current );
		}
		else if (	!strcmp( com_token, "BEGIN_RECV_TABLE" ) ||
					!strcmp( com_token, "BEGIN_RECV_TABLE_NOBASE" ) ||
					!strcmp( com_token, "IMPLEMENT_CLIENTCLASS_DT" ) ||
					!strcmp( com_token, "IMPLEMENT_CLIENTCLASS_DT_NOBASE" ) )
		{
			current = ParseReceiveTable( current );
		}
		else if ( !strcmp( com_token, "IMPLEMENT_PREDICTABLE_NODATA" ) )
		{
			current = CC_ParseToken( current );
			if ( !strcmp( com_token, "(" ) )
			{
				current = CC_ParseToken( current );

				CClass *cl = FindClass( com_token );
				if ( cl )
				{
					if ( cl->m_bHasPredictionData )
					{
						if ( !forcequiet )
						{
							vprint( 0, "Class %s declared predictable and implemented with IMPLEMENT_PREDICTABLE_NODATA in typedescription\n",
								cl->m_szName );
						}

						cl->m_bHasPredictionData = false;
					}
				}

				current = CC_ParseToken( current );
			}
		}

		current = CC_ParseToken( current );
	}

	COM_FreeFile( (unsigned char *)buffer );

	if ( !forcequiet && !GetQuiet() )
	{
		vprint( 0, " %s: headers (%i game / %i total)", (char *)&filename[ m_nOffset ], numheaders - skippedfiles, numheaders );
		if ( maxdepth > 1 )
		{
			vprint( 0, ", depth %i", maxdepth );
		}
		vprint( 0, "\n" );
	}

	m_nLinesOfCode += linesprocessed;
	linesprocessed = 0;
}