ruby-elf 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ # Copyright © 2007-2010 Diego E. "Flameeyes" Pettenò <flameeyes@gmail.com>
4
+ #
5
+ # This program is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation; either version 2 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this generator; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ # bsd-nm implementation based on elf.rb (very limited)
20
+
21
+ require 'elf'
22
+ require 'getoptlong'
23
+
24
+ opts = GetoptLong.new(
25
+ ["--dynamic", "-D", GetoptLong::NO_ARGUMENT],
26
+ ["--demangle", "-C", GetoptLong::NO_ARGUMENT]
27
+ )
28
+
29
+ scan_section = '.symtab'
30
+ demangle = false
31
+
32
+ opts.each do |opt, arg|
33
+ case opt
34
+ when '--dynamic'
35
+ scan_section = '.dynsym'
36
+ when '--demangle'
37
+ demangle = true
38
+ end
39
+ end
40
+
41
+ exitval = 0
42
+
43
+ files = ARGV.length > 0 ? ARGV : ['a.out']
44
+
45
+ files.each do |file|
46
+ begin
47
+ Elf::File.open(file) do |elf|
48
+ addrsize = (elf.elf_class == Elf::Class::Elf32 ? 8 : 16)
49
+
50
+ if not elf.has_section? scan_section
51
+ $stderr.puts "nm.rb: #{elf.path}: No symbols"
52
+ exitval = 1
53
+ next
54
+ end
55
+
56
+ elf[scan_section].each do |sym|
57
+ next if sym.name == ''
58
+ begin
59
+ flag = sym.nm_code
60
+ rescue Elf::Symbol::UnknownNMCode => e
61
+ $stderr.puts e.message
62
+ flag = "?"
63
+ end
64
+
65
+ version_name = sym.version
66
+ version_name = version_name ? "@#{sym.version_default? ? '@' : ''}#{version_name}" : ""
67
+
68
+ name = demangle ? sym.demangle : sym.name
69
+
70
+ puts "#{sym.address_string} #{flag} #{name}#{version_name}"
71
+ end
72
+ end
73
+ rescue Errno::ENOENT
74
+ $stderr.puts "nm.rb: #{file}: No such file"
75
+ end
76
+ end
77
+
78
+ exit exitval
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ # Copyright © 2007-2010 Diego E. "Flameeyes" Pettenò <flameeyes@gmail.com>
4
+ #
5
+ # This program is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation; either version 2 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this generator; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ # Proof of Concept tool to implement ldd-like dependency scan with
20
+ # dependency tree. It is similar to lddtree.sh script as provided by
21
+ # scanelf, but not the same thing.
22
+
23
+ require 'elf'
24
+ require 'elf/utils/loader'
25
+
26
+ require 'set'
27
+
28
+ $seen_libraries = Set.new
29
+
30
+ def print_dependency_list(elf, indent_level)
31
+ elf[".dynamic"].needed_libraries.each_pair do |soname, lib|
32
+ case
33
+ when lib.nil?
34
+ puts "#{" "*indent_level}#{soname} => not found"
35
+ when $seen_libraries.include?(lib.path)
36
+ puts "#{" "*indent_level}#{soname} => #{lib.path} +"
37
+ else
38
+ puts "#{" "*indent_level}#{soname} => #{lib.path}"
39
+ print_dependency_list(lib, indent_level+1)
40
+
41
+ $seen_libraries |= lib.path
42
+ end
43
+ end
44
+ end
45
+
46
+ Elf::File.open(ARGV[0]) do |elf|
47
+ puts ARGV[0]
48
+ print_dependency_list(elf, 1)
49
+ end
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ # Copyright © 2007-2010 Diego E. "Flameeyes" Pettenò <flameeyes@gmail.com>
4
+ #
5
+ # This program is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation; either version 2 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this generator; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ # readelf -d implementation based on elf.rb (very limited)
20
+
21
+ require 'elf'
22
+ require 'getoptlong'
23
+
24
+ files = ARGV.length > 0 ? ARGV : ['a.out']
25
+
26
+ files.each do |file|
27
+ puts
28
+ begin
29
+ Elf::File.open(file) do |elf|
30
+ dynsection = elf['.dynamic']
31
+
32
+ unless dynsection
33
+ puts "There is no dynamic section in this file."
34
+ next
35
+ end
36
+
37
+ addrsize = (elf.elf_class == Elf::Class::Elf32 ? 8 : 16)
38
+
39
+ puts "Dynamic section at offset 0x#{dynsection.offset.hex} contains #{dynsection.size} entries"
40
+ puts " Tag Type Name/Value"
41
+
42
+ dynsection.each_entry do |entry|
43
+
44
+ case entry.type
45
+ when Elf::Dynamic::Type::Needed
46
+ val = "Shared library: [#{entry.parsed}]"
47
+ when Elf::Dynamic::Type::Auxiliary
48
+ val = "Auxiliary library: [#{entry.parsed}]"
49
+ when Elf::Dynamic::Type::SoName
50
+ val = "Library soname: [#{entry.parsed}]"
51
+ when Elf::Dynamic::Type::StrSz, Elf::Dynamic::Type::SymEnt,
52
+ Elf::Dynamic::Type::PltRelSz, Elf::Dynamic::Type::RelASz,
53
+ Elf::Dynamic::Type::RelAEnt
54
+
55
+ val = "#{entry.value} (bytes)"
56
+ when Elf::Dynamic::Type::VerDefNum, Elf::Dynamic::Type::VerNeedNum, Elf::Dynamic::Type::RelACount
57
+ val = entry.value
58
+ when Elf::Dynamic::Type::GNUPrelinked
59
+ val = entry.parsed.getutc.strftime('%Y-%m-%dT%H:%M:%S')
60
+ else
61
+ val = sprintf "0x%0#{addrsize}x", entry.value
62
+ end
63
+
64
+ printf " 0x%08x %-28s %s\n", entry.type.to_i, "(#{entry.type.to_s})", val
65
+
66
+ break if entry.type == Elf::Dynamic::Type::Null
67
+ end
68
+ end
69
+ rescue Errno::ENOENT
70
+ $stderr.puts "readelf-d.rb: '#{file}': No such file"
71
+ exit 1
72
+ end
73
+ end
74
+
75
+ exit 0
76
+
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-elf
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - "Diego Elio Petten\xC3\xB2"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-26 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: |
23
+ Ruby-Elf is a pure-Ruby library for parse and fetch information about
24
+ ELF format used by Linux, FreeBSD, Solaris and other Unix-like
25
+ operating systems, and include a set of analysis tools helpful for
26
+ both optimisations and verification of compiled ELF files.
27
+
28
+ email: flameeyes@gmail.com
29
+ executables:
30
+ - elfgrep
31
+ - cowstats
32
+ - verify-lfs
33
+ - rbelf-size
34
+ - missingstatic
35
+ extensions: []
36
+
37
+ extra_rdoc_files: []
38
+
39
+ files:
40
+ - COPYING
41
+ - DONATING
42
+ - bin/cowstats
43
+ - bin/elfgrep
44
+ - bin/missingstatic
45
+ - bin/rbelf-size
46
+ - bin/verify-lfs
47
+ - extras/README.extras
48
+ - extras/bindings-parsers.rb
49
+ - lib/bytestream-reader.rb
50
+ - lib/elf.rb
51
+ - lib/elf/dynamic.rb
52
+ - lib/elf/file.rb
53
+ - lib/elf/gnu.rb
54
+ - lib/elf/section.rb
55
+ - lib/elf/stringtable.rb
56
+ - lib/elf/sunw.rb
57
+ - lib/elf/symbol.rb
58
+ - lib/elf/symboltable.rb
59
+ - lib/elf/tools.rb
60
+ - lib/elf/utils/loader.rb
61
+ - lib/elf/utils/pool.rb
62
+ - lib/elf/value.rb
63
+ - tools/assess_duplicate_save.rb
64
+ - tools/link-collisions/analyse.rb
65
+ - tools/link-collisions/harvest.rb
66
+ - tools/link-collisions/known-broken
67
+ - tools/link-collisions/multimplementations
68
+ - tools/link-collisions/suppress.rb
69
+ - tools/link-collisions/suppressions
70
+ - tools/nm.rb
71
+ - tools/rbelf-lddtree.rb
72
+ - tools/readelf-d.rb
73
+ - lib/elf/symbol/demangler_gcc3.rb
74
+ - manpages/verify-lfs.1
75
+ - manpages/elfgrep.1
76
+ - manpages/missingstatic.1
77
+ - manpages/cowstats.1
78
+ - manpages/rbelf-size.1
79
+ has_rdoc: true
80
+ homepage: http://www.flameeyes.eu/projects/ruby-elf
81
+ licenses:
82
+ - GPL-2 or later
83
+ post_install_message:
84
+ rdoc_options: []
85
+
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ requirements:
107
+ - none
108
+ rubyforge_project: ruby-elf
109
+ rubygems_version: 1.3.7
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: Pure Ruby ELF file parser and utilities
113
+ test_files: []
114
+