[ Root System Explorer ]
Location:
Root
/
lib
/
python3.9
/
site-packages
/
elftools
/
common
/
__pycache__
+ Folder
+ File
Upload
Editing: utils.cpython-39.pyc
a �#�_B � @ s� d dl mZ ddlmZmZmZ ddlmZ ddlm Z m Z dd� Zd d � Zddd �Z ddd�Zddd�Zd dd�Zedd� �Zdd� Zdd� Zdd� ZdS )!� )�contextmanager� )� ELFParseError�ELFError� DWARFError��int2byte� )�ConstructError�ULInt8c G s i }| D ]}|� |� q|S )z6Given any number of dicts, merges them into a new one.)�update)Zdicts�result�d� r �9/usr/lib/python3.9/site-packages/elftools/common/utils.py�merge_dicts s r c C s d� dd� | D ��S )zd Convert a list of byte values (e.g. [0x10 0x20 0x00]) to a bytes object (e.g. b' '). � c s s | ]}t |�V qd S �Nr )�.0�br r r � <genexpr> r z"bytelist2string.<locals>.<genexpr>)�join)Zbytelistr r r �bytelist2string s r Nc C sT z|dur|� |� | �|�W S tyN } ztt|���W Y d}~n d}~0 0 dS )a4 Convenience function for using the given struct to parse a stream. If stream_pos is provided, the stream is seeked to this position before the parsing is done. Otherwise, the current position of the stream is used. Wraps the error thrown by construct with ELFParseError. N)�seekZparse_streamr r �str)�struct�stream� stream_pos�er r r �struct_parse s r c C s� |dur| � |� d}g }d}| �|�}|�d�}|dkrT|�|d|� � d}qnn |�|� t|�|k rqnq|r|d�|�S dS )a� Parse a C-string from the given stream. The string is returned without the terminating byte. If the terminating byte wasn't found, None is returned (the stream is exhausted). If stream_pos is provided, the stream is seeked to this position before the parsing is done. Otherwise, the current position of the stream is used. Note: a bytes object is returned here, because this is what's read from the binary file. N�@ F� r Tr )r �read�find�append�lenr )r r Z CHUNKSIZE�chunks�found�chunkZ end_indexr r r �parse_cstring_from_stream- s r) � c C s t | |t� dS )z= Assert that cond is True, otherwise raise ELFError(msg) N)�_assert_with_exceptionr ��cond�msgr r r � elf_assertJ s r/ c C s t | |t� dS )z? Assert that cond is True, otherwise raise DWARFError(msg) N)r+ r r, r r r �dwarf_assertP s r0 c c s | � � }dV | �|� dS )z� Usage: # stream has some position FOO (return value of stream.tell()) with preserve_stream_pos(stream): # do stuff that manipulates the stream # stream still has position FOO N)�tellr )r Z saved_posr r r �preserve_stream_posV s r2 c C s | d d|>