1 /* =========================================================================
2 * @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 * =========================================================================
17 // -------------------------------------------------------------------------
18 void Split( const std::string& s, std::string& d, std::string& f )
20 size_t found = s.find_last_of( "/\\" );
21 d = s.substr( 0, found );
22 f = s.substr( found + 1 );
25 // -------------------------------------------------------------------------
26 inline bool Exists( const std::string& name )
29 return( stat( name.c_str( ), &buffer) == 0 );
32 // -------------------------------------------------------------------------
33 std::string Exec( const std::string& cmd )
36 std::array< char, 128 > buffer;
38 std::shared_ptr< FILE > pipe( popen( cmd.c_str( ), "r" ), pclose );
40 throw std::runtime_error( "popen( ) failed!" );
41 while( !feof( pipe.get( ) ) )
42 if( fgets( buffer.data( ), 128, pipe.get( ) ) != NULL )
43 result += buffer.data( );
49 // -------------------------------------------------------------------------
50 int main( int argc, char* argv[] )
54 std::cerr << "Usage: " << argv[ 0 ] << " dump_tool libs" << std::endl;
58 std::string dump_tool;
60 if( !Exists( argv[ 1 ] ) )
63 << "Error: file \"" << argv[ 1 ] << "\" does not exist."
68 dump_tool = realpath( argv[ 1 ], NULL );
70 std::set< std::string > files, dirs;
71 std::queue< std::string > q;
72 for( int i = 2; i < argc; ++i )
74 if( Exists( argv[ i ] ) )
76 std::string fname = realpath( argv[ i ], NULL );
77 std::string fname_dir, fname_file;
78 Split( fname, fname_dir, fname_file );
80 dirs.insert( fname_dir );
88 std::string e = q.front( );
90 if( files.find( e ) == files.end( ) )
96 std::istringstream ss(
97 Exec( dump_tool + " -x " + e + " | grep DLL\\ Name" )
101 while( std::getline( ss, line ) )
103 size_t p = line.find( ":" ) + 2;
104 std::set< std::string >::const_iterator d;
105 for( d = dirs.begin( ); d != dirs.end( ); ++d )
106 q.push( *d + "/" + line.substr( p ) );
112 catch( std::exception& err )
121 for( std::string f: files )
122 std::cout << "---> " << f << std::endl;