HEX
Server: LiteSpeed
System: Linux br-asc-web1845.main-hosting.eu 5.14.0-611.42.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Mar 24 05:30:20 EDT 2026 x86_64
User: u790421558 (790421558)
PHP: 8.2.30
Disabled: system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //lib/python3.9/site-packages/elftools/elf/__pycache__/relocation.cpython-39.pyc
a

�#�_�/�@s�ddlmZddlmZddlmZmZddlmZddl	m
Z
mZmZm
Z
mZmZGdd	�d	e�ZGd
d�de�ZGdd
�d
ee�ZGdd�de�ZdS)�)�
namedtuple�)�ELFRelocationError)�
elf_assert�struct_parse�)�Section)�ENUM_RELOC_TYPE_i386�ENUM_RELOC_TYPE_x64�ENUM_RELOC_TYPE_MIPS�ENUM_RELOC_TYPE_ARM�ENUM_RELOC_TYPE_AARCH64�
ENUM_D_TAGc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�
Relocationz� Relocation object - representing a single relocation entry. Allows
        dictionary-like access to the entry's fields.

        Can be either a REL or RELA relocation.
    cCs||_||_dS�N)�entry�elffile)�selfrr�r�;/usr/lib/python3.9/site-packages/elftools/elf/relocation.py�__init__szRelocation.__init__cCs
d|jvS)z6 Is this a RELA relocation? If not, it's REL.
        �r_addend�r�rrrr�is_RELAszRelocation.is_RELAcCs
|j|S)z% Dict-like access to entries
        r)r�namerrr�__getitem__"szRelocation.__getitem__cCsd|��rdnd|jfS)Nz<Relocation (%s): %s>ZRELAZREL)rrrrrr�__repr__'s�zRelocation.__repr__cCs|��Sr)rrrrr�__str__,szRelocation.__str__N)	�__name__�
__module__�__qualname__�__doc__rrrrrrrrrrsrc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�RelocationTablezL Shared functionality between relocation sections and relocation tables
    cCsR|j|_||_|j|_||_||_||_|r8|jj|_	n
|jj
|_	|j	��|_dSr)
�stream�_stream�_elffile�structsZ_elfstructs�_size�_offset�_is_relaZElf_Rela�entry_structZElf_RelZsizeof�
entry_size)rr�offset�sizeZis_relarrrr4s
zRelocationTable.__init__cCs|jS)z> Is this a RELA relocation section? If not, it's REL.
        )r*rrrrrCszRelocationTable.is_RELAcCs|j|jS)z. Number of relocations in the section
        )r(r,rrrr�num_relocationsHszRelocationTable.num_relocationscCs.|j||j}t|j|j|d�}t||j�S)zM Get the relocation at index #n from the section (Relocation object)
        �Z
stream_pos)r)r,rr+r%rr&)r�nZentry_offsetrrrr�get_relocationMs�zRelocationTable.get_relocationccs"t|���D]}|�|�VqdS)z2 Yield all the relocations in the section
        N)�ranger/r2)r�irrr�iter_relocationsWsz RelocationTable.iter_relocationsN)	rr r!r"rrr/r2r5rrrrr#0s
r#c@seZdZdZdd�ZdS)�RelocationSectionzK ELF relocation section. Serves as a collection of Relocation entries.
    cCslt�||||�t�||j|d|d|ddk�t|ddvd�t|d|jkd|d|jf�dS)	NZ	sh_offsetZsh_sizeZsh_type�SHT_RELA)ZSHT_RELr7zUnknown relocation type sectionZ
sh_entsizez*Expected sh_entsize of %s section to be %s)rrr#rrr,)r�headerrrrrrras
��
��zRelocationSection.__init__N)rr r!r"rrrrrr6^sr6c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zed
d�Z	d.d
d�Z
d/dd�Zd0dd�Zd1dd�Z
d2dd�Zd3dd�Zede	dded�ede	dded�iZede	dd e
d�ed!e	dd e
d�ed"e	dd ed�iZed#e	dde
d�ed$e	dded�iZed%e	dde
d�ed&e	dded�ed'e	dded�iZed(e	dd e
d�ed)e	dd e
d�ed*e	dd ed�ed+e	dd e
d�ed,e	dd e
d�iZd-S)4�RelocationHandlerz4 Handles the logic of relocations in ELF files.
    cCs
||_dSr)r)rrrrrrpszRelocationHandler.__init__cCsDd|jd|jf}|j��D] }t|t�r|j|vr|SqdS)z� Given a section, find the relocation section for it in the ELF
            file. Return a RelocationSection object, or None if none was
            found.
        z.relz.relaN)rrZ
iter_sections�
isinstancer6)r�sectionZreloc_section_namesZ
relsectionrrr�find_relocations_for_sectionss�
�
z.RelocationHandler.find_relocations_for_sectioncCs0|j�|d�}|��D]}|�|||�qdS)z� Apply all relocations in reloc_section (a RelocationSection object)
            to the given stream, that contains the data of the section that is
            being relocated. The stream is modified as a result.
        Zsh_linkN)rZget_sectionr5�_do_apply_relocation)rr$Z
reloc_section�symtab�relocrrr�apply_section_relocations�sz+RelocationHandler.apply_section_relocationsc
Cs�|d|��kr td|d��|�|d�d}|d}d}|j��dkrp|��r`td|��|j�|d�}n�|j��dkr�|��s�td|��|j�|d�}n�|j��d	kr�|��r�td
|��|j	�|d�}nR|j��dk�r|��r�td|��|j
�|d�}n|j��d
k�r&|j�|d�}|du�r<td|��|jdk�rX|jj
�d�}n*|jdk�rt|jj
�d�}ntd|j��t|||dd�}|j|||d|j�r�|dndd�}	|�|d�|	d|jd}	|�|	|�dS)NZ
r_info_symz0Invalid symbol reference in relocation: index %sZst_valueZr_info_typeZx86z&Unexpected RELA relocation for x86: %sZx64z%Unexpected REL relocation for x64: %sZMIPSz'Unexpected RELA relocation for MIPS: %sZARMz&Unexpected RELA relocation for ARM: %sZAArch64zUnsupported relocation type: %s���z"Invalid bytesize %s for relocationZr_offsetr0rr��value�	sym_valuer-Zaddendr)Znum_symbolsrZ
get_symbolrZget_machine_archr�_RELOCATION_RECIPES_X86�get�_RELOCATION_RECIPES_X64�_RELOCATION_RECIPES_MIPS�_RELOCATION_RECIPES_ARM�_RELOCATION_RECIPES_AARCH64�bytesizer'ZElf_wordZ
Elf_word64r�	calc_func�
has_addend�seekZbuild_stream)
rr$r?r>rFZ
reloc_typeZrecipeZvalue_struct�original_valueZrelocated_valuerrrr=�sx������
����z&RelocationHandler._do_apply_relocation�_RELOCATION_RECIPE_TYPEzbytesize has_addend calc_funcrcCs|SrrrDrrr�_reloc_calc_identity�sz&RelocationHandler._reloc_calc_identitycCs||SrrrDrrr�_reloc_calc_sym_plus_value�sz,RelocationHandler._reloc_calc_sym_plus_valuecCs|||SrrrDrrr� _reloc_calc_sym_plus_value_pcrel�sz2RelocationHandler._reloc_calc_sym_plus_value_pcrelcCs||SrrrDrrr�_reloc_calc_sym_plus_addend�sz-RelocationHandler._reloc_calc_sym_plus_addendcCs|||SrrrDrrr�!_reloc_calc_sym_plus_addend_pcrel�sz3RelocationHandler._reloc_calc_sym_plus_addend_pcrelcCs|d||dS)NrArrDrrr�$_arm_reloc_calc_sym_plus_value_pcrel�sz6RelocationHandler._arm_reloc_calc_sym_plus_value_pcrelZR_ARM_ABS32rAF)rMrOrNZ
R_ARM_CALLZR_AARCH64_ABS64rCTZR_AARCH64_ABS32ZR_AARCH64_PREL32ZR_MIPS_NONEZ	R_MIPS_32Z
R_386_NONEZR_386_32Z
R_386_PC32Z
R_X86_64_NONEZR_X86_64_64Z
R_X86_64_PC32ZR_X86_64_32ZR_X86_64_32SN)r)r)r)r)r)r)rr r!r"rr<r@r=rrRrSrTrUrVrWrXrrKr
rLrrJr	rGr
rIrrrrr9ms�
Q�





���
�������	����������r9N)�collectionsrZcommon.exceptionsrZcommon.utilsrrZsectionsrZenumsr	r
rrr
r�objectrr#r6r9rrrr�<module>	s .