metasm/exe_format/coff_encode.rb in metasm-1.0.4 vs metasm/exe_format/coff_encode.rb in metasm-1.0.5

- old
+ new

@@ -77,30 +77,31 @@ } label = lambda { |n| coff.label_at(edata[n], 0, n) } rva = lambda { |n| Expression[label[n], :-, coff.label_at(coff.encoded, 0)] } rva_end = lambda { |n| Expression[[label[n], :-, coff.label_at(coff.encoded, 0)], :+, edata[n].virtsize] } + exports = @exports || [] # ordinal base: smallest number > 1 to honor ordinals, minimize gaps - olist = @exports.map { |e| e.ordinal }.compact + olist = exports.map { |e| e.ordinal }.compact # start with lowest ordinal, substract all exports unused to fill ordinal sequence gaps omin = olist.min.to_i gaps = olist.empty? ? 0 : olist.max+1 - olist.min - olist.length - noord = @exports.length - olist.length + noord = exports.length - olist.length @ordinal_base ||= [omin - (noord - gaps), 1].max @libname_p = rva['libname'] - @num_exports = [@exports.length, @exports.map { |e| e.ordinal }.compact.max.to_i - @ordinal_base].max - @num_names = @exports.find_all { |e| e.name }.length + @num_exports = [exports.length, exports.map { |e| e.ordinal }.compact.max.to_i - @ordinal_base].max + @num_names = exports.find_all { |e| e.name }.length @func_p = rva['addrtable'] @names_p = rva['namptable'] @ord_p = rva['ord_table'] edata['edata'] << super(coff) edata['libname'] << @libname << 0 - elist = @exports.find_all { |e| e.name and not e.ordinal }.sort_by { |e| e.name } - @exports.find_all { |e| e.ordinal }.sort_by { |e| e.ordinal }.each { |e| elist.insert(e.ordinal-@ordinal_base, e) } + elist = exports.find_all { |e| e.name and not e.ordinal }.sort_by { |e| e.name } + exports.find_all { |e| e.ordinal }.sort_by { |e| e.ordinal }.each { |e| elist.insert(e.ordinal-@ordinal_base, e) } elist.each { |e| if not e # export by ordinal with gaps # XXX test this value with the windows loader edata['addrtable'] << coff.encode_word(0xffff_ffff)