-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpkgutil.rb
62 lines (50 loc) · 1.19 KB
/
pkgutil.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Licensed under GPL-2 or later
# Author: Petteri Räty <[email protected]>
MAGIC="\x7FELF"
# It seems that at least qt has shared libraries that aren't
# executable
def is_elf(file)
File.executable?(file) && File.file?(file) && File.read(file, 4) == MAGIC
end
def get_pkg_of_lib(lib)
command='qfile -vqC ' + lib
output = `#{command}`.split("\n")
output.uniq!
raise "#{command} exited with #{$?}" if $? != 0
output.join(' || ')
end
def handle_extra_output(prog)
$stderr.puts 'This program expects only one line'
$stderr.puts 'of output from scanelf. Extra lines:'
while line = scanelf.gets
$stderr.puts line
end
exit 2
end
def run_scanelf(elf)
scanelf = IO.popen("scanelf -q -F '%n#F' #{elf}")
first_line = scanelf.gets
handle_extra_output(scanelf) if not scanelf.eof?
scanelf.close
libs = first_line.split(',')
for lib in libs
yield lib
end
end
class ScanElf
private_class_method :new
@@instance = nil
def ScanElf.instance
@@instance = new unless @@instance
@@instance
end
def initialize
@process = IO.popen('scanelf -B -F "%n#F" -f /dev/stdin','r+')
end
def each(elf)
@process.puts(elf)
@process.gets.scan(/[^,\s]+/) { |match|
yield match
}
end
end