metasm/exe_format/elf_encode.rb in metasm-1.0.2 vs metasm/exe_format/elf_encode.rb in metasm-1.0.3
- old
+ new
@@ -9,11 +9,11 @@
module Metasm
class ELF
class Header
def set_default_values elf
- @magic ||= "\x7fELF"
+ @magic ||= ELF::MAGIC
@e_class ||= elf.bitsize.to_s
@data ||= (elf.endianness == :big ? 'MSB' : 'LSB')
@version ||= 'CURRENT'
@i_version ||= @version
@entry ||= 0
@@ -60,10 +60,11 @@
end
sne = elf.sections[elf.header.shstrndx].encoded
return if name_p and sne.data[@name_p, @name.length+1] == @name+0.chr
return if @name_p = sne.data.index(@name+0.chr)
@name_p = sne.virtsize
+ @name.force_encoding('BINARY') if name.respond_to?(:force_encoding)
sne << @name << 0
end
end
class Segment
@@ -90,10 +91,11 @@
def make_name_p(elf, strtab)
s = strtab.kind_of?(EncodedData) ? strtab.data : strtab
return if name_p and s[@name_p, @name.length+1] == @name+0.chr
return if @name_p = s.index(@name+0.chr)
@name_p = strtab.length
+ @name.force_encoding('BINARY') if name.respond_to?(:force_encoding)
strtab << @name << 0
end
end
@@ -517,9 +519,10 @@
# find or create string in strtab
add_str = lambda { |n|
if n and n != '' and not ret = strtab.encoded.data.index(n + 0.chr)
ret = strtab.encoded.virtsize
+ n.force_encoding('BINARY') if n.respond_to?(:force_encoding)
strtab.encoded << n << 0
end
ret || 0
}
@tag.keys.each { |k|