Class: Elf::Writer::StringTable

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

Overview

Replace with compacting string table

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStringTable

Returns a new instance of StringTable.



30
31
32
33
34
35
36
37
# File 'lib/mithril/writer.rb', line 30

def initialize 
  @buf = StringIO.new("\0")
  @buf.seek 1 
  @strings = {} #TODO: Do substring matching, compress the string
  #table.
  # Actually, make all string tables except dynstr one, might save
  # a bit 
end

Instance Attribute Details

#bufObject (readonly)

Returns the value of attribute buf.



29
30
31
# File 'lib/mithril/writer.rb', line 29

def buf
  @buf
end

Instance Method Details

#add_string(string) ⇒ Object

table. Actually, make all string tables except dynstr one, might save a bit



38
39
40
41
42
43
44
45
# File 'lib/mithril/writer.rb', line 38

def add_string(string) 
  unless @strings.include? string
    @strings[string] =  @buf.tell.tap {|x| 
      BinData::Stringz::new(string).write(@buf)
    }
  end
  @strings[string]
end