node/lib/metasm/metasm/exe_format/elf_encode.rb
def encode_add_section s
		# order: r rx rw noalloc
		rank = lambda { |sec|
			f = sec.flags
			sec.type == 'NULL' ? -2 : sec.addr ? -1 :
			f.include?('ALLOC') ? !f.include?('WRITE') ? !f.include?('EXECINSTR') ? 0 : 1 : 2 : 3
		}
		srank = rank[s]
		nexts = @sections.find { |sec| rank[sec] > srank }	# find section with rank superior
		nexts = nexts ? @sections.index(nexts) : -1		# if none, last
		if @header.shstrndx.to_i != 0 and nexts != -1 and @header.shstrndx >= nexts
			@header.shstrndx += 1
		end
		@sections.insert(nexts, s)				# insert section
	end
# sorted insert of a new section to self.sections according to its permission (for segment merging)
sorted insert of a new section to self.sections according to its permission (for segment merging)
sorted insert of a new section to self . sections according to its permission ( for segment merging )
def encode_add_section s
		rank = lambda { |sec|
			f = sec.flags
			sec.type == 'NULL' ? -2 : sec.addr ? -1 :
			f.include?('ALLOC') ? !f.include?('WRITE') ? !f.include?('EXECINSTR') ? 0 : 1 : 2 : 3
		}
		srank = rank[s]
		nexts = @sections.find { |sec| rank[sec] > srank }	
		nexts = nexts ? @sections.index(nexts) : -1		
		if @header.shstrndx.to_i != 0 and nexts != -1 and @header.shstrndx >= nexts
			@header.shstrndx += 1
		end
		@sections.insert(nexts, s)				
	end
def encode_add_section s rank = lambda { | sec | f = sec . flags sec . type == 'NULL' ? - 2 : sec . addr ? - 1 : f . include? ( 'ALLOC' ) ? ! f . include? ( 'WRITE' ) ? ! f . include? ( 'EXECINSTR' ) ? 0 : 1 : 2 : 3 } srank = rank [ s ] nexts = @sections . find { | sec | rank [ sec ] > srank } nexts = nexts ? @sections . index ( nexts ) : - 1 if @header . shstrndx . to_i != 0 and nexts != - 1 and @header . shstrndx >= nexts @header . shstrndx += 1 end @sections . insert ( nexts , s ) end
sorted insert of a new section to self.sections according to its permission (for segment merging)
sorted insert of a new section to self . sections according to its permission ( for segment merging )
# order: r rx rw noalloc # find section with rank superior # if none, last # insert section
s