Class: ElfStructFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/mithril/elf_structs.rb

Constant Summary collapse

@@instances =
{:little => {32 => ElfStructFactory.new(:little,32), 64=>ElfStructFactory.new(:little,64) },
:big => {32 => ElfStructFactory.new(:big,32) , 64 => ElfStructFactory.new(:big,64)}  }

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endian, width) ⇒ ElfStructFactory

Returns a new instance of ElfStructFactory.



314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/mithril/elf_structs.rb', line 314

def initialize(endian,width)
  @endian = endian
  @width = width
  factory = self
  ElfStructs::ELF_OBJECTS.each do |object|
    klass = Class.new BinData::Record do
      extend ElfStructs
      endian  endian
      bitness width
      @factory =  factory
      if(ElfStructs::Split.include? object)
        self.send(ElfStructs::Split[object][width])
      else
        self.send(object)
      end
    end
    instance_variable_set("@#{object.to_s}",klass)
  end
end

Class Method Details

.instance(endian, bits) ⇒ Object



289
290
291
# File 'lib/mithril/elf_structs.rb', line 289

def self.instance(endian, bits)
   @@instances[endian][bits]
end

Instance Method Details

#rel_build_info(sym, type) ⇒ Object



306
307
308
309
310
311
312
# File 'lib/mithril/elf_structs.rb', line 306

def rel_build_info(sym,type) 
  if @width == 32
    (sym.to_i << 8) | (type.to_i &0xff)
  else
    (sym.to_i << 32) | (type.to_i &0xffffffff)
  end
end

#rel_info_sym(info) ⇒ Object



292
293
294
295
296
297
298
# File 'lib/mithril/elf_structs.rb', line 292

def rel_info_sym(info)
  if @width == 32
      info.to_i >> 8
  else 
      info.to_i >> 32
  end
end

#rel_info_type(info) ⇒ Object



299
300
301
302
303
304
305
# File 'lib/mithril/elf_structs.rb', line 299

def rel_info_type(info) 
  if @width == 32
    info.to_i & 0xff
  else
    info.to_i & 0xffffffff
  end
end