ruby-elf 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/bin/elfgrep +1 -1
  2. data/bin/rbelf-read +37 -0
  3. data/lib/elf.rb +3 -3
  4. data/lib/elf/file.rb +11 -9
  5. metadata +4 -4
@@ -142,7 +142,7 @@ module Elf::Tools
142
142
  @regexp = Regexp.union(@patterns.collect { |pattern|
143
143
  if @match == :fixed_strings
144
144
  pattern.split(/\r?\n/).collect { |string|
145
- Regexp.new(Regexp.escape(string), regexp_options)
145
+ Regexp.new("^" + Regexp.escape(string) + "$", regexp_options)
146
146
  }
147
147
  else
148
148
  Regexp.new(pattern, regexp_options)
@@ -26,6 +26,7 @@ module Elf::Tools
26
26
  super
27
27
  @options |= [
28
28
  ["--all", "-a", GetoptLong::NO_ARGUMENT],
29
+ ["--file-header", "-h", GetoptLong::NO_ARGUMENT],
29
30
  ["--section-headers", "-S", GetoptLong::NO_ARGUMENT],
30
31
  ["--dynamic", "-d", GetoptLong::NO_ARGUMENT],
31
32
  ]
@@ -46,6 +47,7 @@ module Elf::Tools
46
47
 
47
48
  @output_mutex.synchronize {
48
49
  printf("\nFile: %s\n", file) if @targets.size != 1
50
+ read_file_header(elf) if @file_header
49
51
  read_sections(elf) if @section_headers
50
52
  read_dynamic(elf) if @dynamic
51
53
  }
@@ -107,5 +109,40 @@ module Elf::Tools
107
109
  break if entry.type == Elf::Dynamic::Type::Null
108
110
  end
109
111
  end
112
+
113
+ def self.put_header(key, value)
114
+ printf " %s %s\n", "#{key}:".ljust(34), value
115
+ end
116
+
117
+ def self.read_file_header(elf)
118
+ puts "ELF Header:"
119
+ # put this verbatim, since it never should change
120
+ puts " Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00"
121
+
122
+ put_header("Class", case elf.elf_class
123
+ when Elf::Class::Elf32 then "ELF32"
124
+ when Elf::Class::Elf64 then "ELF64"
125
+ end)
126
+ put_header("Data", "2's complement, " + case elf.data_encoding
127
+ when Elf::DataEncoding::Lsb then 'little endian'
128
+ when Elf::DataEncoding::Msb then 'big endian'
129
+ end)
130
+ put_header("Ident Version", elf.version)
131
+ put_header("OS/ABI", elf.abi)
132
+ put_header("ABI Version", elf.abi_version)
133
+ put_header("Type", "#{elf.type.mnemonic.upcase} (#{elf.type})")
134
+ put_header("Machine", elf.machine)
135
+ put_header("Version", elf.version)
136
+ put_header("Entry point address", sprintf("0x%x", elf.entry_address))
137
+ put_header("Start of program headers", "#{elf.phoff} (bytes into file)")
138
+ put_header("Start of section headers", "#{elf.shoff} (bytes into file)")
139
+ put_header("Flags", sprintf("0x%x", elf.flags))
140
+ put_header("Size of this header", "#{elf.ehsize} (bytes)")
141
+ put_header("Size of program headers", "#{elf.phentsize} (bytes)")
142
+ put_header("Number of program headers", elf.phnum);
143
+ put_header("Size of section headers", "#{elf.shentsize} (bytes)")
144
+ put_header("Number of section headers", elf.shnum)
145
+ put_header("Section header string table index", elf.shstrndx)
146
+ end
110
147
  end
111
148
  end
data/lib/elf.rb CHANGED
@@ -29,7 +29,7 @@ require 'elf/file'
29
29
  require 'elf/section'
30
30
 
31
31
  module Elf
32
- VERSION = "1.0.4"
32
+ VERSION = "1.0.5"
33
33
 
34
34
  MagicString = "\177ELF"
35
35
 
@@ -64,7 +64,7 @@ module Elf
64
64
 
65
65
  class OsAbi < Value
66
66
  fill(
67
- 0 => [ :SysV, 'UNIX System V ABI' ],
67
+ 0 => [ :SysV, 'UNIX - System V' ],
68
68
  1 => [ :HPUX, 'HP-UX' ],
69
69
  2 => [ :NetBSD, 'NetBSD' ],
70
70
  3 => [ :Linux, 'Linux' ],
@@ -134,7 +134,7 @@ module Elf
134
134
  59 => [ :ME16, 'Toyota ME16 processor' ],
135
135
  60 => [ :ST100, 'STMicroelectronic ST100 processor' ],
136
136
  61 => [ :Tinyj, 'Advanced Logic Corp. Tinyj emb.fam' ],
137
- 62 => [ :X8664, 'AMD x86-64 architecture' ],
137
+ 62 => [ :X8664, 'AMD x86-64' ],
138
138
  63 => [ :PDSP, 'Sony DSP Processor' ],
139
139
  64 => [ :PDP10, 'DEC PDP-10' ],
140
140
  65 => [ :PDP11, 'DEC PDP-11' ],
@@ -84,7 +84,9 @@ module Elf
84
84
  end
85
85
 
86
86
  attr_reader :elf_class, :data_encoding, :type, :version, :abi,
87
- :abi_version, :machine
87
+ :abi_version, :machine, :entry_address, :phoff, :shoff,
88
+ :flags, :ehsize, :phentsize, :phnum, :shentsize, :shnum,
89
+ :shstrndx
88
90
  attr_reader :string_table
89
91
 
90
92
  # raw data access
@@ -197,7 +199,7 @@ module Elf
197
199
  end
198
200
 
199
201
  @version = read_word
200
- @entry = read_addr
202
+ @entry_address = read_addr
201
203
  @phoff = read_off
202
204
  @shoff = read_off
203
205
  @flags = read_word
@@ -205,15 +207,15 @@ module Elf
205
207
  @phentsize = read_half
206
208
  @phnum = read_half
207
209
  @shentsize = read_half
208
- shnum = read_half
209
- shstrndx = read_half
210
+ @shnum = read_half
211
+ @shstrndx = read_half
210
212
 
211
213
  elf32 = elf_class == Class::Elf32
212
214
  @sections = {}
213
215
 
214
216
  @sections_data = []
215
217
  seek(@shoff)
216
- for i in 1..shnum
218
+ for i in 1..@shnum
217
219
  sectdata = {}
218
220
  sectdata[:idx] = i-1
219
221
  sectdata[:name_idx] = read_word
@@ -240,10 +242,10 @@ module Elf
240
242
  # to false, that is distinct from nil, and raise
241
243
  # MissingStringTable on request. If the string table is not yet
242
244
  # loaded raise instead StringTableNotLoaded.
243
- if shstrndx == 0 or not self[shstrndx].is_a? StringTable
245
+ if @shstrndx == 0 or not self[@shstrndx].is_a? StringTable
244
246
  @string_table = false
245
247
  else
246
- @string_table = self[shstrndx]
248
+ @string_table = self[@shstrndx]
247
249
 
248
250
  @sections_names = {}
249
251
  @sections_data.each do |sectdata|
@@ -382,13 +384,13 @@ module Elf
382
384
  def arm_eabi_version
383
385
  return nil if machine != Elf::Machine::ARM
384
386
 
385
- return (flags & ARM::EFlags_EABI_Mask) >> 24
387
+ return (@flags & ARM::EFlags_EABI_Mask) >> 24
386
388
  end
387
389
 
388
390
  def arm_be8?
389
391
  return nil if machine != Elf::Machine::ARM
390
392
 
391
- return (flags & ARM::EFlags_EB8) == ARM::EFlags_EB8
393
+ return (@flags & ARM::EFlags_BE8) == ARM::EFlags_BE8
392
394
  end
393
395
  end
394
396
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-elf
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 4
10
- version: 1.0.4
9
+ - 5
10
+ version: 1.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Diego Elio Petten\xC3\xB2"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-26 00:00:00 +02:00
18
+ date: 2011-07-16 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21