Пример #1
0
void *
GetDynamicFunction(const char *funcName)
{
    void *func = NULL;

    /* Need to open the library. */
    if(moduleState->moduleLibrary == NULL &&
       moduleState->moduleFile != NULL)
    {
        moduleState->moduleLibrary = OpenDynamicLibrary(moduleState->moduleFile);
    }

    if(moduleState->moduleLibrary != NULL)
    {
#ifdef DEBUG_PRINT
        fprintf(stderr, "Calling dlsym function to get %s.\n", funcName);
#endif 
        func = dlsym(moduleState->moduleLibrary, (char*)funcName);
    }
#ifdef DEBUG_PRINT
    else
    {
        fprintf(stderr, "Could not call dlsym function because library could not be opened.\n");
    }
#endif 

    return func;
}
Пример #2
0
void dynLibImplLinux::GetImportAndExportData( 
	const char* dllName )
{
	if( std::string(dllName).empty())
	{
		return;
	}

	Elf* mainElf;
	struct link_map* mainLm;
	std::string csPath_o;
	OpenDynamicLibrary( dllName, mainElf, mainLm, csPath_o );
	if ( mainLm == NULL )
	{
		return;
	}

	Elf_Scn* section = 0;
	ElfW(Shdr) *shdr;
	FindSection( mainElf, SHT_DYNAMIC, section, shdr );

	std::list<std::string> dependencies;
	ExtractDynSymbols( mainElf, section, shdr, STT_NOTYPE, dependencies );

	std::list<std::string>::iterator it;
	for(it = dependencies.begin( ); it != dependencies.end( ) ; it++) {

		AddString( it->c_str() );

		if ( GetDllEntry( it->c_str()  ) == NULL )
		{
			DLL_ENTRY stImpExport;

			std::string csPath_o;
			if ( GetExportData( it->c_str(), stImpExport.ArrayExport, csPath_o ) )
			{
				stImpExport.m_bIsStable = true;
				stImpExport.m_csFullPath = csPath_o;

				// Add data to static internal map
				MakeUpper( *it );
				m_DataEntry[ *it ] = stImpExport;

			}

		}

		DeleteString( it->c_str() );
	}

	dlclose( mainLm );
}
Пример #3
0
bool dynLibImplLinux::GetExportData( 
	const char* dynamicLibraryName, 
	SingleMapEntryArray& ExportEntriesArr, 
	std::string& csPath_o )
{
	Elf* elf;
	struct link_map* lm;
	if ( !OpenDynamicLibrary( dynamicLibraryName, elf, lm, csPath_o ) )
	{
		return false;
	}

	if ( GetDllEntry( csPath_o  ) == NULL )
	{
	     	Elf_Scn* section = 0;
        	ElfW(Shdr) *shdr;
		FindSection( elf, SHT_SYMTAB, section, shdr );

		std::list<std::string> symbols;
		ExtractSymbols( elf, section, shdr, STT_FUNC, symbols );

		std::list<std::string>::iterator it;
		for ( it = symbols.begin( ) ; it != symbols.end( ) ; it++) 
		{
			SINGLE_FUNCT_ENTRY newElement;
			newElement.csFunction = Demangle( it->c_str( ) );
			// Use dlsym because st_value sometimes is 0
			//newElement.dwData = (void*) (lm->l_addr + esym->st_value);
			newElement.dwData = dlsym( lm, it->c_str( ) );
			newElement.csSymbol = *it;
			ExportEntriesArr.push_back( newElement );
			
		}	

	}

	CloseDynamicLibrary( elf );

	return true;
}