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 )
35 std::array< char, 128 > buffer;
37 std::shared_ptr< FILE > pipe( popen( cmd.c_str( ), "r" ), pclose );
39 throw std::runtime_error( "popen( ) failed!" );
40 while( !feof( pipe.get( ) ) )
41 if( fgets( buffer.data( ), 128, pipe.get( ) ) != NULL )
42 result += buffer.data( );
46 // -------------------------------------------------------------------------
47 int main( int argc, char* argv[] )
52 << "Usage: " << argv[ 0 ]
53 << " entry_point objdump_tool [other_dir(s)]"
58 std::string entry_point, objdump_tool;
59 std::set< std::string > dirs;
61 if( !Exists( argv[ 1 ] ) )
64 << "Error: file \"" << argv[ 1 ] << "\" does not exist."
69 if( !Exists( argv[ 2 ] ) )
72 << "Error: file \"" << argv[ 2 ] << "\" does not exist."
78 entry_point = realpath( argv[ 1 ], NULL );
79 objdump_tool = realpath( argv[ 2 ], NULL );
81 std::string entry_point_dir, entry_point_file;
82 Split( entry_point, entry_point_dir, entry_point_file );
84 dirs.insert( entry_point_dir );
85 for( int i = 3; i < argc; ++i )
86 if( Exists( argv[ i ] ) )
87 dirs.insert( std::string( realpath( argv[ i ], NULL ) ) );
89 std::set< std::string > files;
90 std::queue< std::string > q;
91 q.push( entry_point );
94 std::string e = q.front( );
96 if( files.find( e ) == files.end( ) )
102 std::istringstream ss(
103 Exec( objdump_tool + " -x " + e + " | grep DLL\\ Name" )
107 while( std::getline( ss, line ) )
109 size_t p = line.find( ":" ) + 2;
110 std::set< std::string >::const_iterator d;
111 for( d = dirs.begin( ); d != dirs.end( ); ++d )
112 q.push( *d + "/" + line.substr( p ) );
118 catch( std::exception& err )
127 for( std::string f: files )
128 std::cout << "---> " << f << std::endl;