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_mips(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
		original_word = decode_word
		case reloc.type
		when 'NONE' 
		else addend = reloc.addend || Expression.make_signed(original_word, 32)
		end
		case reloc.type
		when 'NONE'
		when '32', 'REL32'
			target = reloc_target(reloc)
			target = Expression[target, :-, reloc.offset] if reloc.type == 'REL32'
			target = Expression[target, :+, addend] if addend and addend != 0
		when '26'
			target = reloc_target(reloc)
			addend &= 0x3ff_ffff
			target = Expression[target, :+, [addend, :<<, 2]] if addend and addend != 0
			target = Expression[[original_word, :&, 0xfc0_0000], :|, [[target, :&, 0x3ff_ffff], :>>, 2]]
		when 'HI16'
			target = reloc_target(reloc)
			addend &= 0xffff
			target = Expression[target, :+, [addend, :<<, 16]] if addend and addend != 0
			target = Expression[[original_word, :&, 0xffff_0000], :|, [[target, :>>, 16], :&, 0xffff]]
		when 'LO16'
			target = reloc_target(reloc)
			addend &= 0xffff
			target = Expression[target, :+, addend] if addend and addend != 0
			target = Expression[[original_word, :&, 0xffff_0000], :|, [target, :&, 0xffff]]
		else
			puts "W: Elf: unhandled MIPS reloc #{reloc.inspect}" if $VERBOSE
			target = nil
		end
		Metasm::Relocation.new(Expression[target], :u32, @endianness) if target
	end
def arch_decode_segments_reloc_mips ( 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 original_word = decode_word case reloc . type when 'NONE' else addend = reloc . addend || Expression . make_signed ( original_word , 32 ) end case reloc . type when 'NONE' when '32' , 'REL32' target = reloc_target ( reloc ) target = Expression [ target , :- , reloc . offset ] if reloc . type == 'REL32' target = Expression [ target , :+ , addend ] if addend and addend != 0 when '26' target = reloc_target ( reloc ) addend &= 0x3ff_ffff target = Expression [ target , :+ , [ addend , :<< , 2 ] ] if addend and addend != 0 target = Expression [ [ original_word , :& , 0xfc0_0000 ] , :| , [ [ target , :& , 0x3ff_ffff ] , :>> , 2 ] ] when 'HI16' target = reloc_target ( reloc ) addend &= 0xffff target = Expression [ target , :+ , [ addend , :<< , 16 ] ] if addend and addend != 0 target = Expression [ [ original_word , :& , 0xffff_0000 ] , :| , [ [ target , :>> , 16 ] , :& , 0xffff ] ] when 'LO16' target = reloc_target ( reloc ) addend &= 0xffff target = Expression [ target , :+ , addend ] if addend and addend != 0 target = Expression [ [ original_word , :& , 0xffff_0000 ] , :| , [ target , :& , 0xffff ] ] else puts "W: Elf: unhandled MIPS reloc #{reloc.inspect}" if $VERBOSE target = nil end Metasm :: Relocation . new ( Expression [ target ] , :u32 , @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
reloc