ruby-elf 1.0.6.1 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/DONATING +1 -1
  2. data/bin/cowstats +1 -1
  3. data/bin/elfgrep +55 -16
  4. data/bin/missingstatic +1 -1
  5. data/bin/rbelf-nm +46 -11
  6. data/bin/rbelf-read +4 -6
  7. data/bin/rbelf-size +4 -2
  8. data/bin/verify-lfs +1 -1
  9. data/extras/bindings-parsers.rb +1 -1
  10. data/lib/bytestream-reader.rb +1 -1
  11. data/lib/elf.rb +2 -2
  12. data/lib/elf/dynamic.rb +2 -2
  13. data/lib/elf/file.rb +10 -1
  14. data/lib/elf/gnu.rb +1 -1
  15. data/lib/elf/section.rb +1 -1
  16. data/lib/elf/stringtable.rb +4 -14
  17. data/lib/elf/sunw.rb +1 -1
  18. data/lib/elf/symbol.rb +43 -37
  19. data/lib/elf/symboltable.rb +1 -1
  20. data/lib/elf/tools.rb +3 -2
  21. data/lib/elf/utils/loader.rb +1 -1
  22. data/lib/elf/utils/offsettable.rb +49 -0
  23. data/lib/elf/utils/pool.rb +1 -1
  24. data/lib/elf/value.rb +1 -1
  25. data/manpages/cowstats.1 +2 -2
  26. data/manpages/cowstats.1.xml +1 -1
  27. data/manpages/elfgrep.1 +39 -5
  28. data/manpages/elfgrep.1.xml +53 -2
  29. data/manpages/missingstatic.1 +2 -2
  30. data/manpages/missingstatic.1.xml +1 -1
  31. data/manpages/rbelf-nm.1 +18 -3
  32. data/manpages/rbelf-nm.1.xml +41 -1
  33. data/manpages/rbelf-size.1 +2 -2
  34. data/manpages/rbelf-size.1.xml +1 -1
  35. data/manpages/verify-lfs.1 +2 -2
  36. data/manpages/verify-lfs.1.xml +1 -1
  37. data/tools/assess_duplicate_save.rb +1 -1
  38. data/tools/link-collisions/harvest.rb +19 -9
  39. data/tools/link-collisions/known-broken +7 -18
  40. data/tools/link-collisions/multimplementations +35 -4
  41. data/tools/link-collisions/suppress.rb +1 -1
  42. data/tools/link-collisions/suppressions +22 -18
  43. data/tools/rbelf-lddtree.rb +1 -1
  44. metadata +13 -16
  45. data/lib/elf/symbol/demangler_gcc3.rb +0 -1952
data/DONATING CHANGED
@@ -38,5 +38,5 @@ willing to donate.
38
38
 
39
39
  If you know other foundations, donations to which could be deduced
40
40
  from taxes in other countries, feel free to suggest more by mailing me
41
- at flameeyes@gmail.com . Hopefully wherever the research is based, the
41
+ at flameeyes@flameeyes.eu . Hopefully wherever the research is based, the
42
42
  improvements will come equally.
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- mode: ruby; coding: utf-8 -*-
3
- # Copyright © 2008-2010 Diego E. "Flameeyes" Pettenò <flameeyes@gmail.com>
3
+ # Copyright © 2008-2010 Diego Elio Pettenò <flameeyes@flameeyes.eu>
4
4
  #
5
5
  # This program is free software; you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- mode: ruby; coding: utf-8 -*-
3
- # Copyright © 2011 Diego E. "Flameeyes" Pettenò <flameeyes@gmail.com>
3
+ # Copyright © 2011 Diego Elio Pettenò <flameeyes@flameeyes.eu>
4
4
  #
5
5
  # This program is free software; you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -52,6 +52,10 @@ module Elf::Tools
52
52
  ["--ignore-case", "-i", GetoptLong::NO_ARGUMENT],
53
53
  # Use NULLs to terminate filenames
54
54
  ["--null", "-Z", GetoptLong::NO_ARGUMENT],
55
+ # read the list of patterns from the given file
56
+ ["--file", "-f", GetoptLong::REQUIRED_ARGUMENT],
57
+ # match the whole symbol
58
+ ["--symbol-regexp", "-s", GetoptLong::NO_ARGUMENT],
55
59
  ]
56
60
 
57
61
  @invert_match = false
@@ -60,6 +64,7 @@ module Elf::Tools
60
64
  @match_symbols = nil
61
65
 
62
66
  @patterns = []
67
+ @pattern_is_first = true
63
68
  end
64
69
 
65
70
  # We define callbacks for some behaviour-changing options as those
@@ -104,9 +109,19 @@ module Elf::Tools
104
109
  end
105
110
 
106
111
  def self.regexp_cb(pattern)
112
+ @pattern_is_first = false
113
+
107
114
  @patterns << pattern
108
115
  end
109
116
 
117
+ def self.file_cb(filename)
118
+ @pattern_is_first = false
119
+
120
+ @patterns += File.readlines(filename).
121
+ each { |l| l.strip! }.
122
+ reject { |l| l.empty? }
123
+ end
124
+
110
125
  def self.after_options
111
126
  if @no_match_undefined and @no_match_defined
112
127
  puterror "you need to match at least defined or undefined symbols"
@@ -122,7 +137,7 @@ module Elf::Tools
122
137
  # to be given by stdin, and that won't include the actual pattern,
123
138
  # if we have an @-prefixed argument, that's a list of targets and
124
139
  # can't include the pattern either.
125
- if (@patterns.size == 0 and
140
+ if (@pattern_is_first and
126
141
  @targets.size >= 1 and
127
142
  @targets[0] !~ /^@/)
128
143
 
@@ -139,15 +154,40 @@ module Elf::Tools
139
154
  @file_list_fmt = "%s#{@null ? "\0" : "\n"}"
140
155
 
141
156
  regexp_options = @ignore_case ? Regexp::IGNORECASE : 0
142
- @regexp = Regexp.union(@patterns.collect { |pattern|
143
- if @match == :fixed_strings
144
- pattern.split(/\r?\n/).collect { |string|
145
- Regexp.new("^" + Regexp.escape(string) + "$", regexp_options)
146
- }
147
- else
148
- Regexp.new(pattern, regexp_options)
149
- end
150
- }.flatten)
157
+ regexps = @patterns.collect { |pattern|
158
+ if @match == :fixed_strings
159
+ pattern.split(/\r?\n/).collect { |string|
160
+ Regexp.new(Regexp.escape(string), regexp_options)
161
+ }
162
+ else
163
+ Regexp.new(pattern, regexp_options)
164
+ end
165
+ }.flatten
166
+
167
+ if @symbol_regexp
168
+ # if we're matching a whole symbol name we need the longest
169
+ # match, and Ruby's union of regexp does _not_ enforce that,
170
+ # so we have to do it the long way.
171
+
172
+ @match_lambda = proc { |symbol|
173
+ longest_match = ""
174
+
175
+ regexps.each { |re|
176
+ m = re.match(symbol)
177
+ longest_match = m[0] unless (m.nil? or m[0].length < longest_match.length)
178
+ }
179
+
180
+ (longest_match != symbol) == @invert_match
181
+ }
182
+ else
183
+ # if we're just doing a loose match, unite the regexps and do
184
+ # it the fast way.
185
+ regexp = Regexp.union(regexps)
186
+
187
+ @match_lambda = proc { |symbol|
188
+ regexp.match(symbol).nil? == @invert_match
189
+ }
190
+ end
151
191
  end
152
192
 
153
193
  def self.analysis(file)
@@ -181,16 +221,15 @@ module Elf::Tools
181
221
  symname = symbol.name
182
222
  symname += "@#{symbol.version}" if @match_version
183
223
 
184
- # We don't care where it matches, but we do care that it matches
185
- # or not; we use an invert match since we have to further compare
186
- # that to @invert_match
187
- if (@invert_match == (@regexp =~ symname).nil?)
224
+ if (@match_lambda.call(symname))
188
225
  matches = matches+1
189
226
 
190
227
  break unless @show == :full_match
191
228
  next if @count
192
229
 
193
- puts "#{file_prefix}#{symbol.address_string} #{symbol.nm_code rescue '?'} #{symname}"
230
+ printf("%s%#{elf.address_print_size}s %s %s\n",
231
+ file_prefix, symbol.address_string,
232
+ (symbol.nm_code rescue '?'), symname)
194
233
  end
195
234
  end
196
235
 
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- mode: ruby; coding: utf-8 -*-
3
- # Copyright © 2008-2010 Diego E. "Flameeyes" Pettenò <flameeyes@gmail.com>
3
+ # Copyright © 2008-2010 Diego Elio Pettenò <flameeyes@flameeyes.eu>
4
4
  #
5
5
  # This program is free software; you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
- # Copyright © 2007-2010 Diego E. "Flameeyes" Pettenò <flameeyes@gmail.com>
3
+ # Copyright © 2007-2010 Diego Elio Pettenò <flameeyes@flameeyes.eu>
4
4
  #
5
5
  # This program is free software; you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -28,23 +28,40 @@ module Elf::Tools
28
28
  super
29
29
  @options |= [
30
30
  ["--dynamic", "-D", GetoptLong::NO_ARGUMENT],
31
- ["--demangle", "-C", GetoptLong::NO_ARGUMENT]
31
+ ["--demangle", "-C", GetoptLong::NO_ARGUMENT],
32
+ ["--sort-by", "-S", GetoptLong::REQUIRED_ARGUMENT],
33
+ ["--show-version", "-V", GetoptLong::NO_ARGUMENT],
32
34
  ]
33
35
 
34
36
  @scan_section = '.symtab'
35
37
  @demangle = false
36
38
  @exitval = 0
39
+ @show_version = false
37
40
 
38
- # do not use multiple threads (unless we start caching the
39
- # output, and synchronise on it).
40
- @execution_threads = nil
41
+ @sort = :name
41
42
  end
42
43
 
43
44
  def self.dynamic_cb
44
45
  @scan_section = '.dynsym'
45
46
  end
46
47
 
48
+ def self.sort_by_cb(attr)
49
+ case attr
50
+ when 'address'
51
+ @sort = :address
52
+ when 'name'
53
+ @sort = :name
54
+ when 'none'
55
+ @sort = nil
56
+ else
57
+ puterror "invalid sort attribute: #{attr}"
58
+ exit -1
59
+ end
60
+ end
61
+
47
62
  def self.analysis(file)
63
+ symbols = []
64
+
48
65
  Elf::File.open(file) do |elf|
49
66
  if not elf.has_section? @scan_section
50
67
  puterror "No symbols"
@@ -55,19 +72,37 @@ module Elf::Tools
55
72
  elf[@scan_section].each do |sym|
56
73
  next if sym.name == ''
57
74
  begin
58
- flag = sym.nm_code
75
+ code = sym.nm_code
59
76
  rescue Elf::Symbol::UnknownNMCode => e
60
77
  puterror(e.message)
61
- flag = "?"
78
+ code = "?"
62
79
  end
63
80
 
64
- version_name = sym.version
65
- version_name = version_name ? "@#{sym.version_default? ? '@' : ''}#{version_name}" : ""
66
-
67
81
  name = @demangle ? sym.demangle : sym.name
68
82
 
69
- puts "#{sym.address_string} #{flag} #{name}#{version_name}"
83
+ if @show_version and sym.version
84
+ name = sprintf("%s@%s%s",
85
+ name,
86
+ sym.version_default? ? '@' : '',
87
+ sym.version)
88
+ end
89
+
90
+ symbols << {
91
+ :address => sym.address_string,
92
+ :code => code,
93
+ :name => name
94
+ }
70
95
  end
96
+
97
+ symbols.sort! { |x, y| x[@sort] <=> y[@sort] } unless @sort.nil?
98
+
99
+ format_sym = "%#{elf.address_print_size}s %s %s\n"
100
+ @output_mutex.synchronize {
101
+ symbols.each do |sym|
102
+ printf(format_sym,
103
+ sym[:address], sym[:code], sym[:name])
104
+ end
105
+ }
71
106
  end
72
107
  end
73
108
 
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- mode: ruby; coding: utf-8 -*-
3
- # Copyright © 2008-2011 Diego E. "Flameeyes" Pettenò <flameeyes@gmail.com>
3
+ # Copyright © 2008-2011 Diego Elio Pettenò <flameeyes@flameeyes.eu>
4
4
  #
5
5
  # This program is free software; you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -43,8 +43,6 @@ module Elf::Tools
43
43
  def self.analysis(file)
44
44
  elf = Elf::File.open(file)
45
45
 
46
- @addrsize = (elf.elf_class == Elf::Class::Elf32 ? 8 : 16)
47
-
48
46
  @output_mutex.synchronize {
49
47
  printf("\nFile: %s\n", file) if @targets.size != 1
50
48
  read_file_header(elf) if @file_header
@@ -57,12 +55,12 @@ module Elf::Tools
57
55
  printf("There are %d section headers, starting at offset 0x%x:\n\nSection Headers:\n",
58
56
  elf.sections, elf.shoff)
59
57
 
60
- printf("[Nr] Name Type Addr Off Size ES Flags Lk Inf Al\n")
58
+ printf("[Nr] Name Type Addr Off Size ES Flags Lk Inf Al\n")
61
59
 
62
60
  elf.each_section do |section|
63
- printf("[%2d] %s %s %0#{@addrsize}x %08x %08x %2d %s %2d %3d %2d\n",
61
+ printf("[%2d] %s %s %0#{elf.address_print_size}x %08x %08x %2d %s %2d %3d %2d\n",
64
62
  section.index,
65
- section.name.ljust(20),
63
+ section.name.ljust(23),
66
64
  section.type.mnemonic.upcase.ljust(13),
67
65
  section.addr, section.offset, section.size, section.entsize,
68
66
  section.flags_s.ljust(5), section.link.to_i, section.info, section.addralign)
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- mode: ruby; coding: utf-8 -*-
3
- # Copyright © 2008-2011 Diego E. "Flameeyes" Pettenò <flameeyes@gmail.com>
3
+ # Copyright © 2008-2011 Diego Elio Pettenò <flameeyes@flameeyes.eu>
4
4
  #
5
5
  # This program is free software; you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -143,7 +143,9 @@ module Elf::Tools
143
143
  end
144
144
 
145
145
  def self.count_allocated(results)
146
- results[:allocated] = results.values.inject { |sum, val| sum += val rescue sum}
146
+ results[:allocated] = results.values.inject { |sum, val|
147
+ sum = val.is_a?(String) ? sum : (sum+val)
148
+ }
147
149
  end
148
150
 
149
151
  def self.apply_differential(results)
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- mode: ruby; coding: utf-8 -*-
3
- # Copyright © 2010 Diego E. "Flameeyes" Pettenò <flameeyes@gmail.com>
3
+ # Copyright © 2010 Diego Elio Pettenò <flameeyes@flameeyes.eu>
4
4
  #
5
5
  # This program is free software; you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
- # Copyright © 2006-2008, Diego E. "Flameeyes" Pettenò <flameeyes@gmail.com>
3
+ # Copyright © 2006-2008, Diego Elio Pettenò <flameeyes@flameeyes.eu>
4
4
  #
5
5
  # This program is free software; you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -3,7 +3,7 @@
3
3
  # This class is a simple File derivative from which you can read
4
4
  # integers of different sizes, in any endianness.
5
5
  #
6
- # Copyright © 2007-2010 Diego E. "Flameeyes" Pettenò <flameeyes@gmail.com>
6
+ # Copyright © 2007-2010 Diego Elio Pettenò <flameeyes@flameeyes.eu>
7
7
  #
8
8
  # Permission is hereby granted, free of charge, to any person
9
9
  # obtaining a copy of this software and associated documentation files
data/lib/elf.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Simple ELF parser for Ruby
3
3
  #
4
- # Copyright © 2007-2010 Diego E. "Flameeyes" Pettenò <flameeyes@gmail.com>
4
+ # Copyright © 2007-2010 Diego Elio Pettenò <flameeyes@flameeyes.eu>
5
5
  # Portions inspired by elf.py
6
6
  # Copyright © 2002 Netgraft Corporation
7
7
  # Portions inspired by glibc's elf.h
@@ -29,7 +29,7 @@ require 'elf/file'
29
29
  require 'elf/section'
30
30
 
31
31
  module Elf
32
- VERSION = "1.0.6.1"
32
+ VERSION = "1.0.7"
33
33
 
34
34
  MagicString = "\177ELF"
35
35
 
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Simple ELF parser for Ruby
3
3
  #
4
- # Copyright © 2007-2010 Diego E. "Flameeyes" Pettenò <flameeyes@gmail.com>
4
+ # Copyright © 2007-2010 Diego Elio Pettenò <flameeyes@flameeyes.eu>
5
5
  # Portions inspired by elf.py
6
6
  # Copyright © 2002 Netgraft Corporation
7
7
  # Portions inspired by elf.h
@@ -122,7 +122,7 @@ module Elf
122
122
  0x7ffffffd => [ :Auxiliary, "AUXILIARY", :Value ]
123
123
  )
124
124
 
125
- OsSpecific = 0x6000000d..0x6ffff000
125
+ OsSpecific = 0x60000000..0x6fffffff
126
126
  ProcSpecific = 0x70000000..0x7fffffff
127
127
  SpecialRanges = {
128
128
  "DT_LOOS" => OsSpecific,
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Simple ELF parser for Ruby
3
3
  #
4
- # Copyright © 2007-2010 Diego E. "Flameeyes" Pettenò <flameeyes@gmail.com>
4
+ # Copyright © 2007-2010 Diego Elio Pettenò <flameeyes@flameeyes.eu>
5
5
  # Portions inspired by elf.py
6
6
  # Copyright © 2002 Netgraft Corporation
7
7
  # Portions inspired by elf.h
@@ -339,6 +339,15 @@ module Elf
339
339
  end
340
340
  end
341
341
 
342
+ # Returns the hex address size for the file.
343
+ #
344
+ # Since each ELF file uses either 32- or 64-bit addresses, it is
345
+ # important to know how many characters a file's address would
346
+ # require when printed as an hexadecimal string.
347
+ def address_print_size
348
+ (@elf_class == Elf::Class::Elf32 ? 8 : 16)
349
+ end
350
+
342
351
  def summary
343
352
  $stdout.puts "ELF file #{path}"
344
353
  $stdout.puts "ELF class: #{@elf_class} #{@data_encoding} ver. #{@version}"
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Simple ELF parser for Ruby
3
3
  #
4
- # Copyright © 2007-2010 Diego E. "Flameeyes" Pettenò <flameeyes@gmail.com>
4
+ # Copyright © 2007-2010 Diego Elio Pettenò <flameeyes@flameeyes.eu>
5
5
  # Portions inspired by elf.py
6
6
  # Copyright © 2002 Netgraft Corporation
7
7
  # Portions inspired by elf.h
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Simple ELF parser for Ruby
3
3
  #
4
- # Copyright © 2007-2010 Diego E. "Flameeyes" Pettenò <flameeyes@gmail.com>
4
+ # Copyright © 2007-2010 Diego Elio Pettenò <flameeyes@flameeyes.eu>
5
5
  # Portions inspired by elf.py
6
6
  # Copyright © 2002 Netgraft Corporation
7
7
  # Portions inspired by elf.h
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Simple ELF parser for Ruby
3
3
  #
4
- # Copyright © 2007-2010 Diego E. "Flameeyes" Pettenò <flameeyes@gmail.com>
4
+ # Copyright © 2007-2010 Diego Elio Pettenò <flameeyes@flameeyes.eu>
5
5
  # Portions inspired by elf.py
6
6
  # Copyright © 2002 Netgraft Corporation
7
7
  # Portions inspired by elf.h
@@ -22,28 +22,18 @@
22
22
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
23
 
24
24
  require 'elf/section'
25
+ require 'elf/utils/offsettable'
25
26
 
26
27
  module Elf
27
28
  class StringTable < Section
28
29
  def load_internal
29
- @rawtable = @file.readexactly(@size)
30
- end
31
-
32
- class InvalidIndex < Exception
33
- def initialize(idx, max_idx)
34
- super("Invalid index #{idx} (maximum index: #{max_idx})")
35
- end
30
+ @rawtable = Utilities::OffsetTable.new(@file.readexactly(@size), "\x00")
36
31
  end
37
32
 
38
33
  def [](idx)
39
34
  load unless @rawtable
40
35
 
41
- raise InvalidIndex.new(idx, @rawtable.size) if
42
- idx >= @rawtable.size
43
-
44
- endidx = @rawtable.index("\x00", idx)
45
-
46
- return @rawtable[idx..endidx].chomp("\x00")
36
+ @rawtable[idx]
47
37
  end
48
38
  end
49
39
  end