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

�#�_B�@shddlZddlmZddlmZGdd�de�ZGdd	�d	ee�ZGd
d�de�ZGdd
�d
ee�Z	dS)�N�)�struct_parse�)�Sectionc@s4eZdZdZdd�Zdd�Zdd�Zedd	��Zd
S)�ELFHashTablea� Representation of an ELF hash table to find symbols in the
        symbol table - useful for super-stripped binaries without section
        headers where only the start of the symbol table is known from the
        dynamic segment. The layout and contents are nicely described at
        https://flapenguin.me/2017/04/24/elf-lookup-dt-hash/.

        The symboltable argument needs to implement a get_symbol() method -
        in a regular ELF file, this will be the linked symbol table section
        as indicated by the sh_link attribute. For super-stripped binaries,
        one should use the DynamicSegment object as the symboltable as it
        supports symbol lookup without access to a symbol table section.
    cCs(||_||_t|jjj|jj|�|_dS)N)�elffile�_symboltabler�structsZElf_Hash�stream�params��selfrZstart_offset�symboltable�r�5/usr/lib/python3.9/site-packages/elftools/elf/hash.py�__init__s
�zELFHashTable.__init__cCs
|jdS)zC Get the number of symbols from the hash table parameters.
        Znchains)r)r
rrr�get_number_of_symbols%sz"ELFHashTable.get_number_of_symbolscCsj|jddkrdS|�|�|jd}|jd|}|dkrf|j�|�}|j|krV|S|jd|}q4dS)�D Look up a symbol from this hash table with the given name.
        �nbucketsrN�bucketsZchains)r�elf_hashr�
get_symbol�name)r
rZhvalZsymndxZsymrrrr*s
zELFHashTable.get_symbolcCs`t|t�s|�d�}d}d}t|�D]6}|d>|}|d@}|dkrP||d?N}||M}q$|S)z9 Compute the hash value for a given symbol name.
        �utf-8r�l`���
isinstance�bytes�encode�	bytearray)r�h�x�crrrr8s

zELFHashTable.elf_hashN)	�__name__�
__module__�__qualname__�__doc__rrr�staticmethodrrrrrrs
rc@seZdZdZdd�ZdS)�ELFHashSectionz� Section representation of an ELF hash table. In regular ELF files, this
        allows us to use the common functions defined on Section objects when
        dealing with the hash table.
    cCs(t�||||�t�|||d|�dS�NZ	sh_offset)rrr�r
�headerrrrrrrrNszELFHashSection.__init__N�r$r%r&r'rrrrrr)Isr)c@s<eZdZdZdd�Zdd�Zdd�Zdd	�Zed
d��Z	dS)
�GNUHashTablea� Representation of a GNU hash table to find symbols in the
        symbol table - useful for super-stripped binaries without section
        headers where only the start of the symbol table is known from the
        dynamic segment. The layout and contents are nicely described at
        https://flapenguin.me/2017/05/10/elf-lookup-dt-gnu-hash/.

        The symboltable argument needs to implement a get_symbol() method -
        in a regular ELF file, this will be the linked symbol table section
        as indicated by the sh_link attribute. For super-stripped binaries,
        one should use the DynamicSegment object as the symboltable as it
        supports symbol lookup without access to a symbol table section.
    cCs�||_||_t|jjj|jj|�|_|jj�d���|_	|jj�
d���|_|d|j	|jd|j|jd|j	|_dS)N�r�
bloom_sizer)
rrrr	ZGnu_Hashr
rZElf_wordZsizeof�	_wordsizeZ	Elf_xwordZ
_xwordsize�
_chain_posrrrrr`s
���zGNUHashTable.__init__cCs�t|jd�}||jdkr&|jdS|j||jd|j}|jj�|�|jjrZdnd}t�	||jj�
|j��d}|d@r�|dS|d7}q^dS)z� Get the number of symbols in the hash table by finding the bucket
            with the highest symbol index and walking to the end of its chain.
        r�	symoffset�<I�>IrrN)�maxrr2r1rr
�seek�
little_endian�struct�unpack�read)r
Zmax_idxZ
max_chain_pos�hash_format�cur_hashrrrrms
�z"GNUHashTable.get_number_of_symbolscCsZ|jj}||jd?}t||�|jd}d||>d||>B}|jd||@|kS)z� Helper function to check if the given hash could be in the hash
            table by testing it against the bloom filter.
        Zbloom_shiftr0rZbloom)rZelfclassr�int)r
ZH1Z	arch_bitsZH2Zword_idxZBITMASKrrr�_matches_bloom�s
zGNUHashTable._matches_bloomcCs�|�|�}|�|�sdS|jd||jd}||jdkrBdS|jj�|j||jd|j�|jjrrdnd}t	�
||jj�|j��d}|dB|dBkr�|j�
|�}||jkr�|S|d@r�q�|d7}qvdS)	rNrrr3r4r5rr)�gnu_hashr?rrr
r7r2r1r8r9r:r;rrr)r
rZnamehashZsymidxr<r=�symbolrrrr�s"

$

zGNUHashTable.get_symbolcCs:t|t�s|�d�}d}t|�D]}|d|}q |d@S)zC Compute the GNU-style hash value for a given symbol name.
        ri�!l��r)�keyr!r#rrrr@�s

zGNUHashTable.gnu_hashN)
r$r%r&r'rrr?rr(r@rrrrr.Ss

r.c@seZdZdZdd�ZdS)�GNUHashSectionz� Section representation of a GNU hash table. In regular ELF files, this
        allows us to use the common functions defined on Section objects when
        dealing with the hash table.
    cCs(t�||||�t�|||d|�dSr*)rrr.r+rrrr�szGNUHashSection.__init__Nr-rrrrrD�srD)
r9Zcommon.utilsrZsectionsr�objectrr)r.rDrrrr�<module>
s9
`