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/construct/__pycache__/adapters.cpython-39.pyc
a

�#�_�@�@s�ddlmZmZmZddlmZmZmZddlmZm	Z	ddl
mZmZGdd�de�Z
Gdd�de�ZGd	d
�d
e�ZGdd�de�ZGd
d�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd �d e�ZGd!d"�d"e�ZGd#d$�d$e�ZGd%d&�d&e�ZGd'd(�d(e�ZGd)d*�d*e�ZGd+d,�d,e�Z Gd-d.�d.e �Z!Gd/d0�d0e �Z"d1S)2�)�Adapter�AdaptationError�Pass)�
int_to_bin�
bin_to_int�
swap_bytes)�FlagsContainer�	HexString)�BytesIO�decodebytesc@seZdZgZdS)�BitIntegerErrorN��__name__�
__module__�__qualname__�	__slots__�rr�?/usr/lib/python3.9/site-packages/elftools/construct/adapters.pyr
src@seZdZgZdS)�MappingErrorNr
rrrrrsrc@seZdZgZdS)�
ConstErrorNr
rrrrrsrc@seZdZgZdS)�ValidationErrorNr
rrrrrsrc@seZdZgZdS)�PaddingErrorNr
rrrrrsrc@s2eZdZdZgd�Zddd�Zdd�Zd	d
�ZdS)
�BitIntegerAdaptera�
    Adapter for bit-integers (converts bitstrings to integers, and vice versa).
    See BitField.

    Parameters:
    * subcon - the subcon to adapt
    * width - the size of the subcon, in bits
    * swapped - whether to swap byte order (little endian/big endian).
      default is False (big endian)
    * signed - whether the value is signed (two's complement). the default
      is False (unsigned)
    * bytesize - number of bits per byte, used for byte-swapping (if swapped).
      default is 8.
    )�width�swapped�signed�bytesizeF�cCs(t�||�||_||_||_||_dS�N)r�__init__rrrr)�self�subconrrrrrrrr(s
zBitIntegerAdapter.__init__cCs>|dkr|jstd|��t||jd�}|jr:t||jd�}|S)N�z+object is negative, but field is not signed)r�r)rrrrrrr)r �obj�context�obj2rrr�_encode/s�zBitIntegerAdapter._encodecCs"|jrt||jd�}t||jd�S)Nr#)r)rrrrr�r r$r%rrr�_decode7szBitIntegerAdapter._decodeN)FFr�rrr�__doc__rrr'r)rrrrrs�
rc@s6eZdZdZgd�Zeefdd�Zdd�Zdd�Zd	S)
�MappingAdaptera�
    Adapter that maps objects to other objects.
    See SymmetricMapping and Enum.

    Parameters:
    * subcon - the subcon to map
    * decoding - the decoding (parsing) mapping (a dict)
    * encoding - the encoding (building) mapping (a dict)
    * decdefault - the default return value when the object is not found
      in the decoding mapping. if no object is given, an exception is raised.
      if `Pass` is used, the unmapped object will be passed as-is
    * encdefault - the default return value when the object is not found
      in the encoding mapping. if no object is given, an exception is raised.
      if `Pass` is used, the unmapped object will be passed as-is
    )�encoding�decoding�
encdefault�
decdefaultcCs(t�||�||_||_||_||_dSr)rrr.r-r0r/)r r!r.r-r0r/rrrrMs
zMappingAdapter.__init__c	Cs^z|j|WSttfyX|jtur<td||jjf��|jturN|YS|jYS0dS)Nzno encoding mapping for %r [%s])	r-�KeyError�	TypeErrorr/�NotImplementedrr!�namerr(rrrr'Ts
�
zMappingAdapter._encodec	Cs^z|j|WSttfyX|jtur<td||jjf��|jturN|YS|jYS0dS)Nzno decoding mapping for %r [%s])	r.r1r2r0r3rr!r4rr(rrrr)^s
�
zMappingAdapter._decodeN)	rrrr+rr3rr'r)rrrrr,<s�

r,c@s.eZdZdZdgZdd�Zdd�Zdd�Zd	S)
�FlagsAdaptera
    Adapter for flag fields. Each flag is extracted from the number, resulting
    in a FlagsContainer object. Not intended for direct usage.
    See FlagsEnum.

    Parameters
    * subcon - the subcon to extract
    * flags - a dictionary mapping flag-names to their value
    �flagscCst�||�||_dSr)rrr6)r r!r6rrrrtszFlagsAdapter.__init__cCs0d}|j��D]\}}t||d�r||O}q|S)Nr"F)r6�items�getattr)r r$r%r6r4�valuerrrr'ws

zFlagsAdapter._encodecCs2t�}|j��D]\}}t||t||@��q|Sr)rr6r7�setattr�bool)r r$r%r&r4r9rrrr)}szFlagsAdapter._decodeNr*rrrrr5is
	r5c@s0eZdZdZdgZd
dd�Zdd�Zdd	�ZdS)�
StringAdapteraA
    Adapter for strings. Converts a sequence of characters into a python
    string, and optionally handles character encoding.
    See String.

    Parameters:
    * subcon - the subcon to convert
    * encoding - the character encoding name (e.g., "utf8"), or None to
      return raw bytes (usually 8-bit ASCII).
    r-NcCst�||�||_dSr)rrr-)r r!r-rrrr�szStringAdapter.__init__cCs|jr|�|j�}|Sr)r-�encoder(rrrr'�szStringAdapter._encodecCs|jr|�|j�}|Sr)r-�decoder(rrrr)�szStringAdapter._decode)Nr*rrrrr<�s


r<c@s2eZdZdZgd�Zddd�Zdd�Zd	d
�ZdS)
�PaddedStringAdaptera�
    Adapter for padded strings.
    See String.

    Parameters:
    * subcon - the subcon to adapt
    * padchar - the padding character. default is b"\x00".
    * paddir - the direction where padding is placed ("right", "left", or
      "center"). the default is "right".
    * trimdir - the direction where trimming will take place ("right" or
      "left"). the default is "right". trimming is only meaningful for
      building, when the given string is too long.
    )�padchar�paddir�trimdir��rightcCsF|dvrtd|��|dvr$td|��t�||�||_||_||_dS)N)rD�left�centerz*paddir must be 'right', 'left' or 'center')rDrEz!trimdir must be 'right' or 'left')�
ValueErrorrrr@rArB)r r!r@rArBrrrr�s�
zPaddedStringAdapter.__init__cCs@|jdkr|�|j�}n$|jdkr0|�|j�}n|�|j�}|S�NrDrE)rA�rstripr@�lstrip�stripr(rrrr)�s

zPaddedStringAdapter._decodecCs�|�|�}|jdkr$|�||j�}n(|jdkr>|�||j�}n|�||j�}t|�|kr~|jdkrp|d|�}n||d�}|SrH)�_sizeofrA�ljustr@�rjustrF�lenrB)r r$r%�sizerrrr'�s



zPaddedStringAdapter._encodeN)rCrDrD�rrrr+rrr)r'rrrrr?�s
�
r?c@s$eZdZdZgZdd�Zdd�ZdS)�LengthValueAdapterz�
    Adapter for length-value pairs. It extracts only the value from the
    pair, and calculates the length based on the value.
    See PrefixedArray and PascalString.

    Parameters:
    * subcon - the subcon returning a length-value pair
    cCst|�|fSr)rOr(rrrr'�szLengthValueAdapter._encodecCs|dS)Nrrr(rrrr)�szLengthValueAdapter._decodeN)rrrr+rr'r)rrrrrR�srRc@s0eZdZdZdgZddd�Zdd�Zd	d
�ZdS)�CStringAdapterar
    Adapter for C-style strings (strings terminated by a terminator char).

    Parameters:
    * subcon - the subcon to convert
    * terminators - a sequence of terminator chars. default is b"\x00".
    * encoding - the character encoding to use (e.g., "utf8"), or None to
      return raw-bytes. the terminator characters are not affected by the
      encoding.
    �terminatorsrCNcCstj|||d�||_dS)N)r-)r<rrT)r r!rTr-rrrr�szCStringAdapter.__init__cCst�|||�|jdd�S)Nr"r)r<r'rTr(rrrr'�szCStringAdapter._encodecCst�|d�|dd��|�S)N����)r<r)�joinr(rrrr)�szCStringAdapter._decode)rCNr*rrrrrS�s


rSc@s.eZdZdZdgZdd�Zdd�Zdd�Zd	S)
�
TunnelAdapteraC
    Adapter for tunneling (as in protocol tunneling). A tunnel is construct
    nested upon another (layering). For parsing, the lower layer first parses
    the data (note: it must return a string!), then the upper layer is called
    to parse that data (bottom-up). For building it works in a top-down manner;
    first the upper layer builds the data, then the lower layer takes it and
    writes it to the stream.

    Parameters:
    * subcon - the lower layer subcon
    * inner_subcon - the upper layer (tunneled/nested) subcon

    Example:
    # a pascal string containing compressed data (zlib encoding), so first
    # the string is read, decompressed, and finally re-parsed as an array
    # of UBInt16
    TunnelAdapter(
        PascalString("data", encoding = "zlib"),
        GreedyRange(UBInt16("elements"))
    )
    �inner_subconcCst�||�||_dSr)rrrY)r r!rYrrrrszTunnelAdapter.__init__cCs|j�t|�|�Sr)rY�_parser
r(rrrr)	szTunnelAdapter._decodecCst�}|j�|||�|��Sr)r
rYZ_build�getvalue)r r$r%�streamrrrr'szTunnelAdapter._encodeNrQrrrrrX�s
rXc@s eZdZdZddgZdd�ZdS)�ExprAdaptera>
    A generic adapter that accepts 'encoder' and 'decoder' as parameters. You
    can use ExprAdapter instead of writing a full-blown class when only a
    simple expression is needed.

    Parameters:
    * subcon - the subcon to adapt
    * encoder - a function that takes (obj, context) and returns an encoded
      version of obj
    * decoder - a function that takes (obj, context) and returns a decoded
      version of obj

    Example:
    ExprAdapter(UBInt8("foo"),
        encoder = lambda obj, ctx: obj / 4,
        decoder = lambda obj, ctx: obj * 4,
    )
    r'r)cCst�||�||_||_dSr)rrr'r))r r!�encoder�decoderrrrr$szExprAdapter.__init__N)rrrr+rrrrrrr]sr]c@s0eZdZdZdgZddd�Zdd�Zdd	�Zd
S)�HexDumpAdapterzT
    Adapter for hex-dumping strings. It returns a HexString, which is a string
    �linesize�cCst�||�||_dSr)rrra)r r!rarrrr.szHexDumpAdapter.__init__cCs|Srrr(rrrr'1szHexDumpAdapter._encodecCst||jd�S)N)ra)r	rar(rrrr)3szHexDumpAdapter._decodeN)rbr*rrrrr`)s

r`c@s.eZdZdZdgZdd�Zdd�Zdd�Zd	S)
�ConstAdaptera,
    Adapter for enforcing a constant value ("magic numbers"). When decoding,
    the return value is checked; when building, the value is substituted in.

    Parameters:
    * subcon - the subcon to validate
    * value - the expected value

    Example:
    Const(Field("signature", 2), "MZ")
    r9cCst�||�||_dSr)rrr9)r r!r9rrrrCszConstAdapter.__init__cCs.|dus||jkr|jStd|j|f��dS�Nzexpected %r, found %r�r9rr(rrrr'FszConstAdapter._encodecCs ||jkrtd|j|f��|Srdrer(rrrr)Ks
zConstAdapter._decodeNr*rrrrrc6s
rcc@s2eZdZdZgd�Zd
dd�Zdd�Zdd	�ZdS)�SlicingAdapterz�
    Adapter for slicing a list (getting a slice from that list)

    Parameters:
    * subcon - the subcon to slice
    * start - start index
    * stop - stop index (or None for up-to-end)
    * step - step (or None for every element)
    )�start�stop�stepNcCst�||�||_||_dSr)rrrgrh)r r!rgrhrrrr[szSlicingAdapter.__init__cCs|jdur|Sdg|j|Sr)rgr(rrrr'_s
zSlicingAdapter._encodecCs||j|j�Sr)rgrhr(rrrr)cszSlicingAdapter._decode)Nr*rrrrrfPs
	
rfc@s.eZdZdZdgZdd�Zdd�Zdd�Zd	S)
�IndexingAdapterz�
    Adapter for indexing a list (getting a single item from that list)

    Parameters:
    * subcon - the subcon to index
    * index - the index of the list to get
    �indexcCs0t�||�t|�tur&tdt|���||_dS)Nzindex must be an integer)rr�type�intr2rk)r r!rkrrrroszIndexingAdapter.__init__cCsdg|j|gSr�rkr(rrrr'tszIndexingAdapter._encodecCs
||jSrrnr(rrrr)vszIndexingAdapter._decodeNr*rrrrrjfs
rjc@s2eZdZdZddgZd
dd�Zdd	�Zd
d�ZdS)�PaddingAdaptera+
    Adapter for padding.

    Parameters:
    * subcon - the subcon to pad
    * pattern - the padding pattern (character as byte). default is b"\x00"
    * strict - whether or not to verify, during parsing, that the given
      padding matches the padding pattern. default is False (unstrict)
    �pattern�strictrCFcCst�||�||_||_dSr)rrrprq)r r!rprqrrrr�szPaddingAdapter.__init__cCs|�|�|jSr)rLrpr(rrrr'�szPaddingAdapter._encodecCs2|jr.|�|�|j}||kr.td||f��|Srd)rqrLrpr)r r$r%Zexpectedrrrr)�s
zPaddingAdapter._decodeN)rCFr*rrrrroys
	
roc@s,eZdZdZgZdd�Zdd�Zdd�ZdS)	�	Validatorz�
    Abstract class: validates a condition on the encoded/decoded object.
    Override _validate(obj, context) in deriving classes.

    Parameters:
    * subcon - the subcon to validate
    cCs|�||�std|��|S)Nzinvalid object)�	_validaterr(rrrr)�s
zValidator._decodecCs|�||�Sr)r)r(rrrr'�szValidator._encodecCs
t��dSr)�NotImplementedErrorr(rrrrs�szValidator._validateN)rrrr+rr)r'rsrrrrrr�s
rrc@s&eZdZdZdgZdd�Zdd�ZdS)�OneOfai
    Validates that the object is one of the listed values.

    :param ``Construct`` subcon: object to validate
    :param iterable valids: a set of valid values

    >>> OneOf(UBInt8("foo"), [4,5,6,7]).parse("\x05")
    5
    >>> OneOf(UBInt8("foo"), [4,5,6,7]).parse("\x08")
    Traceback (most recent call last):
        ...
    construct.core.ValidationError: ('invalid object', 8)
    >>>
    >>> OneOf(UBInt8("foo"), [4,5,6,7]).build(5)
    '\x05'
    >>> OneOf(UBInt8("foo"), [4,5,6,7]).build(9)
    Traceback (most recent call last):
        ...
    construct.core.ValidationError: ('invalid object', 9)
    �validscCst�||�||_dSr)rrrrv)r r!rvrrrr�szOneOf.__init__cCs
||jvSr)rvr(rrrrs�szOneOf._validateN�rrrr+rrrsrrrrru�sruc@s&eZdZdZdgZdd�Zdd�ZdS)�NoneOfa�
    Validates that the object is none of the listed values.

    :param ``Construct`` subcon: object to validate
    :param iterable invalids: a set of invalid values

    >>> NoneOf(UBInt8("foo"), [4,5,6,7]).parse("\x08")
    8
    >>> NoneOf(UBInt8("foo"), [4,5,6,7]).parse("\x06")
    Traceback (most recent call last):
        ...
    construct.core.ValidationError: ('invalid object', 6)
    �invalidscCst�||�||_dSr)rrrry)r r!ryrrrr�szNoneOf.__init__cCs
||jvSr)ryr(rrrrs�szNoneOf._validateNrwrrrrrx�s
rxN)#Zcorerrr�librrrrr	Z
lib.py3compatr
rrrrrrrr,r5r<r?rRrSrXr]r`rcrfrjrorrrurxrrrr�<module>s2$-1!