Class: Base

Inherits:
Object
  • Object
show all
Defined in:
lib/elfcat/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



4
5
6
7
# File 'lib/elfcat/base.rb', line 4

def initialize
  @data = Hash.new
  @debug = Proc.new { self.debug }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(_method) ⇒ Object



9
10
11
# File 'lib/elfcat/base.rb', line 9

def method_missing _method
  return @data[_method][:data]
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



2
3
4
# File 'lib/elfcat/base.rb', line 2

def data
  @data
end

#debugObject (readonly)

Returns the value of attribute debug.

Raises:

  • (RuntimeError)


2
3
4
# File 'lib/elfcat/base.rb', line 2

def debug
  @debug
end

Instance Method Details

#[](_name) ⇒ Object



13
14
15
# File 'lib/elfcat/base.rb', line 13

def [](_name)
  return @data[_name]
end

#parse_slice(_address, _length) ⇒ Object



34
35
36
# File 'lib/elfcat/base.rb', line 34

def parse_slice _address, _length
  return $resource.slice(_address, _length).split(/\x0/).dup
end

#parse_struct(_struct, _resource, _element_count, _element_size) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/elfcat/base.rb', line 21

def parse_struct _struct, _resource, _element_count, _element_size
  _element_count.times do |i|
    st = Hash.new
    struct_address = i * _element_size

    _struct.each do |k, v|
      st[k] = Util.concatenate(_resource, struct_address + v[0], v[1])
    end

    @data[i] = st.dup
  end
end