Sha256: 347869357024de0a4fc97135a4d772969449394cbb88ee68fe7d2c056a596725

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

#!/usr/bin/env ruby
#    This file is part of Metasm, the Ruby assembly manipulation suite
#    Copyright (C) 2006-2009 Yoann GUILLOT
#
#    Licence is LGPL, see LICENCE in the top-level directory


#
# this script reads a list of elf files, and lists its dependencies recursively
# libraries are searched in LD_LIBRARY_PATH, /usr/lib and /lib
# includes the elf interpreter
# can be useful when chrooting a binary
#

require 'metasm'


paths = ENV['LD_LIBRARY_PATH'].to_s.split(':') + %w[/usr/lib /lib]
todo = ARGV.map { |file| (file[0] == ?/) ? file : "./#{file}" }
done = []
while src = todo.shift
	puts src
	# could do a simple ELF.decode_file, but this is quicker
	elf = Metasm::ELF.decode_file_header(src)

	if s = elf.segments.find { |s_| s_.type == 'INTERP' }
		interp = elf.encoded[s.offset, s.filesz].data.chomp("\0")
		if not done.include? interp
			puts interp
			done << interp
		end
	end

	elf.decode_tags
	elf.decode_segments_tags_interpret
	deps = elf.tag['NEEDED'].to_a - done
	done.concat deps

	deps.each { |dep|
		if not path = paths.find { |path_| File.exist? File.join(path_, dep) }
			$stderr.puts "cannot find #{dep} for #{src}"
		else
			todo << File.join(path, dep)
		end
	}
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
metasm-1.0.5 samples/elf_list_needed.rb
metasm-1.0.4 samples/elf_list_needed.rb
metasm-1.0.3 samples/elf_list_needed.rb
metasm-1.0.2 samples/elf_list_needed.rb
metasm-1.0.1 samples/elf_list_needed.rb
metasm-1.0.0 samples/elf_list_needed.rb