node/lib/metasm/metasm/exe_format/coff_encode.rb
def encode_header
		# encode section table, add CONTAINS_* flags from other characteristics flags
		s_table = EncodedData.new

		@sections.each { |s|
			if s.characteristics.kind_of? Array and s.characteristics.include? 'MEM_READ'
				if s.characteristics.include? 'MEM_EXECUTE'
					s.characteristics |= ['CONTAINS_CODE']
				elsif s.encoded
					if s.encoded.rawsize == 0
						s.characteristics |= ['CONTAINS_UDATA']
					else
						s.characteristics |= ['CONTAINS_DATA']
					end
				end
			end
			s.rawaddr = nil if s.rawaddr.kind_of?(::Integer)	# XXX allow to force rawaddr ?
			s_table << s.encode(self)
		}

		# encode optional header
		@optheader.image_size   ||= new_label('image_size')
		@optheader.image_base   ||= label_at(@encoded, 0)
		@optheader.headers_size ||= new_label('headers_size')
		@optheader.checksum     ||= new_label('checksum')
		@optheader.subsystem    ||= 'WINDOWS_GUI'
		@optheader.numrva = nil
		opth = @optheader.encode(self)

		# encode header
		@header.machine ||= 'UNKNOWN'
		@header.num_sect ||= sections.length
		@header.time ||= Time.now.to_i & -255
		@header.size_opthdr ||= opth.virtsize
		@encoded << @header.encode(self) << opth << s_table
	end
# appends the header/optheader/directories/section table to @encoded
appends the header/optheader/directories/section table to @encoded
appends the header / optheader / directories / section table to @encoded
def encode_header
		s_table = EncodedData.new
		@sections.each { |s|
			if s.characteristics.kind_of? Array and s.characteristics.include? 'MEM_READ'
				if s.characteristics.include? 'MEM_EXECUTE'
					s.characteristics |= ['CONTAINS_CODE']
				elsif s.encoded
					if s.encoded.rawsize == 0
						s.characteristics |= ['CONTAINS_UDATA']
					else
						s.characteristics |= ['CONTAINS_DATA']
					end
				end
			end
			s.rawaddr = nil if s.rawaddr.kind_of?(::Integer)	
			s_table << s.encode(self)
		}
		@optheader.image_size   ||= new_label('image_size')
		@optheader.image_base   ||= label_at(@encoded, 0)
		@optheader.headers_size ||= new_label('headers_size')
		@optheader.checksum     ||= new_label('checksum')
		@optheader.subsystem    ||= 'WINDOWS_GUI'
		@optheader.numrva = nil
		opth = @optheader.encode(self)
		@header.machine ||= 'UNKNOWN'
		@header.num_sect ||= sections.length
		@header.time ||= Time.now.to_i & -255
		@header.size_opthdr ||= opth.virtsize
		@encoded << @header.encode(self) << opth << s_table
	end
def encode_header s_table = EncodedData . new @sections . each { | s | if s . characteristics . kind_of? Array and s . characteristics . include? 'MEM_READ' if s . characteristics . include? 'MEM_EXECUTE' s . characteristics |= [ 'CONTAINS_CODE' ] elsif s . encoded if s . encoded . rawsize == 0 s . characteristics |= [ 'CONTAINS_UDATA' ] else s . characteristics |= [ 'CONTAINS_DATA' ] end end end s . rawaddr = nil if s . rawaddr . kind_of? ( :: Integer ) s_table << s . encode ( self ) } @optheader . image_size ||= new_label ( 'image_size' ) @optheader . image_base ||= label_at ( @encoded , 0 ) @optheader . headers_size ||= new_label ( 'headers_size' ) @optheader . checksum ||= new_label ( 'checksum' ) @optheader . subsystem ||= 'WINDOWS_GUI' @optheader . numrva = nil opth = @optheader . encode ( self ) @header . machine ||= 'UNKNOWN' @header . num_sect ||= sections . length @header . time ||= Time . now . to_i & - 255 @header . size_opthdr ||= opth . virtsize @encoded << @header . encode ( self ) << opth << s_table end
appends the header/optheader/directories/section table to @encoded
appends the header / optheader / directories / section table to @encoded
# encode section table, add CONTAINS_* flags from other characteristics flags # XXX allow to force rawaddr ? # encode optional header # encode header