Ë
    ÖùdB  ã                   ó€   — d dl Z ddlmZ ddlmZ  G d„ de«      Z G d„ d	ee«      Z G d
„ de«      Z G d„ dee«      Z	y)é    Né   )Ústruct_parseé   )ÚSectionc                   ó2   — e Zd ZdZd„ Zd„ Zd„ Zed„ «       Zy)Ú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.
    c                 ó¨   — || _         || _        t        | j                   j                  j                  | j                   j
                  |«      | _        y )N)ÚelffileÚ_symboltabler   ÚstructsÚElf_HashÚstreamÚparams©Úselfr
   Ústart_offsetÚsymboltables       ú3/usr/lib/python3/dist-packages/elftools/elf/hash.pyÚ__init__zELFHashTable.__init__   s?   € ØˆŒØ'ˆÔÜ" 4§<¡<×#7Ñ#7×#@Ñ#@Ø#'§<¡<×#6Ñ#6Ø#/ó1ˆ�ó    c                 ó    — | j                   d   S )zC Get the number of symbols from the hash table parameters.
        Únchains)r   )r   s    r   Úget_number_of_symbolsz"ELFHashTable.get_number_of_symbols%   s   € ð �{‰{˜9Ñ%Ð%r   c                 ó"  — | j                   d   dk(  ry| j                  |«      | j                   d   z  }| j                   d   |   }|dk7  rD| j                  j                  |«      }|j                  |k(  r|S | j                   d   |   }|dk7  rŒDy)úD Look up a symbol from this hash table with the given name.
        Únbucketsr   NÚbucketsÚchains)r   Úelf_hashr   Ú
get_symbolÚname)r   r!   ÚhvalÚsymndxÚsyms        r   r    zELFHashTable.get_symbol*   s–   € ð �;‰;�zÑ" aÒ'ØØ�}‰}˜TÓ" T§[¡[°Ñ%<Ñ<ˆØ—‘˜YÑ'¨Ñ-ˆØ˜ŠkØ×#Ñ#×.Ñ.¨vÓ6ˆCØ�x‰x˜4ÒØ�
Ø—[‘[ Ñ*¨6Ñ2ˆFð	 ˜‹kð
 r   c                 ó°   — t        | t        «      s| j                  d«      } d}d}t        | «      D ]"  }|dz  |z   }|dz  }|dk7  r||dz	  z  }|| z  }Œ$ |S )z9 Compute the hash value for a given symbol name.
        úutf-8r   é   l      ` é   ©Ú
isinstanceÚbytesÚencodeÚ	bytearray)r!   ÚhÚxÚcs       r   r   zELFHashTable.elf_hash8   su   € ô ˜$¤Ô&Ø—;‘;˜wÓ'ˆDØˆØˆÜ˜4“ò 	ˆAØ�a‘˜1‘ˆAØ�J‘ˆAØ�AŠvØ�a˜2‘g‘�Ø�!�‰G‰Að	ð ˆr   N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r    Ústaticmethodr   © r   r   r   r      s*   „ ñò1ò&ò
ð ñó ñr   r   c                   ó   — e Zd ZdZd„ Zy)Ú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.
    c                 ój   — t        j                  | |||«       t        j                  | || d   |«       y ©NÚ	sh_offset)r   r   r   ©r   Úheaderr!   r
   r   s        r   r   zELFHashSection.__init__N   ó/   € Ü×Ñ˜˜v t¨WÔ5Ü×Ñ˜d G¨T°+Ñ->ÀÕLr   N©r1   r2   r3   r4   r   r6   r   r   r8   r8   I   ó   „ ñóMr   r8   c                   ó8   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zed„ «       Z	y)Ú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.
    c                 ó*  — || _         || _        t        | j                   j                  j                  | j                   j
                  |«      | _        | j                   j                  j                  d«      j                  «       | _	        | j                   j                  j                  d«      j                  «       | _        |d| j                  z  z   | j                  d   | j                  z  z   | j                  d   | j                  z  z   | _        y )NÚ r'   Ú
bloom_sizer   )r
   r   r   r   ÚGnu_Hashr   r   ÚElf_wordÚsizeofÚ	_wordsizeÚ	Elf_xwordÚ
_xwordsizeÚ
_chain_posr   s       r   r   zGNUHashTable.__init__`   sÔ   € ØˆŒØ'ˆÔÜ" 4§<¡<×#7Ñ#7×#@Ñ#@Ø#'§<¡<×#6Ñ#6Ø#/ó1ˆŒð Ÿ™×-Ñ-×6Ñ6°rÓ:×AÑAÓCˆŒØŸ,™,×.Ñ.×8Ñ8¸Ó<×CÑCÓEˆŒØ&¨¨T¯^©^Ñ);Ñ;Ø�K‰K˜Ñ%¨¯©Ñ7ñ8à�K‰K˜
Ñ# d§n¡nÑ4ñ5ˆ�r   c                 óø  — t        | j                  d   «      }|| j                  d   k  r| j                  d   S | j                  || j                  d   z
  | j                  z  z   }| j                  j
                  j                  |«       | j                  j                  rdnd}	 t        j                  || j                  j
                  j                  | j                  «      «      d   }|dz  r|dz   S |dz  }ŒV)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ú>Ir   r   )Úmaxr   rL   rI   r
   r   ÚseekÚlittle_endianÚstructÚunpackÚread)r   Úmax_idxÚmax_chain_posÚhash_formatÚcur_hashs        r   r   z"GNUHashTable.get_number_of_symbolsm   sà   € ô
 �d—k‘k )Ñ,Ó-ˆØ�T—[‘[ Ñ-Ò-Ø—;‘;˜{Ñ+Ð+ð Ÿ™Ø�t—{‘{ ;Ñ/Ñ/°4·>±>ÑAñBˆà�‰×Ñ× Ñ  Ô/Ø"Ÿl™l×8Ò8‘d¸dˆð Ü—}‘} [°$·,±,×2EÑ2E×2JÑ2JÈ4Ï>É>Ó2ZÓ[Ð\]Ñ^ˆHØ˜!Š|Ø ‘{Ð"à�q‰LˆGð r   c                 óà   — | j                   j                  }|| j                  d   z	  }t        ||z  «      | j                  d   z  }d||z  z  d||z  z  z  }| j                  d   |   |z  |k(  S )zƒ Helper function to check if the given hash could be in the hash
            table by testing it against the bloom filter.
        Úbloom_shiftrE   r   Úbloom)r
   Úelfclassr   Úint)r   ÚH1Ú	arch_bitsÚH2Úword_idxÚBITMASKs         r   Ú_matches_bloomzGNUHashTable._matches_bloom„   s|   € ð —L‘L×)Ñ)ˆ	Ø�4—;‘;˜}Ñ-Ñ-ˆÜ�r˜I‘~Ó&¨¯©°\Ñ)BÑBˆØ˜˜i™Ñ(¨Q°2¸	±>Ñ-BÑCˆØ—‘˜GÑ$ XÑ.°Ñ8¸WÑDÐDr   c                 óš  — | j                  |«      }| j                  |«      sy| j                  d   || j                  d   z     }|| j                  d   k  ry| j                  j                  j                  | j                  || j                  d   z
  | j                  z  z   «       | j                  j                  rdnd}	 t        j                  || j                  j                  j                  | j                  «      «      d   }|dz  |dz  k(  r,| j                  j                  |«      }||j                  k(  r|S |dz  r	 y|dz  }ŒŠ)	r   Nr   r   rN   rO   rP   r   r   )Úgnu_hashre   r   r
   r   rR   rL   rI   rS   rT   rU   rV   r   r    r!   )r   r!   ÚnamehashÚsymidxrY   rZ   Úsymbols          r   r    zGNUHashTable.get_symbolŽ   s,  € ð —=‘= Ó&ˆØ×"Ñ" 8Ô,Øà—‘˜YÑ'¨°4·;±;¸zÑ3JÑ(JÑKˆØ�D—K‘K Ñ,Ò,Øà�‰×Ñ× Ñ  §¡°F¸T¿[¹[ÈÑ=UÑ4UÐY]×YgÑYgÑ3gÑ!gÔhØ"Ÿl™l×8Ò8‘d¸dˆØÜ—}‘} [°$·,±,×2EÑ2E×2JÑ2JÈ4Ï>É>Ó2ZÓ[Ð\]Ñ^ˆHØ˜!‰|˜x¨!™|Ò+Ø×*Ñ*×5Ñ5°fÓ=�Ø˜6Ÿ;™;Ò&Ø!�Mà˜!Š|Øàð �a‰KˆFð r   c                 ó‚   — t        | t        «      s| j                  d«      } d}t        | «      D ]
  }|dz  |z   }Œ |dz  S )zC Compute the GNU-style hash value for a given symbol name.
        r&   i  é!   l   ÿÿ r)   )Úkeyr.   r0   s      r   rg   zGNUHashTable.gnu_hash§   sK   € ô ˜#œuÔ%Ø—*‘*˜WÓ%ˆCØˆÜ˜3“ò 	ˆAØ�B‘˜‘
‰Að	à�:‰~Ðr   N)
r1   r2   r3   r4   r   r   re   r    r5   rg   r6   r   r   rB   rB   S   s0   „ ñò5òò.Eòð2 ñó ñr   rB   c                   ó   — e Zd ZdZd„ Zy)Ú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.
    c                 ój   — t        j                  | |||«       t        j                  | || d   |«       y r:   )r   r   rB   r<   s        r   r   zGNUHashSection.__init__¸   r>   r   Nr?   r6   r   r   ro   ro   ³   r@   r   ro   )
rT   Úcommon.utilsr   Úsectionsr   Úobjectr   r8   rB   ro   r6   r   r   ú<module>rt      sL   ðó å 'Ý ô6�6ô 6ôrM�W˜lô Mô]�6ô ]ô@M�W˜lõ Mr   