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__/dynamic.cpython-39.pyc
a

�#�_�5�@s�ddlZddlmZddlmZmZddlmZmZddl	m
Z
ddlmZddl
mZd	d
lmZd	dlmZmZmZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�dee�ZGdd�dee�ZdS)�N)�defaultdict�)�ELFHashTable�GNUHashTable)�Section�Symbol)�
ENUM_D_TAG)�Segment)�RelocationTable�)�ELFError)�
elf_assert�struct_parse�parse_cstring_from_streamc@s eZdZdZdd�Zdd�ZdS)�_DynamicStringTablez� Bare string table based on values found via ELF dynamic tags and
        loadable segments only.  Good enough for get_string() only.
    cCs||_||_dS)N)�_stream�
_table_offset)�self�stream�table_offset�r�8/usr/lib/python3.9/site-packages/elftools/elf/dynamic.py�__init__sz_DynamicStringTable.__init__cCs$t|j|j|�}|r |�d�SdS)zI Get the string stored at the given offset in this string table.
        zutf-8�)rrr�decode)r�offset�srrr�
get_stringsz_DynamicStringTable.get_stringN)�__name__�
__module__�__qualname__�__doc__rrrrrrrsrc@s<eZdZdZegd��Zdd�Zdd�Zdd�Zd	d
�Z	dS)�
DynamicTaga� Dynamic Tag object - representing a single dynamic tag entry from a
        dynamic section.

        Allows dictionary-like access to the dynamic structure. For special
        tags (those listed in the _HANDLED_TAGS set below), creates additional
        attributes for convenience. For example, .soname will contain the actual
        value of DT_SONAME (fetched from the dynamic symbol table).
    )Z	DT_NEEDEDZDT_RPATHZ
DT_RUNPATHZ	DT_SONAMEZDT_SUNW_FILTERcCsJ|durtd��||_|j|jvrFt||jdd���|�|jj��dS)Nz(Creating DynamicTag without string table�)r�entry�d_tag�
_HANDLED_TAGS�setattr�lowerr�d_val)rr$�stringtablerrrr1s�zDynamicTag.__init__cCs
|j|S)z/ Implement dict-like access to entries
        )r$)r�namerrr�__getitem__9szDynamicTag.__getitem__cCsd|jj|jfS)Nz<DynamicTag (%s): %r>)r$r%�rrrr�__repr__>szDynamicTag.__repr__cCsJ|jj|jvr.dt||jjdd����}nd|jj}d|jj|fS)Nz"%s"r#z%#xz<DynamicTag (%s) %s>)r$r%r&�getattrr(�d_ptr)rrrrr�__str__As zDynamicTag.__str__N)
rrr r!�	frozensetr&rr,r.r1rrrrr"$s�r"c@s\eZdZdZdd�Zdd�Zdd�Zdd	d
�Zddd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�DynamiczA Shared functionality between dynamic sections and segments.
    cCsF||_|j|_||_|sdnd|_||_|jj��|_||_	||_
dS)a�
        stream:
            The file-like object from which to load data

        elffile:
            The parent elffile object

        stringtable:
            A stringtable reference to use for parsing string references in
            entries

        position:
            The file offset of the dynamic segment/section

        empty:
            Whether this is a degenerate case with zero entries. Normally, every
            dynamic table will have at least one entry, the DT_NULL terminator.
        ���rN)�elffileZstructs�
elfstructsr�	_num_tags�_offset�Elf_Dyn�sizeof�_tagsize�_empty�_stringtable)rrr5r*Zposition�emptyrrrrLszDynamic.__init__cCsDd}|j|d�D]}|d}q"qd}|r<t|j�|�d�}||fS)zH Return the virtual address and file offset of a dynamic table.
        N��typer0)�
_iter_tags�nextr5Zaddress_offsets)rZtag_nameZptr�tagrrrr�get_table_offsetjszDynamic.get_table_offsetcCsJ|jr|jS|�d�\}}|dur6t|j|�|_|jS|j�d�|_|jS)z� Return a string table for looking up dynamic tag related strings.

            This won't be a "full" string table object, but will at least
            support the get_string() function.
        Z	DT_STRTABNz.dynstr)r=rDrrr5Zget_section_by_name)r�_rrrr�_get_stringtablezszDynamic._get_stringtableNccsP|jr
dSt��D]8}|�|�}|dus4|d|kr:|V|ddkrqLqdS)z; Yield all raw tags (limit to |type| if specified)
        Nr%�DT_NULL)r<�	itertools�count�_get_tag)rr@�nrCrrrrA�s
zDynamic._iter_tagsccs&|j|d�D]}t||���VqdS)z7 Yield all tags (limit to |type| if specified)
        r?N)rAr"rF)rr@rCrrr�	iter_tags�szDynamic.iter_tagscCs@|jdkr||jkrt|��|j||j}t|jj|j|d�S)z3 Get the raw tag at index #n from the file
        r4)Z
stream_pos)r7�
IndexErrorr8r;rr6r9r)rrKrrrrrJ�s�zDynamic._get_tagcCst|�|�|���S)zC Get the tag at index #n from the file (DynamicTag object)
        )r"rJrF)rrKrrr�get_tag�szDynamic.get_tagcCsL|jdkr|jSt��D].}|�|�}|jjdkr|d|_|jSqdS)zG Number of dynamic tags in the file, including the DT_NULL tag
        r4rGrN)r7rHrIrNr$r%)rrKrCrrr�num_tags�s


zDynamic.num_tagscCs"i}t|�d��rht|j|�d�dt|�d��dd�|d<t|�d��d}t|dj|kd|�t|�d	��r�t|j|�d	�dt|�d
��dd�|d<t|�d
��d}t|dj|kd|�t|�d���rt|j|�d�dt|�d��dt|�d��dtd	k�|d<|S)z� Load all available relocation tables from DYNAMIC tags.

            Returns a dictionary mapping found table types (REL, RELA,
            JMPREL) to RelocationTable objects.
        ZDT_RELrZDT_RELSZr)FZRELZ	DT_RELENTzExpected DT_RELENT to be %sZDT_RELAZ	DT_RELASZTZRELAZ
DT_RELAENTzExpected DT_RELAENT to be %sZ	DT_JMPRELZDT_PLTRELSZZ	DT_PLTRELZJMPREL)	�listrLr
r5rDrBr
Z
entry_sizer)r�resultZrelentszrrr�get_relocation_tables�s4�����zDynamic.get_relocation_tables)N)N)
rrr r!rrDrFrArLrJrNrOrRrrrrr3Is

r3c@seZdZdZdd�ZdS)�DynamicSectionzH ELF dynamic table section.  Knows how to process the list of tags.
    c	CsFt�||||�|�|d�}t�||j|j||d|ddk�dS)N�sh_link�	sh_offsetZsh_typeZ
SHT_NOBITS)rr�get_sectionr3rr5)r�headerr+r5r*rrrr�s
�zDynamicSection.__init__N)rrr r!rrrrrrS�srSc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�DynamicSegmentzH ELF dynamic table segment.  Knows how to process the list of tags.
    c	Cs|d}|��D]0}t|t�r|d|dkr|�|d�}q>qt�|||�t�|||||d|ddk�d|_d|_dS)NrUZp_offsetrT�p_fileszr)	Z
iter_sections�
isinstancerSrVr	rr3�_symbol_list�_symbol_name_map)rrWrr5r*�sectionrrrr�s
�
�zDynamicSegment.__init__cCs"|jdurt|���|_t|j�S)zA Number of symbols in the table recovered from DT_SYMTAB
        N)r[rP�iter_symbols�lenr-rrr�num_symbolss
zDynamicSegment.num_symbolscCs"|jdurt|���|_|j|S)zG Get the symbol at index #index from the table (Symbol object)
        N)r[rPr^)r�indexrrr�
get_symbol	s
zDynamicSegment.get_symbolcsb�jdur<tt��_t����D]\}}�j|j�|�q �j�|�}|r^�fdd�|D�SdS)za Get a symbol(s) by name. Return None if no symbol by the given name
            exists.
        Ncsg|]}��|��qSr)rb)�.0�ir-rr�
<listcomp>�z5DynamicSegment.get_symbol_by_name.<locals>.<listcomp>)r\rrP�	enumerater^r+�append�get)rr+rdZsymZsymnumsrr-r�get_symbol_by_names

z!DynamicSegment.get_symbol_by_nameccs�|�d�\}}|dus|dur&td��|jj��}d}|�d�\}}|durjt|j||�}||��|}|dur�|�d�\}}|dur�t|j||�}||��|}|du�rhd}	|�	�D]V}
|
d}|
ddkr�||
d	kr�td
|
d	|f��||kr�|	du�s|	|kr�|}	q�|	du�rd|j�
�D]:}|d|k�r(||d|dk�r(|d|d}	�q(|	}|du�rztd
��|��}
t|||�D]:}t
|jj|j|||�}|
�|d�}t||�V�q�dS)a0 Yield all symbols in this dynamic segment. The symbols are usually
            the same as returned by SymbolTableSection.iter_symbols. However,
            in stripped binaries, SymbolTableSection might have been removed.
            This method reads from the mandatory dynamic tag DT_SYMTAB.
        Z	DT_SYMTABNz#Segment does not contain DT_SYMTAB.ZDT_GNU_HASHZDT_HASHr0r%Z	DT_SYMENTr)zDT_SYMENT (%d) != Elf_Sym (%d).Zp_vaddrrYz&Cannot determine the end of DT_SYMTAB.Zst_name)rDrr6ZElf_Symr:rr5Zget_number_of_symbolsrrLZ
iter_segmentsrF�rangerrrr)rZtab_ptrZ
tab_offsetZsymbol_sizeZend_ptrrEZgnu_hash_offsetZhash_sectionZhash_offsetZnearest_ptrrCZtag_ptrZsegmentZstring_tablerd�symbolZsymbol_namerrrr^sb
�
�

���
�

�zDynamicSegment.iter_symbolsN)	rrr r!rr`rbrjr^rrrrrX�srX)rH�collectionsr�hashrrZsectionsrrZenumsr�segmentsr	Z
relocationr
Zcommon.exceptionsrZcommon.utilsr
rr�objectrr"r3rSrXrrrr�<module>	s%