metasm/exe_format/coff_encode.rb in metasm-1.0.3 vs metasm/exe_format/coff_encode.rb in metasm-1.0.4
- old
+ new
@@ -170,20 +170,22 @@
@libname_p = rva_end['nametable']
@ilt_p = rva_end['ilt']
@iat_p ||= Expression[coff.label_at(edata['iat'].last, 0, 'iat'), :-, coff.label_at(coff.encoded, 0)]
edata['idata'] << super(coff)
+ @libname.force_encoding('BINARY') if @libname.respond_to?(:force_encoding)
edata['nametable'] << @libname << 0
ord_mask = 1 << (coff.bitsize - 1)
@imports.each { |i|
edata['iat'].last.add_export i.target, edata['iat'].last.virtsize if i.target
if i.ordinal
ptr = coff.encode_xword(Expression[i.ordinal, :|, ord_mask])
else
edata['nametable'].align 2
ptr = coff.encode_xword(rva_end['nametable'])
+ i.name.force_encoding('BINARY') if i.name.respond_to?(:force_encoding)
edata['nametable'] << coff.encode_half(i.hint || 0) << i.name << 0
end
edata['ilt'] << ptr
edata['iat'].last << ptr
}
@@ -508,20 +510,20 @@
# rt.base_addr temporarily holds the offset from section_start, and is fixed up to rva before '@reloc << rt'
rt = RelocationTable.new
s.encoded.reloc.each { |off, rel|
# check that the relocation looks like "program_start + integer" when bound using the fake binding
- # XXX allow :i32 etc
- if rel.endianness == @endianness and [:u32, :a32, :u64, :a64].include?(rel.type) and
+ # TODO relocate refs to IAT (eg plt)
+ if rel.endianness == @endianness and [:i32, :u32, :a32, :i64, :u64, :a64].include?(rel.type) and
rel.target.bind(binding).reduce.kind_of?(Expression) and
Expression[rel.target, :-, startaddr].bind(binding).reduce.kind_of?(::Integer)
# winner !
# build relocation
r = RelocationTable::Relocation.new
r.offset = off & 0xfff
- r.type = { :u32 => 'HIGHLOW', :u64 => 'DIR64', :a32 => 'HIGHLOW', :a64 => 'DIR64' }[rel.type]
+ r.type = { '32' => 'HIGHLOW', '64' => 'DIR64' }[rel.type.to_s[1, 2]]
# check if we need to start a new relocation table
if rt.base_addr and (rt.base_addr & ~0xfff) != (off & ~0xfff)
rt.base_addr = Expression[[label_at(s.encoded, 0, 'sect_start'), :-, startaddr], :+, rt.base_addr]
@relocations << rt
@@ -624,9 +626,10 @@
s.characteristics |= ['CONTAINS_DATA']
end
end
end
s.rawaddr = nil if s.rawaddr.kind_of?(::Integer) # XXX allow to force rawaddr ?
+ s.name.force_encoding('BINARY') if s.name.respond_to?(:force_encoding)
s_table << s.encode(self)
}
# encode optional header
@optheader.image_size ||= new_label('image_size')