
    d[                     v    d dl mZ d dlmZ ddlmZ ddlmZ  G d de      Z	 G d d	e	      Z
 G d
 de	      Zy)   )CString)struct_parse   )SH_FLAGS)
iter_notesc                   $    e Zd Zd Zd Zd Zd Zy)Segmentc                      || _         || _        y N)headerstream)selfr   r   s      7/usr/lib/python3/dist-packages/elftools/elf/segments.py__init__zSegment.__init__   s        c                 z    | j                   j                  | d          | j                   j                  | d         S )z) The segment data from the file.
        p_offsetp_filesz)r   seekreadr   s    r   datazSegment.data   s5     	j)*{{Z 011r   c                      | j                   |   S )z6 Implement dict-like access to header entries
        )r   )r   names     r   __getitem__zSegment.__getitem__   s     {{4  r   c                    | d   }|d   }|d   }|t         j                  z  r|dv rn|t         j                  z  dk(  r|dvrny|t         j                  z  dk(  r|dv ry|t         j                  z  r/|d	   }| d
   }||k\  r||z
  |d   z   | d   k  r||z
  | d   dz
  k  sy|dk(  ry|d   }| d   }||k\  xr! ||z
  |d   z   | d   k  xr ||z
  | d   dz
  k  S )z Is the given section contained in this segment?

            Note: this tries to reproduce the intricate rules of the
            ELF_SECTION_IN_SEGMENT_STRICT macro of the header
            elf/include/internal.h in the source of binutils.
        p_typesh_typesh_flags)PT_TLSPT_GNU_RELROPT_LOAD    )r    PT_PHDRF)r"   
PT_DYNAMICPT_GNU_EH_FRAMEr!   PT_GNU_STACKsh_addrp_vaddrsh_sizep_memszr   
SHT_NOBITST	sh_offsetr   r   )r   SHF_TLS	SHF_ALLOC)	r   sectionsegtypesectypesecflagssecaddrvaddr	secoffsetpoffsets	            r   section_in_segmentzSegment.section_in_segment   sR    x.)$:& 8+++@@ H,,,244 H...14 < < h(((i(GOE u$eOgi&88DOKeOtI':: l"K(	z" W$ <G#gi&88D<LL<G#tJ'7!';;	=r   N)__name__
__module____qualname__r   r   r   r8    r   r   r	   r	      s    2!
9=r   r	   c                   (     e Zd ZdZ fdZd Z xZS )InterpSegmentze INTERP segment. Knows how to obtain the path to the interpreter used
        for this ELF file.
    c                 .    t         t        |   ||       y r   )superr>   r   )r   r   r   	__class__s      r   r   zInterpSegment.__init___   s    mT+FF;r   c                 R    | d   }t        t        dd      | j                  |      S )z= Obtain the interpreter path used for this ELF file.
        r    zutf-8)encoding)
stream_pos)r   r   r   )r   path_offsets     r   get_interp_namezInterpSegment.get_interp_nameb   s/     :&B)KK"$ 	$r   )r9   r:   r;   __doc__r   rG   __classcell__rA   s   @r   r>   r>   [   s    <$r   r>   c                   (     e Zd ZdZ fdZd Z xZS )NoteSegmentz- NOTE segment. Knows how to parse notes.
    c                 <    t         t        |   ||       || _        y r   )r@   rL   r   elffile)r   r   r   rN   rA   s       r   r   zNoteSegment.__init__o   s    k4)&&9r   c                 <    t        | j                  | d   | d         S )z Yield all the notes in the segment.  Each result is a dictionary-
            like object with "n_name", "n_type", and "n_desc" fields, amongst
            others.
        r   r   )r   rN   r   s    r   r   zNoteSegment.iter_notess   s!     $,,Z(8$z:JKKr   )r9   r:   r;   rH   r   r   rI   rJ   s   @r   rL   rL   l   s    Lr   rL   N)	constructr   common.utilsr   	constantsr   notesr   objectr	   r>   rL   r<   r   r   <module>rU      s<      '  I=f I=X$G $"L' Lr   