node/lib/metasm/metasm/exe_format/elf_decode.rb
# returns the Metasm::Relocation that should be applied for reloc
# self.encoded.ptr must point to the location that will be relocated (for implicit addends)
returns the Metasm::Relocation that should be applied for reloc
self.encoded.ptr must point to the location that will be relocated (for implicit addends)
returns the Metasm :: Relocation that should be applied for reloc self . encoded . ptr must point to the location that will be relocated ( for implicit addends )
def arch_decode_segments_reloc_x86_64(reloc)
		if reloc.symbol.kind_of?(Symbol) and n = reloc.symbol.name and reloc.symbol.shndx == 'UNDEF' and @sections and
			s = @sections.find { |s_| s_.name and s_.offset <= @encoded.ptr and s_.offset + s_.size > @encoded.ptr }
			@encoded.add_export(new_label("#{s.name}_#{n}"), @encoded.ptr, true)
		end
		case reloc.type
		when 'NONE' 
		when '32', 'PC32'; addend = reloc.addend || decode_sword
		else addend = reloc.addend || decode_sxword
		end
		sz = :u64
		case reloc.type
		when 'NONE'
		when 'RELATIVE'
			target = addend
			if o = addr_to_off(target)
				if not label = @encoded.inv_export[o]
					label = new_label("xref_#{Expression[target]}")
					@encoded.add_export label, o
				end
				target = label
			else
				puts "W: Elf: relocation pointing out of mmaped space #{reloc.inspect}" if $VERBOSE
			end
		when 'GLOB_DAT', 'JMP_SLOT', '64', 'PC64', '32', 'PC32'
			target = reloc_target(reloc)
			target = Expression[target, :-, reloc.offset] if reloc.type == 'PC64' or reloc.type == 'PC32'
			target = Expression[target, :+, addend] if addend and addend != 0
			sz = :u32 if reloc.type == '32' or reloc.type == 'PC32'
		when 'COPY'
			if not reloc.symbol.kind_of?(Symbol) or not name = reloc.symbol.name
				puts "W: Elf: symbol to COPY has no name: #{reloc.inspect}" if $VERBOSE
				name = ''
			end
			name = new_label("copy_of_#{name}")
			@encoded.add_export name, @encoded.ptr
			target = nil
		else
			puts "W: Elf: unhandled X86_64 reloc #{reloc.inspect}" if $VERBOSE
			target = nil
		end
		Metasm::Relocation.new(Expression[target], sz, @endianness) if target
	end
def arch_decode_segments_reloc_x86_64 ( reloc ) if reloc . symbol . kind_of? ( Symbol ) and n = reloc . symbol . name and reloc . symbol . shndx == 'UNDEF' and @sections and s = @sections . find { | s_ | s_ . name and s_ . offset <= @encoded . ptr and s_ . offset + s_ . size > @encoded . ptr } @encoded . add_export ( new_label ( "#{s.name}_#{n}" ) , @encoded . ptr , true ) end case reloc . type when 'NONE' when '32' , 'PC32' ; addend = reloc . addend || decode_sword else addend = reloc . addend || decode_sxword end sz = :u64 case reloc . type when 'NONE' when 'RELATIVE' target = addend if o = addr_to_off ( target ) if not label = @encoded . inv_export [ o ] label = new_label ( "xref_#{Expression[target]}" ) @encoded . add_export label , o end target = label else puts "W: Elf: relocation pointing out of mmaped space #{reloc.inspect}" if $VERBOSE end when 'GLOB_DAT' , 'JMP_SLOT' , '64' , 'PC64' , '32' , 'PC32' target = reloc_target ( reloc ) target = Expression [ target , :- , reloc . offset ] if reloc . type == 'PC64' or reloc . type == 'PC32' target = Expression [ target , :+ , addend ] if addend and addend != 0 sz = :u32 if reloc . type == '32' or reloc . type == 'PC32' when 'COPY' if not reloc . symbol . kind_of? ( Symbol ) or not name = reloc . symbol . name puts "W: Elf: symbol to COPY has no name: #{reloc.inspect}" if $VERBOSE name = '' end name = new_label ( "copy_of_#{name}" ) @encoded . add_export name , @encoded . ptr target = nil else puts "W: Elf: unhandled X86_64 reloc #{reloc.inspect}" if $VERBOSE target = nil end Metasm :: Relocation . new ( Expression [ target ] , sz , @endianness ) if target end
returns the Metasm::Relocation that should be applied for reloc
self.encoded.ptr must point to the location that will be relocated (for implicit addends)
returns the Metasm :: Relocation that should be applied for reloc self . encoded . ptr must point to the location that will be relocated ( for implicit addends )
# decode addend if needed # no addend # base = @segments.find_all { |s| s.type == 'LOAD' }.map { |s| s.vaddr }.min & 0xffff_f000 # compiled to be loaded at seg.vaddr # XXX use versionned version # lazy jmp_slot ? # mark the address pointed as a copy of the relocation target
reloc