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

�#�_�S�@s�ddlmZddlmZmZmZmZddlmZm	Z	m
Z
mZmZm
Z
mZmZmZmZmZmZmZmZmZmZmZmZddlmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$dd�Z%d�d	d
�Z&d�dd
�Z'd�dd�Z(dd�Z)dd�Z*dd�Z+dd�Z,dd�Z-dd�Z.dd�Z/dd �Z0d!d"�Z1d#d$�Z2d%d&�Z3d'd(�Z4d)d*�Z5d+d,�Z6d-d.�Z7d/d0�Z8d1d2�Z9d3d4�Z:d5d6�Z;d7d8�Z<d9d:�Z=d;d<�Z>d=d>�Z?d?d@�Z@dAdB�ZAdCdD�ZBdEdF�ZCdGdH�ZDdIdJ�ZEdKdL�ZFdMdN�ZGdOdP�ZHdQdR�ZIdSdT�ZJe,dU�fdVdW�ZKdXdY�ZLdZd[�ZMd\d]�ZNd^d_�ZOd`da�ZPd�dcdd�ZQdedf�ZRdgdh�ZSdidj�ZTdkdl�ZUeVfdmdn�ZWdodp�ZXdqdr�ZYdsdt�ZZdudv�Z[dwdx�Z\d�d{d|�Z]e,dU�dyfd}d~�Z^ddye%dyd�fdd��Z_d�d��Z`d�d�d��Zad�d�d��Zbd�d��ZcdyS)��)�int2byte)�BitStreamReader�BitStreamWriter�
encode_bin�
decode_bin)�Struct�	MetaField�StaticField�FormatField�OnDemand�Pointer�Switch�Value�RepeatUntil�	MetaArray�Sequence�Range�Select�Pass�SizeofError�Buffered�Restream�Reconfig)
�BitIntegerAdapter�PaddingAdapter�ConstAdapter�CStringAdapter�LengthValueAdapter�IndexingAdapter�PaddedStringAdapter�FlagsAdapter�
StringAdapter�MappingAdaptercCs t|�rt||�St||�SdS)a*
    A field consisting of a specified number of bytes.

    :param str name: the name of the field
    :param length: the length of the field. the length can be either an integer
      (StaticField), or a function that takes the context as an argument and
      returns the length (MetaField)
    N)�callablerr	)�name�length�r&�=/usr/lib/python3.9/site-packages/elftools/construct/macros.py�Fields	
r(F�cCstt||�||||d�S)a�
    BitFields, as the name suggests, are fields that operate on raw, unaligned
    bits, and therefore must be enclosed in a BitStruct. Using them is very
    similar to all normal fields: they take a name and a length (in bits).

    :param str name: name of the field
    :param int length: number of bits in the field, or a function that takes
                       the context as its argument and returns the length
    :param bool swapped: whether the value is byte-swapped
    :param bool signed: whether the value is signed
    :param int bytesize: number of bits per byte, for byte-swapping

    >>> foo = BitStruct("foo",
    ...     BitField("a", 3),
    ...     Flag("b"),
    ...     Padding(3),
    ...     Nibble("c"),
    ...     BitField("d", 5),
    ... )
    >>> foo.parse("\xe1\x1f")
    Container(a = 7, b = False, c = 8, d = 31)
    >>> foo = BitStruct("foo",
    ...     BitField("a", 3),
    ...     Flag("b"),
    ...     Padding(3),
    ...     Nibble("c"),
    ...     Struct("bar",
    ...             Nibble("d"),
    ...             Bit("e"),
    ...     )
    ... )
    >>> foo.parse("\xe1\x1f")
    Container(a = 7, b = False, bar = Container(d = 15, e = 1), c = 8)
    )�swapped�signed�bytesize)rr()r$r%r*r+r,r&r&r'�BitFields$
�r-�cCsttd|�||d�S)a�a padding field (value is discarded)
    * length - the length of the field. the length can be either an integer,
      or a function that takes the context as an argument and returns the
      length
    * pattern - the padding pattern (character/byte) to use. default is b"\x00"
    * strict - whether or not to raise an exception is the actual padding
      pattern mismatches the desired pattern. default is False.
    N)�pattern�strict)rr()r%r/r0r&r&r'�PaddingHs	
�r1�cCs"tt|d�t|�t|�d�|d�S)a@
    A flag.

    Flags are usually used to signify a Boolean value, and this construct
    maps values onto the ``bool`` type.

    .. note:: This construct works with both bit and byte contexts.

    .. warning:: Flags default to False, not True. This is different from the
        C and Python way of thinking about truth, and may be subject to change
        in the future.

    :param str name: field name
    :param int truth: value of truth (default 1)
    :param int falsehood: value of falsehood (default 0)
    :param bool default: default value (default False)
    r�TF)�default)�SymmetricMappingr(r)r$�truthZ	falsehoodr4r&r&r'�FlagVs
�r7cCs
t|d�S)z1a 1-bit BitField; must be enclosed in a BitStructr�r-�r$r&r&r'�Bitqsr:cCs
t|d�S)z1a 4-bit BitField; must be enclosed in a BitStruct�r8r9r&r&r'�Nibbletsr<cCs
t|d�S)z2an 8-bit BitField; must be enclosed in a BitStructr)r8r9r&r&r'�Octetwsr=cCst|dd�S)z"unsigned, big endian 8-bit integer�>�B�r
r9r&r&r'�UBInt8{srAcCst|dd�S)z#unsigned, big endian 16-bit integerr>�Hr@r9r&r&r'�UBInt16~srCcCst|dd�S)z#unsigned, big endian 32-bit integerr>�Lr@r9r&r&r'�UBInt32�srEcCst|dd�S)z#unsigned, big endian 64-bit integerr>�Qr@r9r&r&r'�UBInt64�srGcCst|dd�S)z signed, big endian 8-bit integerr>�br@r9r&r&r'�SBInt8�srIcCst|dd�S)z!signed, big endian 16-bit integerr>�hr@r9r&r&r'�SBInt16�srKcCst|dd�S)z!signed, big endian 32-bit integerr>�lr@r9r&r&r'�SBInt32�srMcCst|dd�S)z!signed, big endian 64-bit integerr>�qr@r9r&r&r'�SBInt64�srOcCst|dd�S)z%unsigned, little endian 8-bit integer�<r?r@r9r&r&r'�ULInt8�srQcCst|dd�S)z&unsigned, little endian 16-bit integerrPrBr@r9r&r&r'�ULInt16�srRcCst|dd�S)z&unsigned, little endian 32-bit integerrPrDr@r9r&r&r'�ULInt32�srScCst|dd�S)z&unsigned, little endian 64-bit integerrPrFr@r9r&r&r'�ULInt64�srTcCst|dd�S)z#signed, little endian 8-bit integerrPrHr@r9r&r&r'�SLInt8�srUcCst|dd�S)z$signed, little endian 16-bit integerrPrJr@r9r&r&r'�SLInt16�srVcCst|dd�S)z$signed, little endian 32-bit integerrPrLr@r9r&r&r'�SLInt32�srWcCst|dd�S)z$signed, little endian 64-bit integerrPrNr@r9r&r&r'�SLInt64�srXcCst|dd�S)z(unsigned, native endianity 8-bit integer�=r?r@r9r&r&r'�UNInt8�srZcCst|dd�S)z)unsigned, native endianity 16-bit integerrYrBr@r9r&r&r'�UNInt16�sr[cCst|dd�S)z)unsigned, native endianity 32-bit integerrYrDr@r9r&r&r'�UNInt32�sr\cCst|dd�S)z)unsigned, native endianity 64-bit integerrYrFr@r9r&r&r'�UNInt64�sr]cCst|dd�S)z&signed, native endianity 8-bit integerrYrHr@r9r&r&r'�SNInt8�sr^cCst|dd�S)z'signed, native endianity 16-bit integerrYrJr@r9r&r&r'�SNInt16�sr_cCst|dd�S)z'signed, native endianity 32-bit integerrYrLr@r9r&r&r'�SNInt32�sr`cCst|dd�S)z'signed, native endianity 64-bit integerrYrNr@r9r&r&r'�SNInt64�sracCst|dd�S)z-big endian, 32-bit IEEE floating point numberr>�fr@r9r&r&r'�BFloat32�srccCst|dd�S)z0little endian, 32-bit IEEE floating point numberrPrbr@r9r&r&r'�LFloat32�srdcCst|dd�S)z3native endianity, 32-bit IEEE floating point numberrYrbr@r9r&r&r'�NFloat32�srecCst|dd�S)z-big endian, 64-bit IEEE floating point numberr>�dr@r9r&r&r'�BFloat64�srgcCst|dd�S)z0little endian, 64-bit IEEE floating point numberrPrfr@r9r&r&r'�LFloat64�srhcCst|dd�S)z3native endianity, 64-bit IEEE floating point numberrYrfr@r9r&r&r'�NFloat64�srics6t��rt�|�}nt�fdd�|�}|�|j�|S)a�
    Repeats the given unit a fixed number of times.

    :param int count: number of times to repeat
    :param ``Construct`` subcon: construct to repeat

    >>> c = Array(4, UBInt8("foo"))
    >>> c.parse("\x01\x02\x03\x04")
    [1, 2, 3, 4]
    >>> c.parse("\x01\x02\x03\x04\x05\x06")
    [1, 2, 3, 4]
    >>> c.build([5,6,7,8])
    '\x05\x06\x07\x08'
    >>> c.build([5,6,7,8,9])
    Traceback (most recent call last):
      ...
    construct.core.RangeError: expected 4..4, found 5
    cs�S�Nr&��ctx��countr&r'�<lambda>��zArray.<locals>.<lambda>)r#rZ_clear_flag�FLAG_DYNAMIC)rn�subcon�conr&rmr'�Array�s
rtr%cs$tt|j�t�fdd�|�dd��S)z�an array prefixed by a length field.
    * subcon - the subcon to be repeated
    * length_field - a construct returning an integer
    cs
|�jSrjr9rk��length_fieldr&r'rorpzPrefixedArray.<locals>.<lambda>F��nested)rrr$rt)rrrvr&rur'�
PrefixedArray�s��rycCsddlm}t|||�S)Nr2)�maxsize)�sysrzr)Zmincountrrrzr&r&r'�	OpenRange	sr|cCs
td|�S)a�
    Repeats the given unit one or more times.

    :param ``Construct`` subcon: construct to repeat

    >>> from construct import GreedyRange, UBInt8
    >>> c = GreedyRange(UBInt8("foo"))
    >>> c.parse("\x01")
    [1]
    >>> c.parse("\x01\x02\x03")
    [1, 2, 3]
    >>> c.parse("\x01\x02\x03\x04\x05\x06")
    [1, 2, 3, 4, 5, 6]
    >>> c.parse("")
    Traceback (most recent call last):
      ...
    construct.core.RangeError: expected 1..2147483647, found 0
    >>> c.build([1,2])
    '\x01\x02'
    >>> c.build([])
    Traceback (most recent call last):
      ...
    construct.core.RangeError: expected 1..2147483647, found 0
    r�r|�rrr&r&r'�GreedyRange
srcCs
td|�S)a�
    Repeats the given unit zero or more times. This repeater can't
    fail, as it accepts lists of any length.

    :param ``Construct`` subcon: construct to repeat

    >>> from construct import OptionalGreedyRange, UBInt8
    >>> c = OptionalGreedyRange(UBInt8("foo"))
    >>> c.parse("")
    []
    >>> c.parse("\x01\x02")
    [1, 2]
    >>> c.build([])
    ''
    >>> c.build([1,2])
    '\x01\x02'
    r2r}r~r&r&r'�OptionalGreedyRange)sr�cCst|j|t�S)zran optional construct. if parsing fails, returns None.
    * subcon - the subcon to optionally parse or build
    )rr$rr~r&r&r'�OptionalBsr�cCsJd}dd�}|�|j�s6|��|kr6t|tt|d�}nt|tt|d�}|S)zzconverts the stream to bits, and passes the bitstream to subcon
    * subcon - a bitwise construct (usually BitField)
    i cSs|d@rtd|��|d?S)N�zsize must be a multiple of 8�)r)r%r&r&r'�resizerOs
zBitwise.<locals>.resizer)�encoder�decoderr�)Z
stream_readerZ
stream_writerr�)	Z_is_flagrqZsizeofrrrrrr)rrZ
MAX_BUFFERr�rsr&r&r'�BitwiseHs��r�r;cs:�dkrtd�����fdd�}t�j�t||d�dd�S)z�aligns subcon to modulus boundary using padding pattern
    * subcon - the subcon to align
    * modulus - the modulus boundary (default is 4)
    * pattern - the padding pattern (default is \x00)
    �zmodulus must be >= 2cs���|���Srj)Z_sizeofrk��modulusrrr&r'�	padlengthhszAligned.<locals>.padlength)r/Frw)�
ValueError�SeqOfOner$r1)rrr�r/r�r&r�r'�Aligned`s

�r�cOstt|g|�Ri|��dd�S)z�a sequence of one element. only the first element is meaningful, the
    rest are discarded
    * name - the name of the sequence
    * args - subconstructs
    * kw - any keyword arguments to Sequence
    r2)�index)rr)r$�args�kwr&r&r'r�tsr�cCst|j||j�S)zRembeds a struct into the enclosing struct.
    * subcon - the struct to embed
    )rr$Z
FLAG_EMBEDr~r&r&r'�Embedded}sr�cCs
t||�S)zcrenames an existing construct
    * newname - the new name
    * subcon - the subcon to rename
    )r)�newnamerrr&r&r'�Rename�sr�cst|�fdd��S)z�creates an alias for an existing element in a struct
    * newname - the new name
    * oldname - the name of an existing element
    cs|�Srjr&rk��oldnamer&r'ro�rpzAlias.<locals>.<lambda>)r)r�r�r&r�r'�Alias�sr�cCs(tdd�|��D��}t|||||d�S)a�defines a symmetrical mapping: a->b, b->a.
    * subcon - the subcon to map
    * mapping - the encoding mapping (a dict); the decoding mapping is
      achieved by reversing this mapping
    * default - the default value to use when no mapping is found. if no
      default value is given, and exception is raised. setting to Pass would
      return the value "as is" (unmapped)
    css|]\}}||fVqdSrjr&)�.0�k�vr&r&r'�	<genexpr>�rpz#SymmetricMapping.<locals>.<genexpr>)�encodingZdecodingZ
encdefaultZ
decdefault)�dict�itemsr")rr�mappingr4Zreversed_mappingr&r&r'r5�s	�r5cKst|||�dt��S)a�a set of named values mapping.
    * subcon - the subcon to map
    * kw - keyword arguments which serve as the encoding mapping
    * _default_ - an optional, keyword-only argument that specifies the
      default value to use when the mapping is undefined. if not given,
      and exception is raised when the mapping is undefined. use `Pass` to
      pass the unmapped value as-is
    Z	_default_)r5�pop�NotImplemented�rrr�r&r&r'�Enum�s	r�cKs
t||�S)z�a set of flag values mapping.
    * subcon - the subcon to map
    * kw - keyword arguments which serve as the encoding mapping
    )r r�r&r&r'�	FlagsEnum�sr�cst|g�fdd�|D��R�S)z�a struct of aligned fields
    * name - the name of the struct
    * subcons - the subcons that make up this structure
    * kw - keyword arguments to pass to Aligned: 'modulus' and 'pattern'
    c3s|]}t|fi���VqdSrj)r�)r�Zsc�r�r&r'r��rpz AlignedStruct.<locals>.<genexpr>)r)r$�subconsr�r&r�r'�
AlignedStruct�sr�cGstt|g|�R��S)z{a struct of bitwise fields
    * name - the name of the struct
    * subcons - the subcons that make up this structure
    )r�r)r$r�r&r&r'�	BitStruct�sr�cGstttdg|�R���S)zian embedded BitStruct. no name is necessary.
    * subcons - the subcons that make up this structure
    N)r�r�r)r�r&r&r'�EmbeddedBitStruct�sr�N�rightcCs.tt||�|d�}|dur*t||||d�}|S)ae
    A configurable, fixed-length string field.

    The padding character must be specified for padding and trimming to work.

    :param str name: name
    :param int length: length, in bytes
    :param str encoding: encoding (e.g. "utf8") or None for no encoding
    :param str padchar: optional character to pad out strings
    :param str paddir: direction to pad out strings; one of "right", "left",
                       or "both"
    :param str trim: direction to trim strings; one of "right", "left"

    >>> from construct import String
    >>> String("foo", 5).parse("hello")
    'hello'
    >>>
    >>> String("foo", 12, encoding = "utf8").parse("hello joh\xd4\x83n")
    u'hello joh\u0503n'
    >>>
    >>> foo = String("foo", 10, padchar = "X", paddir = "right")
    >>> foo.parse("helloXXXXX")
    'hello'
    >>> foo.build("hello")
    'helloXXXXX'
    �r�N)�padchar�paddir�trimdir)r!r(r)r$r%r�r�r�r�rsr&r&r'�String�s�r�c
s&ttt|�td�fdd����|d�S)a-
    A length-prefixed string.

    ``PascalString`` is named after the string types of Pascal, which are
    length-prefixed. Lisp strings also follow this convention.

    The length field will appear in the same ``Container`` as the
    ``PascalString``, with the given name.

    :param str name: name
    :param ``Construct`` length_field: a field which will store the length of
                                       the string
    :param str encoding: encoding (e.g. "utf8") or None for no encoding

    >>> foo = PascalString("foo")
    >>> foo.parse("\x05hello")
    'hello'
    >>> foo.build("hello world")
    '\x0bhello world'
    >>>
    >>> foo = PascalString("foo", length_field = UBInt16("length"))
    >>> foo.parse("\x00\x05hello")
    'hello'
    >>> foo.build("hello")
    '\x00\x05hello'
    �datacs
|�jSrjr9rkrur&r'rorpzPascalString.<locals>.<lambda>r�)r!rrr()r$rvr�r&rur'�PascalString�s���r�cs"t|tt�fdd�|��|d��S)aH
    A string ending in a terminator.

    ``CString`` is similar to the strings of C, C++, and other related
    programming languages.

    By default, the terminator is the NULL byte (b``0x00``).

    :param str name: name
    :param iterable terminators: sequence of valid terminators, in order of
                                 preference
    :param str encoding: encoding (e.g. "utf8") or None for no encoding
    :param ``Construct`` char_field: construct representing a single character

    >>> foo = CString("foo")
    >>> foo.parse(b"hello\x00")
    b'hello'
    >>> foo.build(b"hello")
    b'hello\x00'
    >>> foo = CString("foo", terminators = b"XYZ")
    >>> foo.parse(b"helloX")
    b'hello'
    >>> foo.parse(b"helloY")
    b'hello'
    >>> foo.parse(b"helloZ")
    b'hello'
    >>> foo.build(b"hello")
    b'helloX'
    cs|�vSrjr&)�objrl��terminatorsr&r'ro?rpzCString.<locals>.<lambda>)r�r�)r�rr)r$r�r�Z
char_fieldr&r�r'�CStrings ��r�cst|�fdd�||d��S)a�an if-then-else conditional construct: if the predicate indicates True,
    `then_subcon` will be used; otherwise `else_subcon`
    * name - the name of the construct
    * predicate - a function taking the context as an argument and returning
      True or False
    * then_subcon - the subcon that will be used if the predicate returns True
    * else_subcon - the subcon that will be used if the predicate returns False
    cst�|��Srj)�boolrk��	predicater&r'roRrpzIfThenElse.<locals>.<lambda>r3)r
)r$r�Zthen_subconZelse_subconr&r�r'�
IfThenElseIs
	��r�c	st|j||td�fdd���S)a�an if-then conditional construct: if the predicate indicates True,
    subcon will be used; otherwise, `elsevalue` will be returned instead.
    * predicate - a function taking the context as an argument and returning
      True or False
    * subcon - the subcon that will be used if the predicate returns True
    * elsevalue - the value that will be used should the predicate return False.
      by default this value is None.
    �	elsevaluecs�Srjr&rk�r�r&r'roerpzIf.<locals>.<lambda>)r�r$r)r�rrr�r&r�r'�IfYs
	�r�TcCstt||�d|d�S)a$an on-demand pointer.
    * offsetfunc - a function taking the context as an argument and returning
      the absolute stream position
    * subcon - the subcon that will be parsed from the `offsetfunc()` stream
      position on demand
    * force_build - see OnDemand. by default True.
    F)Zadvance_stream�force_build)rr)Z
offsetfuncrrr�r&r&r'�OnDemandPointerls
�r�cCsttdt|��|�Srj)rr(�len)r�r&r&r'�Magicysr�)FFr))r.F)rr2F)r;r.)NNr�r�)N)T)dZ
lib.py3compatr�librrrrZcorerrr	r
rrr
rrrrrrrrrrrZadaptersrrrrrrrr r!r"r(r-r1r7r:r<r=rArCrErGrIrKrMrOrQrRrSrTrUrVrWrXrZr[r\r]r^r_r`rarcrdrergrhrirtryr|rr�r�r�r�r�r�r�r�r�r5r�r�r�r�r�r�r�r�r�r�r�r�r&r&r&r'�<module>s�P0
+



		�
#&�
,