Class: PEdump::VersionString

Inherits:
Object
  • Object
show all
Defined in:
lib/pedump/version_info.rb

Class Method Summary collapse

Class Method Details

.read(f, size = SIZE) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/pedump/version_info.rb', line 118

def self.read f, size = SIZE
  pos = f.tell
  super.tap do |x|
    x.szKey   = ''
    x.szKey << f.read(2) until x.szKey[-2..-1] == "\x00\x00" || f.eof?
    x.Padding = f.tell%4 > 0 ? f.read(4 - f.tell%4) : nil

    value_len = [x.wValueLength*2, x.wLength - (f.tell-pos)].min
    value_len = 0 if value_len < 0

    x.Value   = f.read(value_len)
    if f.tell%4 > 0
      f.read(4-f.tell%4) # undoc padding?
    end
    x.szKey.force_encoding('UTF-16LE').encode!('UTF-8').sub!(/\u0000+$/,'') rescue nil
    x.Value.force_encoding('UTF-16LE').encode!('UTF-8').sub!(/\u0000+$/,'') rescue nil
  end
end