Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
B

,lÂv2rs½ã	@sÌdZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlmZddlmZddlmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&dd	l'm(Z(dd
l)m*Z*m+Z+ddl,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2ddl3m4Z4m5Z5dd
l6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<ddl=m>Z>m?Z?m@Z@mAZAmBZBmCZCddlDmEZEmFZFmGZGmHZHddl)mIZIddlJmKmLZLddlMmNZNddlJmOZOddl,mPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]e]rddl^m_Z_Gdd„dƒZ`Gdd„deSeaebfƒZceZdƒZdeZdƒZeeL feH¡Gdd„deUedeefƒƒZgGdd„dehƒZie[egePePfeifZjGdd „d eiƒZkGd!d"„d"eiƒZlGd#d$„d$eiƒZmGd%d&„d&eiƒZnGd'd(„d(eiƒZoGd)d*„d*eoƒZpGd+d,„d,egeaeafƒZqGd-d.„d.egeberfƒZsGd/d0„d0egeVeberfƒZtGd1d2„d2ege[ebeFferfƒZuGd3d4„d4euƒZvGd5d6„d6egeVe[ebeBferfƒZwGd7d8„d8ewƒZxGd9d:„d:ewesƒZyGd;d<„d<egeaeafƒZzGd=d>„d>ezƒZ{Gd?d@„d@ezƒZ|GdAdB„dBegeaeafƒZ}GdCdD„dDe}e{ƒZ~GdEdF„dFezƒZGdGdH„dHee{ƒZ€GdIdJ„dJegeaeTeafƒZGdKdL„dLeƒZ‚GdMdN„dNegeaeafƒZƒGdOdP„dPe+ƒZ„GdQdR„dRe+ƒZ…GdSdT„dTezƒZ†GdUdV„dVegeaeafƒZ‡GdWdX„dXegeaeafƒZˆGdYdZ„dZegeaeafƒZ‰Gd[d\„d\egeaeafƒZŠGd]d^„d^e‡ƒZ‹Gd_d`„d`egeaeafƒZŒGdadb„dbegeaeafƒZGdcdd„ddegeaeafƒZŽGdedf„dfegeaeafƒZGdgdh„dheŒƒZGdidj„djeŽeƒZ‘Gdkdl„dle‰e‹ƒZ’Gdmdn„dnegeaeafƒZ“Gdodp„dpegeaeafƒZ”Gdqdr„dre“ƒZ•Gdsdt„dtegeaeafƒZ–Gdudv„dve“ƒZ—Gdwdx„dxe•e—ƒZ˜Gdydz„dzegeaeafƒZ™Gd{d|„d|egeaeafƒZšGd}d~„d~egederfƒZ›Gdd€„d€e›erƒZœGdd‚„d‚eœƒZeZdƒeTeGeGƒZžGd„d…„d…e›ežƒZŸGd†d‡„d‡eŸeGƒZ Gdˆd‰„d‰e ƒZ¡GdŠd‹„d‹eŸeTeGƒZ¢GdŒd„deœƒZ£GdŽd„de£ƒZ¤Gdd‘„d‘e£ƒZ¥Gd’d“„d“eœƒZ¦Gd”d•„d•eœƒZ§Gd–d—„d—ƒZ¨Gd˜d™„d™e¨e¦ƒZ©Gdšd›„d›e¨e£ƒZªGdœd„de©ƒZ«GdždŸ„dŸe¦ƒZ¬Gd d¡„d¡e¦ƒZ­Gd¢d£„d£egeTePeTePfƒZ®Gd¤d¥„d¥egeaeafƒZ¯Gd¦d§„d§eœƒZ°Gd¨d©„d©eœƒZ±Gdªd«„d«egeaeafƒZ²Gd¬d­„d­ege³eafƒZ´Gd®d¯„d¯egedeafƒZµGd°d±„d±eµeaƒZ¶Gd²d³„d³e¶ƒZ·Gd´dµ„dµe¶ƒZ¸Gd¶d·„d·e¶ƒZ¹Gd¸d¹„d¹ege[eTededfedfƒZºGdºd»„d»eºedƒZ»Gd¼d½„d½e»ebƒZ¼Gd¾d¿„d¿eµe[eTeaeafeºeaƒZ½GdÀdDdÁe»eaƒZ¾GdÂdÄdÃe»eaƒZ¿GdÄdńdÅe»eaƒZÀGdÆdDŽdÇeZÁGdÈdɄdÉe»eaƒZÂGdÊd˄dËe»eaƒZÃGdÌd̈́dÍe»eaƒZÄGdÎdτdÏe¾ƒZÅGdÐdфdÑeºedƒZÆGdÒdӄdÓeÆeae»eaƒZÇGdÔdՄdÕeµe[eTeaeafeÆeaƒZÈGdÖdׄd×eZÉGdØdلdÙe¾ƒZÊGdÚdۄdÛeƒZËGdÜd݄dÝe¯ƒZÌGdÞd߄dßehƒZÍGdàdá„dáehƒZÎGdâdã„dãeµeVe[eaeÎfƒZÏe Ðdädådæg¡ZÑGdçdè„dèeµeWebƒZÒGdédê„dêe¶ƒZÓGdëdì„dìegeXebeafeXereaffƒZÔGdídî„dîeԃZÕGdïdð„dðeԃZÖGdñdò„dòege³eafƒZ×Gdódô„dôege³eafƒZØGdõdö„döehƒZÙGd÷dø„døeÙege[eae³fe[eae³ffƒZÚGdùdú„dúeÙe¶ƒZÛGdûdü„düe~ƒZÜGdýdþ„dþegeerfƒZÝGdÿd„degeVeaerfƒZÞGdd„deރZßGdd„deރZàdS(z>
Fields: basic data structures that make up parts of packets.
é)Úabsolute_importN)Ú
MethodType)ÚUUID)Úconf)ÚDADict)ÚRandBinÚRandByteÚRandEnumKeysÚRandIntÚRandIPÚRandIP6ÚRandLongÚRandMACÚRandNumÚ	RandShortÚRandSIntÚ	RandSByteÚRandTermStringÚRandUUIDÚ
VolatileValueÚ
RandSShortÚ	RandSLongÚ	RandFloat)ÚEPOCH)Úlog_runtimeÚScapy_Exception)Ú	bytes_hexÚchbÚorbÚ	plain_strÚrawÚbytes_encode)Ú	inet_ntopÚ	inet_pton)Ú	inet_atonÚ	inet_ntoaÚlhexÚmac2strÚstr2macÚEDecimal)Úin6_6to4ExtractAddrÚin6_isaddr6to4Úin6_isaddrTeredoÚin6_ptopÚNet6ÚteredoAddrExtractInfo)ÚGenÚNetÚ
BasePacketÚField_metaclass)Úwarning)Úrange)Ú
integer_types)ÚAnyÚAnyStrÚCallableÚDictÚListÚGenericÚOptionalÚSetÚTupleÚTypeÚTypeVarÚUnionÚcastÚ
TYPE_CHECKING)ÚPacketc@s:eZdZdZddd„Zdd„Zdd„Zd	d
„Zdd„Zd
S)ÚRawVala
    A raw value that will not be processed by the field and inserted
    as-is in the packet string.

    Example::

        >>> a = IP(len=RawVal("####"))
        >>> bytes(a)
        b'F\x00####\x00\x01\x00\x005\xb5\x00\x00\x7f\x00\x00\x01\x7f\x00\x00\x01\x00\x00'

    ócCst|ƒ|_dS)N)r!Úval)ÚselfrH©rJúŠ/build/wlanpi-profiler-8o1rr4/wlanpi-profiler-1.0.9/debian/wlanpi-profiler/opt/wlanpi-profiler/lib/python3.7/site-packages/scapy/fields.pyÚ__init__QszRawVal.__init__cCs
t|jƒS)N)ÚstrrH)rIrJrJrKÚ__str__UszRawVal.__str__cCs|jS)N)rH)rIrJrJrKÚ	__bytes__YszRawVal.__bytes__cCs
t|jƒS)N)ÚlenrH)rIrJrJrKÚ__len__]szRawVal.__len__cCs
d|jS)Nz
<RawVal [%r]>)rH)rIrJrJrKÚ__repr__aszRawVal.__repr__N)rG)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__rLrNrOrQrRrJrJrJrKrFEs
rFcsHeZdZdZ‡fdd„Zdd„Z‡fdd„Z‡fdd	„Zd
d„Z‡Z	S)ÚObservableDictzQ
    Helper class to specify a protocol extendable for runtime modifications
    csg|_tt|ƒj||ŽdS)N)Ú	observersÚsuperrWrL)rIÚargsÚkw)Ú	__class__rJrKrLjszObservableDict.__init__cCs|j |¡dS)N)rXÚappend)rIZobserverrJrJrKÚobserveoszObservableDict.observecs4x|jD]}| |||¡qWtt|ƒ ||¡dS)N)rXÚ
notify_setrYrWÚ__setitem__)rIÚkeyÚvalueÚo)r\rJrKr`sszObservableDict.__setitem__cs0x|jD]}| ||¡qWtt|ƒ |¡dS)N)rXÚ
notify_delrYrWÚ__delitem__)rIrarc)r\rJrKreyszObservableDict.__delitem__cCsx|D]}||||<qWdS)NrJ)rIZanotherDictÚkrJrJrKÚupdates
zObservableDict.update)
rSrTrUrVrLr^r`rergÚ
__classcell__rJrJ)r\rKrWfsrWÚIÚMc@s®eZdZdZddddddgZdZd	ZdZd,dd„Zd
d„Z	dd„Z
dd„Zdd„Zdd„Z
dd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+S)-ÚFieldzÄ
    For more information on how this works, please refer to the
    'Adding new protocols' chapter in the online documentation:

    https://scapy.readthedocs.io/en/stable/build_dissect.html
    ÚnameÚfmtÚdefaultÚszÚownersÚstructrFÚHcCsjt|tƒstdƒ‚||_|ddkr,||_n
d||_t |j¡|_| d|¡|_t 	|j¡|_
g|_dS)Nzname should be a stringrz@=<>!ú!)Ú
isinstancerMÚ
ValueErrorrlrmrqÚStructÚany2irnÚcalcsizerorp)rIrlrnrmrJrJrKrL s

zField.__init__cCs|j |¡dS)N)rpr])rIÚclsrJrJrKÚregister_owner®szField.register_ownercCst|tƒrt|ƒS|jS)z<Convert internal value to a length usable by a FieldLenField)rtrFrPro)rIÚpktÚxrJrJrKÚi2len²s
zField.i2lencCsdS)zqConvert internal value to a number of elements usable by a FieldLenField.
        Always 1 except for list fieldsérJ)rIr{r|rJrJrKÚi2count¼sz
Field.i2countcCs
tt|ƒS)z%Convert human value to internal value)rCri)rIr{r|rJrJrKÚh2iÂsz	Field.h2icCs|S)z%Convert internal value to human valuerJ)rIr{r|rJrJrKÚi2hÇsz	Field.i2hcCs
tt|ƒS)z'Convert machine value to internal value)rCri)rIr{r|rJrJrKÚm2iÌsz	Field.m2icCs4|dkrttdƒSt|tƒr*ttt|ƒƒStt|ƒS)z'Convert internal value to machine valueNr)rCrjrtrMr!)rIr{r|rJrJrKÚi2mÑs


z	Field.i2mcCs| ||¡S)zUTry to understand the most input values possible and make an internal value from them)r€)rIr{r|rJrJrKrwÚszField.any2icCst| ||¡ƒS)z/Convert internal value to a nice representation)Úreprr)rIr{r|rJrJrKÚi2reprßszField.i2reprc
Cs`y||j | ||¡¡Stjk
rZ}z"td|jd|ddƒ‚Wdd}~XYnXdS)zÅAdd an internal value to a string

        Copy the network representation of field `val` (belonging to layer
        `pkt`) to the raw string packet `s`, and return the new string packet.
        z&Incorrect type of value for field %s:
zstruct.error('%s')
z7To inject bytes into the field regardless of the type, zuse RawVal. See help(RawVal)N)rqÚpackrƒÚerrorrurl)rIr{ÚsrHÚexrJrJrKÚaddfieldäszField.addfieldc	Cs0||jd…| ||j |d|j…¡d¡fS)aDExtract an internal value from a string

        Extract from the raw packet `s` the field value belonging to layer
        `pkt`.

        Returns a two-element list,
        first the raw packet string after having removed the extracted field,
        second the extracted field itself in internal representation.
        Nr)ror‚rqÚunpack)rIr{rˆrJrJrKÚgetfieldõszField.getfieldcCs`t|dƒr| ¡St|tƒr\|dd…}x2tt|ƒƒD]"}t||tƒr6|| ¡||<q6W|S)NÚcopy)ÚhasattrrrtÚlistr5rPr2)rIr|ÚirJrJrKÚdo_copys

z
Field.do_copycCs&d|jjd dd„|jDƒ¡|jfS)Nz<%s (%s).%s>ú,css|]}|jVqdS)N)rS)Ú.0r|rJrJrKú	<genexpr>sz!Field.__repr__.<locals>.<genexpr>)r\rSÚjoinrprl)rIrJrJrKrR
szField.__repr__cCs
t |¡S)N)r)rIrJrJrKrsz
Field.copyc	Cs†|jd}|dkr.ttttttttdœ|ƒS|dkrr|jddkrXt	|jdd…ƒ}nt	|jdd…ƒ}t
|ƒStd	|j|jƒdS)
zOReturn a volatile object whose value is both random and suitable for this fieldéÿÿÿÿZBbHhIiQq)ÚBÚbrrÚhrirÚQÚqrˆrÚ
0123456789Nr~z"no random class for [%s] (fmt=%s).)
rmrrrrr
rr
rÚintrr4rl)rIZfmttrbrJrJrKÚrandvals
z
Field.randvalN)rr)rSrTrUrVÚ	__slots__ÚislistÚ	ismutableÚ
holds_packetsrLrzr}rr€rr‚rƒrwr…rŠrŒr‘rRrržrJrJrJrKrkŒs4

	
rkc@seZdZdZdd„ZdS)Ú_FieldContainerz<
    A field that acts as a container for another field
    cCst|j|ƒS)N)ÚgetattrÚfld)rIÚattrrJrJrKÚ__getattr__0sz_FieldContainer.__getattr__N)rSrTrUrVr§rJrJrJrKr£,sr£c@s2eZdZdZdgZdd„Zdd„Zdd„Zd	Zd	S)
ÚEmphzEmpathize sub-layer for displayr¥cCs
||_dS)N)r¥)rIr¥rJrJrKrL<sz
Emph.__init__cCst|j|kƒS)N)Úboolr¥)rIÚotherrJrJrKÚ__eq__@szEmph.__eq__cCs
||kS)NrJ)rIrªrJrJrKÚ__ne__DszEmph.__ne__N)	rSrTrUrVrŸrLr«r¬Ú__hash__rJrJrJrKr¨8sr¨c@s&eZdZdddgZdd„Zdd„ZdS)	ÚActionFieldr¥Ú_action_methodÚ	_privdatacKs||_||_||_dS)N)r¥r¯r°)rIr¥Z
action_methodZkargsrJrJrKrLPszActionField.__init__cCs,t||jƒ||jf|jŽt|jdƒ||ƒS)Nrw)r¤r¯r¥r°)rIr{rHrJrJrKrwVszActionField.any2iN)rSrTrUrŸrLrwrJrJrJrKr®Ms
r®c@sLeZdZddgZdd„Zdd„Zdd„Zd	d
„Zdd„Zd
d„Z	dd„Z
dS)ÚConditionalFieldr¥ÚcondcCs||_||_dS)N)r¥r²)rIr¥r²rJrJrKrL_szConditionalField.__init__cCst| |¡ƒS)N)r©r²)rIr{rJrJrKÚ	_evalcondgszConditionalField._evalcondcCs t|jƒtkr|S|j ||¡S)N)Útyper¥rkrw)rIr{r|rJrJrKrwkszConditionalField.any2icCs |r| |¡sdS|j ||¡S)N)r³r¥r)rIr{rHrJrJrKrzszConditionalField.i2hcCs$| |¡r|j ||¡S|dfSdS)N)r³r¥rŒ)rIr{rˆrJrJrKrŒ€s
zConditionalField.getfieldcCs"| |¡r|j |||¡S|SdS)N)r³r¥rŠ)rIr{rˆrHrJrJrKrЇs
zConditionalField.addfieldcCst|j|ƒS)N)r¤r¥)rIr¦rJrJrKr§ŽszConditionalField.__getattr__N)rSrTrUrŸrLr³rwrrŒrŠr§rJrJrJrKr±\sr±c@s˜eZdZdZddddgZdd„Zdd	„Zd
d„Zdd
„Zdd„Z	dd„Z
dd„Zdd„Zdd„Z
dd„Zdd„Zdd„Zdd„Zd d!„Zed"d#„ƒZd$S)%ÚMultipleTypeFielda¡MultipleTypeField are used for fields that can be implemented by
various Field subclasses, depending on conditions on the packet.

It is initialized with `flds` and `dflt`.

`dflt` is the default field type, to be used when none of the
conditions matched the current packet.

`flds` is a list of tuples (`fld`, `cond`), where `fld` if a field
type, and `cond` a "condition" to determine if `fld` is the field type
that should be used.

`cond` is either:

  - a callable `cond_pkt` that accepts one argument (the packet) and
    returns True if `fld` should be used, False otherwise.

  - a tuple (`cond_pkt`, `cond_pkt_val`), where `cond_pkt` is the same
    as in the previous case and `cond_pkt_val` is a callable that
    accepts two arguments (the packet, and the value to be set) and
    returns True if `fld` should be used, False otherwise.

See scapy.layers.l2.ARP (type "help(ARP)" in Scapy) for an example of
use.

    ÚfldsÚdfltrlrncsD|ˆ_|ˆ_dˆ_ˆjjˆ_t‡fdd„ˆjDƒƒr@t dt¡dS)Nc3s|]}|djˆjkVqdS)rN)rl)r“r|)rIrJrKr”ºsz-MultipleTypeField.__init__.<locals>.<genexpr>z;All fields should have the same name in a MultipleTypeField)r¶r·rnrlÚanyÚwarningsÚwarnÚ
SyntaxWarning)rIr¶r·rJ)rIrKrL±s
zMultipleTypeField.__init__cCsbxZ|jD]P\}}t|tƒrL|rD|dkr.|jj}|d||ƒr|Sqn|d}||ƒr|SqW|jS)z;Internal function used by _find_fld_pkt & _find_fld_pkt_valNr~r)r¶rtÚtupler·rn)rIr{rHZuse_valr¥r²rJrJrKÚ_iterate_fields_condÀs
z&MultipleTypeField._iterate_fields_condcCs| |dd¡S)z©Given a Packet instance `pkt`, returns the Field subclass to be
used. If you know the value to be set (e.g., in .addfield()), use
._find_fld_pkt_val() instead.

        NF)r½)rIr{rJrJrKÚ
_find_fld_pktÒszMultipleTypeField._find_fld_pktcCs$| ||d¡}|dkr|j}||fS)z‘Given a Packet instance `pkt` and the value `val` to be set,
returns the Field subclass to be used, and the updated `val` if necessary.

        TN)r½rn)rIr{rHr¥rJrJrKÚ_find_fld_pkt_valÛs	z#MultipleTypeField._find_fld_pkt_valcCsrt ¡jj}x^|dk	rjy|jd}Wntk
r8Yn*Xt|t|jjƒƒrb|j	sX|jS| 
|¡S|j}qW|jS)a½Returns the Field subclass to be used, depending on the Packet
instance, or the default subclass.

DEV: since the Packet instance is not provided, we have to use a hack
to guess it. It should only be used if you cannot provide the current
Packet instance (for example, because of the current Scapy API).

If you have the current Packet instance, use ._find_fld_pkt_val() (if
the value to set is also known) of ._find_fld_pkt() instead.

        NrI)ÚinspectÚcurrentframeÚf_backÚf_localsÚKeyErrorrtr¼r·rpZdefault_fieldsr¾)rIÚframer{rJrJrKÚ	_find_fldés


zMultipleTypeField._find_fldcCs| |¡ ||¡S)N)r¾rŒ)rIr{rˆrJrJrKrŒszMultipleTypeField.getfieldcCs| ||¡\}}| |||¡S)N)r¿rŠ)rIr{rˆrHr¥rJrJrKrŠszMultipleTypeField.addfieldcCs| ||¡\}}| ||¡S)N)r¿rw)rIr{rHr¥rJrJrKrwszMultipleTypeField.any2icCs| ||¡\}}| ||¡S)N)r¿r€)rIr{rHr¥rJrJrKr€szMultipleTypeField.h2icCs| ||¡\}}| ||¡S)N)r¿r)rIr{rHr¥rJrJrKrszMultipleTypeField.i2hcCs| ||¡\}}| ||¡S)N)r¿rƒ)rIr{rHr¥rJrJrKrƒ%szMultipleTypeField.i2mcCs| ||¡\}}| ||¡S)N)r¿r})rIr{rHr¥rJrJrKr}*szMultipleTypeField.i2lencCs| ||¡\}}| ||¡S)N)r¿r…)rIr{rHr¥rJrJrKr…/szMultipleTypeField.i2reprcCs2x|jD]\}}|j |¡qW|jj |¡dS)N)r¶rpr]r·)rIryr¥Ú_rJrJrKrz4sz MultipleTypeField.register_ownercCs| ¡S)N)rÆ)rIrJrJrKr¥:szMultipleTypeField.fldN)rSrTrUrVrŸrLr½r¾r¿rÆrŒrŠrwr€rrƒr}r…rzÚpropertyr¥rJrJrJrKrµ“s"	rµc@s<eZdZdZdddgZddd„Zdd	„Zd
d„Zdd
„ZdS)ÚPadFieldzhAdd bytes after the proxified field so that it ends at the specified
       alignment from its beginningr¥Ú_alignÚ_padwithNcCs||_||_|pd|_dS)Nó)r¥rÊrË)rIr¥ZalignZpadwithrJrJrKrLEszPadField.__init__cCs||jS)N)rÊ)rIZflenrJrJrKÚpadlenKszPadField.padlencCs8|j ||¡\}}| t|ƒt|ƒ¡}||d…|fS)N)r¥rŒrÍrP)rIr{rˆÚremainrHrÍrJrJrKrŒOszPadField.getfieldcCs4|j |d|¡}||t d| t|ƒ¡|j¡S)NrGz%is)r¥rŠrqr†rÍrPrË)rIr{rˆrHÚsvalrJrJrKrŠXs

zPadField.addfield)N)	rSrTrUrVrŸrLrÍrŒrŠrJrJrJrKrÉ@s

	rÉc@s eZdZdZdd„Zdd„ZdS)ÚReversePadFieldzkAdd bytes BEFORE the proxified field so that it starts at the specified
       alignment from its beginningcCs:| t|jƒt|ƒ¡}|j |||d…¡\}}||fS)N)rÍrPÚoriginalr¥rŒ)rIr{rˆrÍrÎrHrJrJrKrŒkszReversePadField.getfieldcCs4|j |d|¡}|t d| t|ƒ¡|j¡|S)NrGz%is)r¥rŠrqr†rÍrPrË)rIr{rˆrHrÏrJrJrKrŠuszReversePadField.addfieldN)rSrTrUrVrŒrŠrJrJrJrKrÐgs
rÐc@s(eZdZdZdd„Zdd„Zdd„ZdS)	ÚFCSFieldzSpecial Field that gets its value from the end of the *packet*
    (Note: not layer, but packet).

    Mostly used for FCS
    c	sX|j‰| |t |j||jd…¡d¡}‡fdd„}t||ƒ|_|d|j…|fS)Nrcsd|_ˆ|_ˆ|ƒS)N)Zraw_packet_cacheÚpost_dissect)rIrˆ)Úprevious_post_dissectrJrKÚ
_post_dissectsz(FCSField.getfield.<locals>._post_dissect)rÓr‚rqr‹rmror)rIr{rˆrHrÕrJ)rÔrKrŒˆs
&zFCSField.getfieldcs:|j‰t |j| ||¡¡‰‡‡fdd„}t||ƒ|_|S)Ncs|ˆ7}ˆ|_ˆ||ƒS)N)Ú
post_build)rIÚpZpay)Úprevious_post_buildrbrJrKÚ_post_build›sz&FCSField.addfield.<locals>._post_build)rÖrqr†rmrƒr)rIr{rˆrHrÙrJ)rØrbrKrŠ–s
zFCSField.addfieldcCst| ||¡ƒS)N)r&r)rIr{r|rJrJrKr…£szFCSField.i2reprN)rSrTrUrVrŒrŠr…rJrJrJrKrҁs
rÒc@s2eZdZdgZiZdd„Zdd„Zedd„ƒZdS)	Ú	DestFieldÚ
defaultdstcCs
||_dS)N)rÛ)rIrlrnrJrJrKrL­szDestField.__init__c	s`xX|j ˆjjg¡D]B\}}y$t‡fdd„t |¡Dƒƒr>|SWqtk
rTYqXqW|jS)Nc3s"|]\}}ˆj |¡|kVqdS)N)ÚpayloadZgetfieldval)r“Úfieldrb)r{rJrKr”µsz)DestField.dst_from_pkt.<locals>.<genexpr>)	ÚbindingsÚgetrÜr\ÚallÚsixÚ	iteritemsÚAttributeErrorrÛ)rIr{ÚaddrÚ	conditionrJ)r{rKÚdst_from_pkt±s
zDestField.dst_from_pktcKs|j |g¡ ||f¡dS)N)rÞÚ
setdefaultr])ryZlayerrärårJrJrKÚ	bind_addr¼szDestField.bind_addrN)	rSrTrUrŸrÞrLræÚclassmethodrèrJrJrJrKrÚ¨s
rÚc@s<eZdZdd„Zdd„Zdd„Zdd„Zd	d
„Zdd„Zd
S)ÚMACFieldcCst |||d¡dS)NZ6s)rkrL)rIrlrnrJrJrKrLÅszMACField.__init__c	Cs@|dkrdSyt|ƒ}Wn"tjtfk
r:t|ƒ}YnX|S)Ns)r'rqr‡Ú
OverflowErrorr!)rIr{r|ÚyrJrJrKrƒÉszMACField.i2mcCst|ƒS)N)r()rIr{r|rJrJrKr‚ÓszMACField.m2icCs,t|tƒr"t|ƒdkr"| ||¡Stt|ƒS)Né)rtÚbytesrPr‚rCrM)rIr{r|rJrJrKrw×szMACField.any2icCs6| ||¡}|dkrt|ƒS|tjkr2tj |¡}|S)N)rr„rÚresolveÚmanufdbZ_resolve_MAC)rIr{r|rJrJrKr…Ýs
zMACField.i2reprcCstƒS)N)r)rIrJrJrKržæszMACField.randvalN)	rSrTrUrLrƒr‚rwr…ržrJrJrJrKrêÄs
	rêc@sTeZdZdd„Zdd„Zdd„Zdd„Zd	d
„Zdd„Zd
d„Z	dd„Z
dd„ZdS)ÚIPFieldcCst |||d¡dS)NZ4s)rkrL)rIrlrnrJrJrKrLìszIPField.__init__csht|tƒrt|ƒ}t|tƒrFyt|ƒWqdtjk
rBt|ƒSXnt|tƒrd‡‡fdd„|DƒS|S)Ncsg|]}ˆ ˆ|¡‘qSrJ)r€)r“Ún)r{rIrJrKú
<listcomp>úszIPField.h2i.<locals>.<listcomp>)	rtrîrrMr$Úsocketr‡r1r)rIr{r|rJ)r{rIrKr€ðs


zIPField.h2icCs
tt|ƒS)N)rCrM)rIr{r|rJrJrKrýszIPField.i2hcCs>|tjkr:yt |¡d}Wntk
r0Yn
X|r:|S|S)Nr)rrïrôÚ
gethostbyaddrÚ	Exception)rIr|ÚretrJrJrKrïs
zIPField.resolvecCs|dkrdStt|ƒƒS)Ns)r$r)rIr{r|rJrJrKrƒ
szIPField.i2mcCst|ƒS)N)r%)rIr{r|rJrJrKr‚szIPField.m2icCs| ||¡S)N)r€)rIr{r|rJrJrKrwsz
IPField.any2icCs(| | ||¡¡}t|tƒr |St|ƒS)N)rïrrtrMr„)rIr{r|ÚrrJrJrKr…szIPField.i2reprcCstƒS)N)r)rIrJrJrKrž szIPField.randvalN)rSrTrUrLr€rrïrƒr‚rwr…ržrJrJrJrKrñës
rñcs>eZdZdgZdd„Zdd„Z‡fdd„Z‡fdd	„Z‡ZS)
Ú
SourceIPFieldÚdstnamecCst ||d¡||_dS)N)rñrLrú)rIrlrúrJrJrKrL(szSourceIPField.__init__cCs‚tjdkrddl}|jdkr dnt||jƒp.d}t|ttfƒrrdd„|Dƒ}t|ƒdkrft	d|fƒt
|ƒdStj |¡dS)Nrz0.0.0.0cSsh|]}tj t|ƒ¡’qSrJ)rÚrouterM)r“ÚdaddrrJrJrKú	<setcomp>5sz+SourceIPField.__findaddr.<locals>.<setcomp>r~z#More than one possible route for %r)rrûZscapy.routerúr¤rtr0rrPr4Úmin)rIr{ÚscapyÚdstrørJrJrKZ
__findaddr-s
zSourceIPField.__findaddrcs,|dkr|dk	r| |¡}tt|ƒ ||¡S)N)Ú_SourceIPField__findaddrrYrùrƒ)rIr{r|)r\rJrKrƒ>s
zSourceIPField.i2mcs,|dkr|dk	r| |¡}tt|ƒ ||¡S)N)rrYrùr)rIr{r|)r\rJrKrDs
zSourceIPField.i2h)	rSrTrUrŸrLrrƒrrhrJrJ)r\rKrù%s
rùc@sLeZdZdd„Zdd„Zdd„Zdd„Zd	d
„Zdd„Zd
d„Z	dd„Z
dS)ÚIP6FieldcCst |||d¡dS)NÚ16s)rkrL)rIrlrnrJrJrKrLLszIP6Field.__init__csht|tƒrt|ƒ}t|tƒrFyt|ƒ}Wqdtjk
rBt|ƒSXnt|tƒrd‡‡fdd„|Dƒ}|S)Ncsg|]}ˆ ˆ|¡‘qSrJ)r€)r“rò)r{rIrJrKróZsz IP6Field.h2i.<locals>.<listcomp>)	rtrîrrMr-rôr‡r.r)rIr{r|rJ)r{rIrKr€Ps


zIP6Field.h2icCs
tt|ƒS)N)rCrM)rIr{r|rJrJrKr]szIP6Field.i2hcCs|dkrd}ttjt|ƒƒS)Nz::)r#rôÚAF_INET6r)rIr{r|rJrJrKrƒaszIP6Field.i2mcCsttj|ƒS)N)r"rôr)rIr{r|rJrJrKr‚gszIP6Field.m2icCs| ||¡S)N)r€)rIr{r|rJrJrKrwkszIP6Field.any2ic	Csž|dkr| ||¡St|tƒs|t|tƒs|t|ƒrXt|ƒ\}}}}d| ||¡|||fSt|ƒr|t|ƒ}d| ||¡|fS| ||¡}t|tƒr–|St	|ƒS)Nz%s [Teredo srv: %s cli: %s:%s]z%s [6to4 GW: %s])
rrtr.rr,r/r+r*rMr„)	rIr{r|ÚserverrÇZmaddrZmportZvaddrrørJrJrKr…oszIP6Field.i2reprcCstƒS)N)r)rIrJrJrKrž}szIP6Field.randvalN)rSrTrUrLr€rrƒr‚rwr…ržrJrJrJrKrKs
rcs6eZdZdgZdd„Z‡fdd„Z‡fdd„Z‡ZS)ÚSourceIP6FieldrúcCst ||d¡||_dS)N)rrLrú)rIrlrúrJrJrKrL…szSourceIP6Field.__init__csJ|dkr8|jdkrdnt||jƒp$d}tj |¡\}}}tt|ƒ ||¡S)Nz::)rúr¤rÚroute6rûrYrrƒ)rIr{r|rZiffZnh)r\rJrKrƒŠs
zSourceIP6Field.i2mcsš|dkrˆtjdkrddl}|jdkr(dn
t||jƒ}t|ttfƒrxdd„|Dƒ}t|ƒdkrjt	d|fƒt
|ƒd}ntj |¡d}tt
|ƒ ||¡S)Nrz::cSsh|]}tj t|ƒ¡’qSrJ)rrrûrM)r“rürJrJrKrýšsz%SourceIP6Field.i2h.<locals>.<setcomp>r~z#More than one possible route for %r)rrZscapy.route6rúr¤rtr0rrPr4rþrûrYrr)rIr{r|rÿrrø)r\rJrKr’s
zSourceIP6Field.i2h)rSrTrUrŸrLrƒrrhrJrJ)r\rKr‚srcs0eZdZiZdd„Zdd„Z‡fdd„Z‡ZS)ÚDestIP6FieldcCs t ||d¡t |||¡dS)N)rrLrÚ)rIrlrnrJrJrKrL§szDestIP6Field.__init__cCs(|dkr|dk	r| |¡}t |||¡S)N)rærrƒ)rIr{r|rJrJrKrƒ¬s
zDestIP6Field.i2mcs,|dkr|dk	r| |¡}tt|ƒ ||¡S)N)rærYrr)rIr{r|)r\rJrKr²s
zDestIP6Field.i2h)rSrTrUrÞrLrƒrrhrJrJ)r\rKr¤src@seZdZdd„ZdS)Ú	ByteFieldcCst |||d¡dS)Nr—)rkrL)rIrlrnrJrJrKrLºszByteField.__init__N)rSrTrUrLrJrJrJrKr	¹sr	c@seZdZdd„ZdS)Ú
XByteFieldcCst| ||¡ƒS)N)r&r)rIr{r|rJrJrKr…ÀszXByteField.i2reprN)rSrTrUr…rJrJrJrKr
¿sr
c@seZdZdd„ZdS)Ú
OByteFieldcCsd| ||¡S)Nz%03o)r)rIr{r|rJrJrKr…ÇszOByteField.i2reprN)rSrTrUr…rJrJrJrKrÆsrc@s$eZdZdd„Zdd„Zdd„ZdS)ÚThreeBytesFieldcCst |||d¡dS)Nz!I)rkrL)rIrlrnrJrJrKrLÍszThreeBytesField.__init__cCs"|t |j| ||¡¡dd…S)Nr~é)rqr†rmrƒ)rIr{rˆrHrJrJrKrŠÑszThreeBytesField.addfieldcCs2|dd…| |t |jd|dd…¡d¡fS)NérÌr)r‚rqr‹rm)rIr{rˆrJrJrKrŒÕszThreeBytesField.getfieldN)rSrTrUrLrŠrŒrJrJrJrKrÌsrc@seZdZdd„ZdS)ÚX3BytesFieldcCst |||¡S)N)r
r…)rIr{r|rJrJrKr…ÛszX3BytesField.i2reprN)rSrTrUr…rJrJrJrKrÚsrc@s$eZdZdd„Zdd„Zdd„ZdS)ÚLEThreeBytesFieldcCst |||d¡dS)Nz<I)rkrL)rIrlrnrJrJrKrLászLEThreeBytesField.__init__cCs"|t |j| ||¡¡dd…S)Nr)rqr†rmrƒ)rIr{rˆrHrJrJrKrŠåszLEThreeBytesField.addfieldc
Cs2|dd…| |t |j|dd…d¡d¡fS)NrrÌr)r‚rqr‹rm)rIr{rˆrJrJrKrŒészLEThreeBytesField.getfieldN)rSrTrUrLrŠrŒrJrJrJrKràsrc@seZdZdd„ZdS)ÚLEX3BytesFieldcCst |||¡S)N)r
r…)rIr{r|rJrJrKr…ïszLEX3BytesField.i2reprN)rSrTrUr…rJrJrJrKrîsrcsDeZdZdd„Zdd„Zdd„Z‡fdd„Zd	d
„Zdd„Z‡Z	S)
ÚNBytesFieldcCst |||dd|¡dS)Nú<r—)rkrL)rIrlrnrorJrJrKrLõszNBytesField.__init__cCsJ|dkrgStƒ}x(t|jƒD]}| |d¡|d}qW|ddd…S)Nér–)rr5ror])rIr{r|Zx2mrÇrJrJrKrƒùszNBytesField.i2mcCs6t|tƒr|St|ttfƒr2tdd„t|ƒDƒƒSdS)Ncss|]\}}|d|VqdS)rNrJ)r“rÚdrJrJrKr”	sz"NBytesField.m2i.<locals>.<genexpr>r)rtrrr¼ÚsumÚ	enumerate)rIr{r|rJrJrKr‚s

zNBytesField.m2ics$t|tƒrd|Stt|ƒ ||¡S)Nz%i)rtr6rYrr…)rIr{r|)r\rJrKr…s
zNBytesField.i2reprcCs||jj| ||¡ŽS)N)rqr†rƒ)rIr{rˆrHrJrJrKrŠszNBytesField.addfieldc	Cs,||jd…| ||j |d|j…¡¡fS)N)ror‚rqr‹)rIr{rˆrJrJrKrŒszNBytesField.getfield)
rSrTrUrLrƒr‚r…rŠrŒrhrJrJ)r\rKrôs
	rcseZdZ‡fdd„Z‡ZS)ÚXNBytesFieldcsJt|tƒrd|St|ttfƒr8dd dd„|Dƒ¡Stt|ƒ ||¡S)Nz0x%xÚ0xÚcss|]}d|VqdS)z%02xNrJ)r“r˜rJrJrKr”#sz&XNBytesField.i2repr.<locals>.<genexpr>)rtr6rr¼r•rYrr…)rIr{r|)r\rJrKr…s

zXNBytesField.i2repr)rSrTrUr…rhrJrJ)r\rKrsrc@seZdZdd„ZdS)ÚSignedByteFieldcCst |||d¡dS)Nr˜)rkrL)rIrlrnrJrJrKrL(szSignedByteField.__init__N)rSrTrUrLrJrJrJrKr'src@seZdZdS)ÚFieldValueRangeExceptionN)rSrTrUrJrJrJrKr-src@seZdZdS)ÚFieldAttributeExceptionN)rSrTrUrJrJrJrKr1src@s0eZdZdZdgZdd„Zd
dd„Zdd	„ZdS)ÚYesNoByteFielda–
    A byte based flag field that shows representation of its number
    based on a given association

    In its default configuration the following representation is generated:
        x == 0 : 'no'
        x != 0 : 'yes'

    In more sophisticated use-cases (e.g. yes/no/invalid) one can use the
    config attribute to configure.
    Key-value, key-range and key-value-set associations that will be used to
    generate the values representation.

    - A range is given by a tuple (<first-val>, <last-value>) including the
      last value.
    - A single-value tuple is treated as scalar.
    - A list defines a set of (probably non consecutive) values that should be
      associated to a given key.

    All values not associated with a key will be shown as number of type
    unsigned byte.

    **For instance**::

        config = {
            'no' : 0,
            'foo' : (1,22),
            'yes' : 23,
            'bar' : [24,25, 42, 48, 87, 253]
        }

    Generates the following representations::

        x == 0 : 'no'
        x == 15: 'foo'
        x == 23: 'yes'
        x == 42: 'bar'
        x == 43: 43

    Another example, using the config attribute one could also revert
    the stock-yes-no-behavior::

        config = {
                'yes' : 0,
                'no' : (1,255)
        }

    Will generate the following value representation::

        x == 0 : 'yes'
        x != 0 : 'no'

    Úeval_fnc	s@tƒ‰x$|D]}||}t|ƒ}|tkrT|dks<|dkrJtd |¡ƒ‚|ˆ|<q|tkr’xÌ|D]*}|dksv|dkr„td |¡ƒ‚|ˆ|<qbWq|tkrt|ƒ}|dkrºtd ||¡ƒ‚|d}|dksÒ|dkràtd |¡ƒ‚|d}|dksú|dkrtd |¡ƒ‚x t	||dƒD]}|ˆ|<qWqW‡fdd„|_
dS)	Nréÿz8given field value {} invalid - must be in range [0..255]ézWinvalid length {} of given config item tuple {} - must be (<start-range>, <end-range>).r~cs|ˆkrˆ|S|S)NrJ)r|)Úassoc_tablerJrKÚ<lambda>–rGz=YesNoByteField._build_config_representation.<locals>.<lambda>)Údictr´rrÚformatrr¼rPrr5r)	rIÚconfigraZ
value_specZvalue_spec_typerbZvalue_spec_lenZvalue_range_startZvalue_range_endrJ)r"rKÚ_build_config_representationms>


z+YesNoByteField._build_config_representationNcCs,|sdd„|_n
| |¡t |||¡dS)NcSs|dkrdSdS)NrÚnoÚyesrJ)r|rJrJrKr#rGz)YesNoByteField.__init__.<locals>.<lambda>)rr'r	rL)rIrlrnr&rJrJrKrL˜s
zYesNoByteField.__init__cCs
| |¡S)N)r)rIr{r|rJrJrKr…¢szYesNoByteField.i2repr)N)rSrTrUrVrŸr'rLr…rJrJrJrKr5s
5+

rc@seZdZdd„ZdS)Ú
ShortFieldcCst |||d¡dS)Nrr)rkrL)rIrlrnrJrJrKrL¨szShortField.__init__N)rSrTrUrLrJrJrJrKr*§sr*c@seZdZdd„ZdS)ÚSignedShortFieldcCst |||d¡dS)Nr™)rkrL)rIrlrnrJrJrKrL®szSignedShortField.__init__N)rSrTrUrLrJrJrJrKr+­sr+c@seZdZdd„ZdS)ÚLEShortFieldcCst |||d¡dS)Nz<H)rkrL)rIrlrnrJrJrKrL´szLEShortField.__init__N)rSrTrUrLrJrJrJrKr,³sr,c@seZdZdd„ZdS)ÚLESignedShortFieldcCst |||d¡dS)Nz<h)rkrL)rIrlrnrJrJrKrLºszLESignedShortField.__init__N)rSrTrUrLrJrJrJrKr-¹sr-c@seZdZdd„ZdS)ÚXShortFieldcCst| ||¡ƒS)N)r&r)rIr{r|rJrJrKr…ÀszXShortField.i2reprN)rSrTrUr…rJrJrJrKr.¿sr.c@seZdZdd„ZdS)ÚIntFieldcCst |||d¡dS)Nri)rkrL)rIrlrnrJrJrKrLÆszIntField.__init__N)rSrTrUrLrJrJrJrKr/Åsr/c@seZdZdd„ZdS)ÚSignedIntFieldcCst |||d¡dS)Nr)rkrL)rIrlrnrJrJrKrLÌszSignedIntField.__init__N)rSrTrUrLrJrJrJrKr0Ësr0c@seZdZdd„ZdS)Ú
LEIntFieldcCst |||d¡dS)Nz<I)rkrL)rIrlrnrJrJrKrLÒszLEIntField.__init__N)rSrTrUrLrJrJrJrKr1Ñsr1c@seZdZdd„ZdS)ÚLESignedIntFieldcCst |||d¡dS)Nz<i)rkrL)rIrlrnrJrJrKrLØszLESignedIntField.__init__N)rSrTrUrLrJrJrJrKr2×sr2c@seZdZdd„ZdS)Ú	XIntFieldcCst| ||¡ƒS)N)r&r)rIr{r|rJrJrKr…ÞszXIntField.i2reprN)rSrTrUr…rJrJrJrKr3Ýsr3c@seZdZdd„ZdS)ÚXLEIntFieldcCst |||¡S)N)r3r…)rIr{r|rJrJrKr…äszXLEIntField.i2reprN)rSrTrUr…rJrJrJrKr4ãsr4c@seZdZdd„ZdS)Ú
XLEShortFieldcCst |||¡S)N)r.r…)rIr{r|rJrJrKr…êszXLEShortField.i2reprN)rSrTrUr…rJrJrJrKr5ésr5c@seZdZdd„ZdS)Ú	LongFieldcCst |||d¡dS)Nrš)rkrL)rIrlrnrJrJrKrLðszLongField.__init__N)rSrTrUrLrJrJrJrKr6ïsr6c@seZdZdd„ZdS)ÚSignedLongFieldcCst |||d¡dS)Nr›)rkrL)rIrlrnrJrJrKrLöszSignedLongField.__init__N)rSrTrUrLrJrJrJrKr7õsr7c@seZdZdd„ZdS)ÚLELongFieldcCst |||d¡dS)Nz<Q)rkrL)rIrlrnrJrJrKrLüszLELongField.__init__N)rSrTrUrLrJrJrJrKr8ûsr8c@seZdZdd„ZdS)ÚLESignedLongFieldcCst |||d¡dS)Nz<q)rkrL)rIrlrnrJrJrKrLszLESignedLongField.__init__N)rSrTrUrLrJrJrJrKr9sr9c@seZdZdd„ZdS)Ú
XLongFieldcCst| ||¡ƒS)N)r&r)rIr{r|rJrJrKr…szXLongField.i2reprN)rSrTrUr…rJrJrJrKr:sr:c@seZdZdd„ZdS)ÚXLELongFieldcCst |||¡S)N)r:r…)rIr{r|rJrJrKr…szXLELongField.i2reprN)rSrTrUr…rJrJrJrKr;
sr;c@seZdZdd„ZdS)ÚIEEEFloatFieldcCst |||d¡dS)NÚf)rkrL)rIrlrnrJrJrKrLszIEEEFloatField.__init__N)rSrTrUrLrJrJrJrKr<sr<c@seZdZdd„ZdS)ÚIEEEDoubleFieldcCst |||d¡dS)Nr)rkrL)rIrlrnrJrJrKrLszIEEEDoubleField.__init__N)rSrTrUrLrJrJrJrKr>sr>cs`eZdZdgZddd„Zdd„Z‡fdd	„Z‡fd
d„Zdd
„Zdd„Z	dd„Z
dd„Z‡ZS)Ú	_StrFieldrÎrrrcCst ||||¡||_dS)N)rkrLrÎ)rIrlrnrmrÎrJrJrKrL"sz_StrField.__init__cCs|dkrdSt|ƒS)Nr)rP)rIr{r|rJrJrKr}'sz_StrField.i2lencs&t|tjƒrt|ƒ}tt|ƒ ||¡S)N)rtráÚ	text_typer!rYr?rw)rIr{r|)r\rJrKrw-sz_StrField.any2ics(t|tƒrtt|ƒƒStt|ƒ ||¡S)N)rtrîr„rrYr?r…)rIr{r|)r\rJrKr…3s
z_StrField.i2reprcCs"|dkrdSt|tƒst|ƒS|S)NrG)rtrîr!)rIr{r|rJrJrKrƒ9s

z
_StrField.i2mcCs|| ||¡S)N)rƒ)rIr{rˆrHrJrJrKrŠAsz_StrField.addfieldcCsF|jdkrd| ||¡fS||jd…| ||d|j…¡fSdS)NrrG)rÎr‚)rIr{rˆrJrJrKrŒEs
z_StrField.getfieldcCsttddƒƒS)Nri°)rr)rIrJrJrKržLsz_StrField.randval)rrr)
rSrTrUrŸrLr}rwr…rƒrŠrŒržrhrJrJ)r\rKr?s
r?c@seZdZdS)ÚStrFieldN)rSrTrUrJrJrJrKrAQsrAcs4eZdZdd„Z‡fdd„Zdd„Zdd„Z‡ZS)	Ú
StrFieldUtf16cCst|ƒ d¡dd…S)Nzutf-16r!)rÚencode)rIr{r|rJrJrKr€VszStrFieldUtf16.h2ics*t|tjƒr| ||¡Stt|ƒ ||¡S)N)rtrár@r€rYrBrw)rIr{r|)r\rJrKrwZszStrFieldUtf16.any2icCst|ƒS)N)r)rIr{r|rJrJrKr…`szStrFieldUtf16.i2reprcCst|ƒ d¡S)Nzutf-16)r!Údecode)rIr{r|rJrJrKrdszStrFieldUtf16.i2h)rSrTrUr€rwr…rrhrJrJ)r\rKrBUsrBÚKcsFeZdZdgZdZ‡fdd„Zdd„Zdd„Zd	d
„Zdd„Z	‡Z
S)
Ú_PacketFieldryr~cstt|ƒ ||¡||_dS)N)rYrFrLry)rIrlrnÚpkt_cls)r\rJrKrLpsz_PacketField.__init__cCs|dkrdSt|ƒS)NrG)r )rIr{rrJrJrKrƒysz_PacketField.i2mcCs
| |¡S)N)ry)rIr{ÚmrJrJrKr‚‚sz_PacketField.m2icCs8| ||¡}d}tj|kr0|tj}|j`|j}||fS)NrG)r‚rÚ
padding_layerÚ
underlayerrÜÚload)rIr{rˆrrÎrørJrJrKrŒ†s

z_PacketField.getfieldcCsddlm}|| ¡ƒS)Nr)Úfuzz)Úscapy.packetrLry)rIrLrJrJrKrž“sz_PacketField.randval)rSrTrUrŸr¢rLrƒr‚rŒržrhrJrJ)r\rKrFls		
rFc@seZdZdS)ÚPacketFieldN)rSrTrUrJrJrJrKrN™srNcs,eZdZdgZd‡fdd„	Zdd„Z‡ZS)ÚPacketLenFieldÚlength_fromNcs&tt|ƒ |||¡|pdd„|_dS)NcSsdS)NrrJ)r|rJrJrKr#¨rGz)PacketLenField.__init__.<locals>.<lambda>)rYrOrLrP)rIrlrnryrP)r\rJrKrL szPacketLenField.__init__cCsd| |¡}y| ||d|…¡}Wn0tk
rRtjr:‚tj|d|…d}YnX||d…|fS)N)rK)rPr‚rörÚdebug_dissectorÚ	raw_layer)rIr{rˆÚlen_pktrrJrJrKrŒªs
zPacketLenField.getfield)N)rSrTrUrŸrLrŒrhrJrJ)r\rKrOsrOcsXeZdZdZdddgZdZd‡fdd„	Zd	d
„Zdd„Zd
d„Z	dd„Z
dd„Z‡ZS)ÚPacketListFielda7PacketListField represents a series of Packet instances that might
    occur right in the middle of another Packet field list.
    This field type may also be used to indicate that a series of Packet
    instances have a sibling semantic instead of a parent/child relationship
    (i.e. a stack of layers).
    Ú
count_fromrPÚnext_cls_cbr~Ncs6|dkrg}tt|ƒ |||¡||_||_||_dS)aˆ
        The number of Packet instances that are dissected by this field can
        be parametrized using one of three different mechanisms/parameters:

            * count_from: a callback that returns the number of Packet
              instances to dissect. The callback prototype is::

                count_from(pkt:Packet) -> int

            * length_from: a callback that returns the number of bytes that
              must be dissected by this field. The callback prototype is::

                length_from(pkt:Packet) -> int

            * next_cls_cb: a callback that enables a Scapy developer to
              dynamically discover if another Packet instance should be
              dissected or not. See below for this callback prototype.

        The bytes that are not consumed during the dissection of this field
        are passed to the next field of the current packet.

        For the serialization of such a field, the list of Packets that are
        contained in a PacketListField can be heterogeneous and is
        unrestricted.

        The type of the Packet instances that are dissected with this field is
        specified or discovered using one of the following mechanism:

            * the pkt_cls parameter may contain a callable that returns an
              instance of the dissected Packet. This may either be a
              reference of a Packet subclass (e.g. DNSRROPT in layers/dns.py)
              to generate an homogeneous PacketListField or a function
              deciding the type of the Packet instance
              (e.g. _CDPGuessAddrRecord in contrib/cdp.py)

            * the pkt_cls parameter may contain a class object with a defined
              ``dispatch_hook`` classmethod. That method must return a Packet
              instance. The ``dispatch_hook`` callmethod must implement the
                following prototype::

                dispatch_hook(cls,
                              _pkt:Optional[Packet],
                              *args, **kargs
                ) -> Type[Packet]

                The _pkt parameter may contain a reference to the packet
                instance containing the PacketListField that is being
                dissected.

            * the ``next_cls_cb`` parameter may contain a callable whose
              prototype is::

                cbk(pkt:Packet,
                    lst:List[Packet],
                    cur:Optional[Packet],
                    remain:str
                ) -> Optional[Type[Packet]]

              The pkt argument contains a reference to the Packet instance
              containing the PacketListField that is being dissected.
              The lst argument is the list of all Packet instances that were
              previously parsed during the current ``PacketListField``
              dissection, saved for the very last Packet instance.
              The cur argument contains a reference to that very last parsed
              ``Packet`` instance. The remain argument contains the bytes
              that may still be consumed by the current PacketListField
              dissection operation.

              This callback returns either the type of the next Packet to
              dissect or None to indicate that no more Packet are to be
              dissected.

              These four arguments allows a variety of dynamic discovery of
              the number of Packet to dissect and of the type of each one of
              these Packets, including: type determination based on current
              Packet instances or its underlayers, continuation based on the
              previously parsed Packet instances within that PacketListField,
              continuation based on a look-ahead on the bytes to be
              dissected...

        The pkt_cls and next_cls_cb parameters are semantically exclusive,
        although one could specify both. If both are specified, pkt_cls is
        silently ignored. The same is true for count_from and next_cls_cb.

        length_from and next_cls_cb are compatible and the dissection will
        end, whichever of the two stop conditions comes first.

        :param name: the name of the field
        :param default: the default value of this field; generally an empty
            Python list
        :param pkt_cls: either a callable returning a Packet instance or a
            class object defining a ``dispatch_hook`` class method
        :param count_from: a callback returning the number of Packet
            instances to dissect.
        :param length_from: a callback returning the number of bytes to dissect
        :param next_cls_cb: a callback returning either None or the type of
            the next Packet to dissect.
        N)rYrTrLrUrPrV)rIrlrnrGrUrPrV)r\rJrKrLÃsl
zPacketListField.__init__cCst|tƒs|gS|SdS)N)rtr)rIr{r|rJrJrKrw:s
zPacketListField.any2icCst|tƒrt|ƒSdS)Nr~)rtrrP)rIr{rHrJrJrKrAs
zPacketListField.i2countcCstdd„|DƒƒS)Ncss|]}t|ƒVqdS)N)rP)r“r×rJrJrKr”Osz(PacketListField.i2len.<locals>.<genexpr>)r)rIr{rHrJrJrKr}JszPacketListField.i2lencCs„d}}}|jdk	r"| |¡}n|jdk	r6| |¡}|jdk	r`| |gd|¡}d}|dkr`d}g}d}|}|dk	rŽ|d|…||d…}}xè|rv|dk	r°|dkr¨P|d8}y"|dk	rÄ||ƒ}	n| ||¡}	Wn.tk
rtjrì‚tj|d}	d}YnjXtj|	krf|	tj}
|
j	}|
j
`|jdk	rj| |||	|¡}|dk	rj|dkrXdn|}|d7}nd}| |	¡qW|||fS)Nr~rrG)rK)
rPrUrVr‚rörrQrRrIrKrJrÜr])rIr{rˆÚcrSryÚlstr÷rÎr×ÚpadrJrJrKrŒQsR








zPacketListField.getfieldcCs|d dd„|Dƒ¡S)NrGcss|]}t|ƒVqdS)N)r!)r“ÚvrJrJrKr”ƒsz+PacketListField.addfield.<locals>.<genexpr>)r•)rIr{rˆrHrJrJrKrЁszPacketListField.addfield)NNNN)
rSrTrUrVrŸr rLrwrr}rŒrŠrhrJrJ)r\rKrT¹s
p	0rTcsHeZdZdgZd
‡fdd„	Z‡fdd„Zdd„Zd	d
„Zdd„Z‡Z	S)ÚStrFixedLenFieldrPNcs:tt|ƒ ||¡|pdd„|_|dk	r6|fdd„|_dS)NcSsdS)NrrJ)r|rJrJrKr#’rGz+StrFixedLenField.__init__.<locals>.<lambda>cSs|S)NrJ)r|ÚlengthrJrJrKr#”rG)rYr[rLrP)rIrlrnr\rP)r\rJrKrL‰szStrFixedLenField.__init__cs&t|tƒr| d¡}tt|ƒ ||¡S)NrÌ)rtrîÚrstriprYr[r…)rIr{rZ)r\rJrKr…–s

zStrFixedLenField.i2reprcCs*| |¡}||d…| ||d|…¡fS)N)rPr‚)rIr{rˆrSrJrJrKrŒŸs
zStrFixedLenField.getfieldcCs>| |¡}|dkr"|| ||¡S|t d|| ||¡¡S)Nz%is)rPrƒrqr†)rIr{rˆrHrSrJrJrKrФs
zStrFixedLenField.addfieldcCs6y| d¡}Wntk
r,tddƒ}YnXt|ƒS)NréÈ)rPrörr)rIrSrJrJrKrž«s
zStrFixedLenField.randval)NN)
rSrTrUrŸrLr…rŒrŠržrhrJrJ)r\rKr[†s	r[c@s$eZdZdgZddd„Zdd„ZdS)ÚStrFixedLenEnumFieldÚenumNcCstj|||||d||_dS)N)r\rP)r[rLr`)rIrlrnr\r`rPrJrJrKrL·s	zStrFixedLenEnumField.__init__cCs^t|ƒ}| d¡}t|ƒ}|jrZ||jkr>d||j|f}n||jkrZd||j|f}|S)Núz%s (%s))rr]r„r`)rIr{ÚwrZrøÚrrrJrJrKr…Ãs


zStrFixedLenEnumField.i2repr)NNN)rSrTrUrŸrLr…rJrJrJrKr_´s

r_c@s&eZdZd	dd„Zdd„Zdd„ZdS)
ÚNetBIOSNameFieldécCst ||||¡dS)N)r[rL)rIrlrnr\rJrJrKrLÑszNetBIOSNameField.__init__cCsX|r| |¡d}nd}t|p dƒ}|d|7}|d|…}d dd„|Dƒ¡}d|S)Nr!rrGó css6|].}tdt|ƒd?ƒtdt|ƒd@ƒVqdS)éAr
éN)rr)r“r˜rJrJrKr”ßsz'NetBIOSNameField.i2m.<locals>.<genexpr>)rPr!r•)rIr{rìrSr|rJrJrKrƒÕs
zNetBIOSNameField.i2mc	Cs:| d¡ d¡}d tdd„|ddd…|ddd…ƒ¡S)NrÌrfrGcSs(tt|ƒdd@d>t|ƒdd@ƒS)Nr~rhr
)rr)r|rìrJrJrKr#ész&NetBIOSNameField.m2i.<locals>.<lambda>r!r~)Ústripr•Úmap)rIr{r|rJrJrKr‚åszNetBIOSNameField.m2iN)re)rSrTrUrLrƒr‚rJrJrJrKrdÐs
rdcs6eZdZddgZd
‡fdd„	Zdd„Zdd	„Z‡ZS)ÚStrLenFieldrPÚ
max_lengthNcs"tt|ƒ ||¡||_||_dS)N)rYrkrLrPrl)rIrlrnrPrl)r\rJrKrLószStrLenField.__init__cCs2|jpdd„|ƒ}||d…| ||d|…¡fS)NcSsdS)NrrJ)r|rJrJrKr#rGz&StrLenField.getfield.<locals>.<lambda>)rPr‚)rIr{rˆrSrJrJrKrŒÿszStrLenField.getfieldcCsttd|jpdƒƒS)Nri°)rrrl)rIrJrJrKržszStrLenField.randval)NN)rSrTrUrŸrLrŒržrhrJrJ)r\rKrkðs
rkc@seZdZdZdd„ZdS)Ú	XStrFieldz9
    StrField which value is printed as hexadecimal.
    cCs|dkrt|ƒSt|ƒ ¡S)N)r„rrD)rIr{r|rJrJrKr…szXStrField.i2reprN)rSrTrUrVr…rJrJrJrKrm	srmc@seZdZdd„ZdS)Ú
_XStrLenFieldcCs.|st|ƒSt|d|jpdd„|ƒ…ƒ ¡S)NcSsdS)NrrJ)r|rJrJrKr#rGz&_XStrLenField.i2repr.<locals>.<lambda>)r„rrPrD)rIr{r|rJrJrKr…sz_XStrLenField.i2reprN)rSrTrUr…rJrJrJrKrnsrnc@seZdZdZdS)ÚXStrLenFieldz<
    StrLenField which value is printed as hexadecimal.
    N)rSrTrUrVrJrJrJrKrosroc@seZdZdZdS)ÚXStrFixedLenFieldzA
    StrFixedLenField which value is printed as hexadecimal.
    N)rSrTrUrVrJrJrJrKrp%srpc@seZdZdd„Zdd„ZdS)ÚXLEStrLenFieldcCs|sdS|ddd…S)NrGr–rJ)rIr{r|rJrJrKrƒ,szXLEStrLenField.i2mcCs|ddd…S)Nr–rJ)rIr{r|rJrJrKr‚2szXLEStrLenField.m2iN)rSrTrUrƒr‚rJrJrJrKrq+srqcs4eZdZdd„Z‡fdd„Zdd„Zdd„Z‡ZS)	ÚStrLenFieldUtf16cCst|ƒ d¡dd…S)Nzutf-16r!)rrC)rIr{r|rJrJrKr€8szStrLenFieldUtf16.h2ics*t|tjƒr| ||¡Stt|ƒ ||¡S)N)rtrár@r€rYrrrw)rIr{r|)r\rJrKrw<szStrLenFieldUtf16.any2icCst|ƒS)N)r)rIr{r|rJrJrKr…BszStrLenFieldUtf16.i2reprcCst|ƒ d¡S)Nzutf-16)r!rD)rIr{r|rJrJrKrFszStrLenFieldUtf16.i2h)rSrTrUr€rwr…rrhrJrJ)r\rKrr7srrc@s&eZdZddgZd
dd„Zdd	„ZdS)ÚBoundStrLenFieldÚminlenÚmaxlenrr NcCs"tj||||d||_||_dS)N)rP)rkrLrtru)rIrlrnrtrurPrJrJrKrLQs	zBoundStrLenField.__init__cCstt|j|jƒƒS)N)rrrtru)rIrJrJrKrž^szBoundStrLenField.randval)rr N)rSrTrUrŸrLržrJrJrJrKrsNs

rsc@sTeZdZdddgZdZddd„Zdd	„Zd
d„Zdd
„Zdd„Z	dd„Z
dd„ZdS)ÚFieldListFieldrÝrUrPr~NcCs0|dkrg}||_t |||¡||_||_dS)N)rÝrkrLrUrP)rIrlrnrÝrPrUrJrJrKrLgs	zFieldListField.__init__cCst|tƒrt|ƒSdS)Nr~)rtrrP)rIr{rHrJrJrKrws
zFieldListField.i2countcstt‡‡fdd„|DƒƒƒS)Nc3s|]}ˆj ˆ|¡VqdS)N)rÝr})r“rZ)r{rIrJrKr”sz'FieldListField.i2len.<locals>.<genexpr>)rr)rIr{rHrJ)r{rIrKr}}szFieldListField.i2lencs2t|tƒsˆj ˆ|¡gS‡‡fdd„|DƒSdS)Ncsg|]}ˆj ˆ|¡‘qSrJ)rÝrw)r“Úe)r{rIrJrKró†sz(FieldListField.any2i.<locals>.<listcomp>)rtrrÝrw)rIr{r|rJ)r{rIrKrws
zFieldListField.any2icsdd ‡‡fdd„|Dƒ¡S)Nz[%s]z, c3s|]}ˆj ˆ|¡VqdS)N)rÝr…)r“rZ)r{rIrJrKr”sz(FieldListField.i2repr.<locals>.<genexpr>)r•)rIr{r|rJ)r{rIrKr…ˆszFieldListField.i2reprcCs.| ||¡}x|D]}|j |||¡}qW|S)N)rƒrÝrŠ)rIr{rˆrHrZrJrJrKrŠs
zFieldListField.addfieldcCs¨d}}|jdk	r| |¡}n|jdk	r2| |¡}g}d}|dk	r\|d|…||d…}}x>|rš|dk	r||dkrtP|d8}|j ||¡\}}| |¡q^W|||fS)NrGrr~)rPrUrÝrŒr])rIr{rˆrWrSrHr÷rZrJrJrKrŒšs"


zFieldListField.getfield)NN)rSrTrUrŸr rLrr}rwr…rŠrŒrJrJrJrKrvcs


rvc@s4eZdZdddgZddddd„fdd	„Zd
d„ZdS)Ú
FieldLenFieldÚ	length_ofÚcount_ofÚadjustNrrcCs|S)NrJ)r{r|rJrJrKr#¾rGzFieldLenField.<lambda>cCs&t ||||¡||_||_||_dS)N)rkrLryrzr{)rIrlrnryrmrzr{rJrJrKrL·s
zFieldLenField.__init__cCs†|dkrv|dk	rv|jdk	r8| |j¡\}}| ||¡}n0|jdk	r`| |j¡\}}| ||¡}ntdƒ‚| ||¡}n|dkr‚d}|S)Nz.Field should have either length_of or count_ofr)ryZgetfield_and_valr}rzrrur{)rIr{r|r¥Zfvalr=rJrJrKrƒÆs

zFieldLenField.i2m)rSrTrUrŸrLrƒrJrJrJrKrx´s
rxc@s$eZdZdd„Zdd„Zdd„ZdS)ÚStrNullFieldcCs|| ||¡dS)NrÌ)rƒ)rIr{rˆrHrJrJrKrŠÚszStrNullField.addfieldcCs>| d¡}|dkrd|fS||dd…| ||d|…¡fS)NrÌrrGr~)Úfindr‚)rIr{rˆÚlen_strrJrJrKrŒÞs
zStrNullField.getfieldcCsttddƒdƒS)Nri°rÌ)rr)rIrJrJrKržészStrNullField.randvalN)rSrTrUrŠrŒržrJrJrJrKr|Ùsr|c@s.eZdZddgZddd„Zdd„Zdd	„Zd
S)ÚStrStopFieldÚstopÚ
additionalrcCst |||¡||_||_dS)N)rkrLr€r)rIrlrnr€rrJrJrKrLñszStrStopField.__init__cCsH| |j¡}|dkrd|fS|t|jƒ|j7}||d…|d|…fS)NrrG)r}r€rPr)rIr{rˆr~rJrJrKrŒ÷s
zStrStopField.getfieldcCsttddƒ|jƒS)Nri°)rrr€)rIrJrJrKržszStrStopField.randvalN)r)rSrTrUrŸrLrŒržrJrJrJrKrîs
	rc@s0eZdZdZdgZddd„fdd„Zdd	„Zd
S)ÚLenFieldz>
    If None, will be filled with the size of the payload
    r{rrcCs|S)NrJ)r|rJrJrKr#rGzLenField.<lambda>cCst ||||¡||_dS)N)rkrLr{)rIrlrnrmr{rJrJrKrLszLenField.__init__cCs(|dkr$d}|dk	r$| t|jƒ¡}|S)Nr)r{rPrÜ)rIr{r|rJrJrKrƒs
zLenField.i2mN)rSrTrUrVrŸrLrƒrJrJrJrKr‚sr‚c@seZdZdd„Zdd„ZdS)Ú
BCDFloatFieldcCs|dkrdStd|ƒS)Nrr)r)rIr{r|rJrJrKrƒszBCDFloatField.i2mcCs|dS)Ngp@rJ)rIr{r|rJrJrKr‚#szBCDFloatField.m2iN)rSrTrUrƒr‚rJrJrJrKrƒsrƒc@sFeZdZdZddddgZddd„Zd	d
„Zdd„Zd
d„Zdd„Z	dS)Ú	_BitFieldaÌ
    Field to handle bits.

    :param name: name of the field
    :param default: default value
    :param size: size (in bits). If negative, Low endian
    :param tot_size: size of the total group of bits (in bytes) the bitfield
                     is in. If negative, Low endian.
    :param end_tot_size: same but for the BitField ending a group.

    Example - normal usage::

         0                   1                   2                   3
         0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        |             A             |               B               | C |
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                                 Fig. TestPacket

        class TestPacket(Packet):
            fields_desc = [
                BitField("a", 0, 14),
                BitField("b", 0, 16),
                BitField("c", 0, 2),
            ]

    Example - Low endian stored as 16 bits on the network::

        x x x x x x x x x x x x x x x x
        a [b] [   c   ] [      a      ]

        Will first get reversed during dissecion:

        x x x x x x x x x x x x x x x x
        [      a        ] [b] [   c   ]

        class TestPacket(Packet):
            fields_desc = [
                BitField("a", 0, 9, tot_size=-2),
                BitField("b", 0, 2),
                BitField("c", 0, 5, end_tot_size=-2)
            ]

    ÚrevÚsizeÚtot_sizeÚend_tot_sizercCs‚t |||¡t|ƒr||ƒ}|dkp4|dkp4|dk|_t|ƒ|_|sP|jd}t|ƒ|_|sh|jd}t|ƒ|_|jd|_dS)Nrég @)	rkrLÚcallabler…Úabsr†r‡rˆro)rIrlrnr†r‡rˆrJrJrKrLXs




z_BitField.__init__cCsÞ| ||¡}t|tƒr"|\}}}nd}d}||jK}||d|j>d@O}||j7}x8|dkrŒ|d8}|t d||?¡}|d|>dM}qVW|rœ|||fS|jrÖ|jdkrÖ|d|j…||jd…ddd…}|SdS)Nrr~r‰z!Br–)rƒrtr¼r†rqr†r…rˆ)rIr{rˆÚivalrHZbitsdonerZrJrJrKrŠls"




*z_BitField.addfieldc
Cs0t|tƒr|\}}n:d}|jrN|jdkrN|d|j…ddd…||jd…}|j|ddd}|d|…}t d||¡}d}x0t|ƒD]$}|t||ƒ||dd>O}qŽW|d|d|>dM}||d|j|?}||j7}||dd…}|d}| 	||¡}	|r$||f|	fS||	fSdS)Nrr~r–r‰z!%dB)
rtr¼r…r‡r†rqr‹r5rr‚)
rIr{rˆZbnZnb_bytesrbZ_bytesr˜rWZb2rJrJrKrŒ‡s(

&$
z_BitField.getfieldcCstdd|jdƒS)Nrr!r~)rr†)rIrJrJrKrž®sz_BitField.randvalcCst|jƒdS)Nr‰)Úfloatr†)rIr{r|rJrJrKr}²sz_BitField.i2lenN)rr)
rSrTrUrVrŸrLrŠrŒržr}rJrJrJrKr„(s-
'r„c@seZdZejZdS)ÚBitFieldN)rSrTrUr„rVrJrJrJrKrŽ·srŽcs:eZdZdgZ‡fdd„Z‡fdd„Z‡fdd„Z‡ZS)ÚBitFixedLenFieldrPcs||_tt|ƒ ||d¡dS)Nr)rPrYrrL)rIrlrnrP)r\rJrKrL¾szBitFixedLenField.__init__cs| |¡|_tt|ƒ ||¡S)N)rPr†rYrrŒ)rIr{rˆ)r\rJrKrŒÇszBitFixedLenField.getfieldcs | |¡|_tt|ƒ |||¡S)N)rPr†rYrrŠ)rIr{rˆrH)r\rJrKrŠÏszBitFixedLenField.addfield)rSrTrUrŸrLrŒrŠrhrJrJ)r\rKr»s	rcs:eZdZdddgZdddd„f‡fdd„	Zd	d
„Z‡ZS)ÚBitFieldLenFieldryrzr{NcCs|S)NrJ)r{r|rJrJrKr#ârGzBitFieldLenField.<lambda>cs*tt|ƒ |||¡||_||_||_dS)N)rYrrLryrzr{)rIrlrnr†ryrzr{)r\rJrKrLÜs	zBitFieldLenField.__init__cCs"tjrtjj}ntj}||||ƒS)N)ráÚPY2rxrƒÚ__func__)rIr{r|ÚfuncrJrJrKrƒês
zBitFieldLenField.i2m)rSrTrUrŸrLrƒrhrJrJ)r\rKrÙs

rc@seZdZdd„ZdS)Ú	XBitFieldcCst| ||¡ƒS)N)r&r)rIr{r|rJrJrKr…ôszXBitField.i2reprN)rSrTrUr…rJrJrJrKr”ósr”c@sFeZdZddd„Zdd„Zdd„Zdd	„Zd
d„Zdd
„Zdd„Z	dS)Ú
_EnumFieldrrc
Csút|tƒrtt|ƒ |¡t|tƒrF|d|_|d|_d|_d|_n i}|_i}|_d|_d|_t|t	ƒr‚t	t
t|ƒƒƒ}n8t|tƒr–| 
¡}n$t	|ƒ}tdd„|Dƒƒrº||}}x*|D]"}tt||ƒ}	|	||<|||	<qÀWt ||||¡dS)aˆ Initializes enum fields.

        @param name:    name of this field
        @param default: default value of this field
        @param enum:    either a dict or a tuple of two callables. Dict keys are  # noqa: E501
                        the internal values, while the dict values are the
                        user-friendly representations. If the tuple is provided,  # noqa: E501
                        the first callable receives the internal value as
                        parameter and returns the user-friendly representation
                        and the second callable does the converse. The first
                        callable may return None to default to a literal string
                        (repr()) representation.
        @param fmt:     struct.pack format used to parse and serialize the
                        internal value from and to machine representation.
        rr~Ncss|]}t|tƒVqdS)N)rtrM)r“r|rJrJrKr”#	sz&_EnumField.__init__.<locals>.<genexpr>)rtrWrCr^r¼Úi2s_cbÚs2i_cbÚi2sÚs2irr5rPrÚkeysr¸rMrkrL)
rIrlrnr`rmr˜r™ršrfrbrJrJrKrLús.










z_EnumField.__init__cCsPt|tƒrF|jr6y|j|}WqFtk
r2YqFXn|jrF| |¡}tt|ƒS)N)rtrMr™rÄr—rCri)rIr{r|rJrJrKÚ	any2i_one+	s

z_EnumField.any2i_onecCs`|tjkrXt|tƒsX|jr<y
|j|Stk
r8YqXXn|jrX| |¡}|dk	rX|St|ƒS)N)rÚnoenumrtrr˜rÄr–r„)rIr{r|r÷rJrJrKÚ
i2repr_one7	s

z_EnumField.i2repr_onecs.t|tƒr‡‡fdd„|DƒSˆ ˆ|¡SdS)Ncsg|]}ˆ ˆ|¡‘qSrJ)r›)r“Úz)r{rIrJrKróH	sz$_EnumField.any2i.<locals>.<listcomp>)rtrr›)rIr{r|rJ)r{rIrKrwE	s
z_EnumField.any2ics.t|tƒr‡‡fdd„|DƒSˆ ˆ|¡SdS)Ncsg|]}ˆ ˆ|¡‘qSrJ)r)r“rž)r{rIrJrKróO	sz%_EnumField.i2repr.<locals>.<listcomp>)rtrr)rIr{r|rJ)r{rIrKr…L	s
z_EnumField.i2reprcCsRt|tƒrdnd}t d||||¡|jdk	rN|jdk	rN||j|<||j|<dS)Nz0x%xz%szAt %s: Change to %s at )rtrrÚdebugr˜r™)rIr`rarbÚksrJrJrKr_S	s
z_EnumField.notify_setcCsVt|tƒrdnd}t d|||¡|jdk	rR|jdk	rR|j|}|j|=|j|=dS)Nz0x%xz%szAt %s: Delete value at )rtrrrŸr˜r™)rIr`rar rbrJrJrKrd]	s
z_EnumField.notify_delN)rr)
rSrTrUrLr›rrwr…r_rdrJrJrJrKr•ùs
-
r•c@seZdZddddgZdS)Ú	EnumFieldr˜r™r—r–N)rSrTrUrŸrJrJrJrKr¡g	sr¡c@seZdZddd„Zdd„ZdS)Ú
CharEnumFieldÚ1scCsPt |||||¡|jdk	rLt|jƒ}|rLt|dƒdkrL|j|j|_|_dS)Nrr~)r¡rLr˜rrPr™)rIrlrnr`rmrfrJrJrKrLl	s


zCharEnumField.__init__cCs2t|ƒdkr.|jr|j|}n|jr.| |¡}|S)Nr~)rPr™r—)rIr{r|rJrJrKr›y	s
zCharEnumField.any2i_oneN)r£)rSrTrUrLr›rJrJrJrKr¢k	s
	r¢c@s*eZdZejZdd„Zdd„Zdd„ZdS)ÚBitEnumFieldcCs4t ||||¡|dk|_t|ƒ|_|jd|_dS)Nrg @)r•rLr…r‹r†ro)rIrlrnr†r`rJrJrKrL†	s

zBitEnumField.__init__cCst |||¡S)N)r•rw)rIr{r|rJrJrKrw	szBitEnumField.any2icCst |||¡S)N)r•r…)rIr{r|rJrJrKr…‘	szBitEnumField.i2reprN)rSrTrUr¡rŸrLrwr…rJrJrJrKr¤ƒ	sr¤c@seZdZejZdd„ZdS)ÚShortEnumFieldcCst ||||d¡dS)Nrr)r¡rL)rIrlrnr`rJrJrKrLœ	szShortEnumField.__init__N)rSrTrUr¡rŸrLrJrJrJrKr¥™	sr¥c@seZdZdd„ZdS)ÚLEShortEnumFieldcCst ||||d¡dS)Nz<H)r¡rL)rIrlrnr`rJrJrKrL¦	szLEShortEnumField.__init__N)rSrTrUrLrJrJrJrKr¦¥	sr¦c@seZdZdd„ZdS)Ú
ByteEnumFieldcCst ||||d¡dS)Nr—)r¡rL)rIrlrnr`rJrJrKrL¬	szByteEnumField.__init__N)rSrTrUrLrJrJrJrKr§«	sr§c@seZdZdd„ZdS)ÚXByteEnumFieldcCs`|tjkrXt|tƒsX|jr<y
|j|Stk
r8YqXXn|jrX| |¡}|dk	rX|St|ƒS)N)rrœrtrr˜rÄr–r&)rIr{r|r÷rJrJrKr²	s

zXByteEnumField.i2repr_oneN)rSrTrUrrJrJrJrKr¨±	sr¨c@seZdZdd„ZdS)ÚIntEnumFieldcCst ||||d¡dS)Nri)r¡rL)rIrlrnr`rJrJrKrLÂ	szIntEnumField.__init__N)rSrTrUrLrJrJrJrKr©Á	sr©c@seZdZdd„ZdS)ÚSignedIntEnumFieldcCst ||||d¡dS)Nr)r¡rL)rIrlrnr`rJrJrKrLÈ	szSignedIntEnumField.__init__N)rSrTrUrLrJrJrJrKrªÇ	srªc@seZdZdd„ZdS)ÚLEIntEnumFieldcCst ||||d¡dS)Nz<I)r¡rL)rIrlrnr`rJrJrKrLÎ	szLEIntEnumField.__init__N)rSrTrUrLrJrJrJrKr«Í	sr«c@seZdZdd„ZdS)ÚXShortEnumFieldcCsd|tjkr\t|tƒs\|jdk	r@y
|j|Stk
r<Yq\Xn|jr\| |¡}|dk	r\|St|ƒS)N)rrœrtrr˜rÄr–r&)rIr{r|r÷rJrJrKrÔ	s


zXShortEnumField.i2repr_oneN)rSrTrUrrJrJrJrKr¬Ó	sr¬c@s&eZdZd	dd„Zdd„Zdd„ZdS)
Ú_MultiEnumFieldrrc
Csv||_||_i|_i|_xH|D]@}i}||j|<x,t ||¡D]\}}	|||	<||j|	<q@WqWt ||||¡dS)N)Ú
depends_onÚ	i2s_multiÚ	s2i_multiÚs2i_allrárârkrL)
rIrlrnr`r®rmrHr™rfrZrJrJrKrLä	s	

z_MultiEnumField.__init__cCsLt|tƒrB| |¡}||jkr8|j|}||kr8||S|j|Stt|ƒS)N)rtrMr®r°r±rCri)rIr{r|rZr™rJrJrKr›ù	s




z_MultiEnumField.any2i_onecCsD| |¡}t|tƒrt|ƒS||jkr<t|j| ||¡ƒSt|ƒS)N)r®rtrr„r¯rMrß)rIr{r|rZrJrJrKr
s


z_MultiEnumField.i2repr_oneN)rr)rSrTrUrLr›rrJrJrJrKr­ã	s
r­c@seZdZddddgZdS)ÚMultiEnumFieldr®r¯r°r±N)rSrTrUrŸrJrJrJrKr²
sr²c@s0eZdZejejZdd„Zdd„Zdd„ZdS)ÚBitMultiEnumFieldcCs6t |||||¡|dk|_t|ƒ|_|jd|_dS)Nrg @)r­rLr…r‹r†ro)rIrlrnr†r`r®rJrJrKrL
s	

zBitMultiEnumField.__init__cCst |||¡S)N)r­rw)rIr{r|rJrJrKrw$
szBitMultiEnumField.any2icCst |||¡S)N)r­r…)rIr{r|rJrJrKr…(
szBitMultiEnumField.i2reprN)	rSrTrUr¡rŸr²rLrwr…rJrJrJrKr³
sr³c@seZdZdZdd„ZdS)ÚByteEnumKeysFieldz3ByteEnumField that picks valid values when fuzzed. cCs
t|jƒS)N)r	r˜)rIrJrJrKrž4
szByteEnumKeysField.randvalN)rSrTrUrVržrJrJrJrKr´1
sr´c@seZdZdZdd„ZdS)ÚShortEnumKeysFieldz4ShortEnumField that picks valid values when fuzzed. cCs
t|jƒS)N)r	r˜)rIrJrJrKrž<
szShortEnumKeysField.randvalN)rSrTrUrVržrJrJrJrKrµ9
srµc@seZdZdZdd„ZdS)ÚIntEnumKeysFieldz2IntEnumField that picks valid values when fuzzed. cCs
t|jƒS)N)r	r˜)rIrJrJrKržD
szIntEnumKeysField.randvalN)rSrTrUrVržrJrJrJrKr¶A
sr¶c@s"eZdZddddd„fdd„ZdS)ÚLEFieldLenFieldNz<HcCs|S)NrJ)r{r|rJrJrKr#T
rGzLEFieldLenField.<lambda>c	Cstj|||||||ddS)N)ryrmrzr{)rxrL)rIrlrnryrmrzr{rJrJrKrLM
s
zLEFieldLenField.__init__)rSrTrUrLrJrJrJrKr·L
sr·c@s0eZdZddgZdd„Zdd„Zdd„ZeZd	S)
Ú
FlagValueIterÚ	flagvalueÚcursorcCs||_d|_dS)Nr)r¹rº)rIr¹rJrJrKrLd
szFlagValueIter.__init__cCs|S)NrJ)rIrJrJrKÚ__iter__i
szFlagValueIter.__iter__cCsVt|jƒ}||jL}x8|rL|jd7_|d@rB|jj|jdS|dL}qWt‚dS)Nr~)rr¹rºÚnamesÚ
StopIteration)rIr|rJrJrKÚ__next__m
s

zFlagValueIter.__next__N)rSrTrUrŸrLr»r¾ÚnextrJrJrJrKr¸`
s
r¸csæeZdZdddgZdd„Zdd„Zdd	„Zd
d„Zdd
„Zdd„Z	dd„Z
dd„Zdd„Zdd„Z
dd„ZeZdd„ZeZdd„Zdd„Zd d!„ZeZd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Z‡fd,d-„Z‡fd.d/„Zd0d1„Z‡ZS)2Ú	FlagValuerbr¼ÚmulticCsh|sdSt|tjƒr,|jr$| d¡nt|ƒ}t|tƒr`d}x |D]}|d|j |¡>O}q@W|}t|ƒS)Nrú+r~)	rtráÚstring_typesrÁÚsplitrr¼Úindexr)rIrbrìrrJrJrKÚ	_fixvalue~
s

zFlagValue._fixvaluecCs"t|tƒ|_||_| |¡|_dS)N)rtrrÁr¼rÆrb)rIrbr¼rJrJrKrL‹
szFlagValue.__init__cCs
t|jƒS)N)Úhashrb)rIrJrJrKr­‘
szFlagValue.__hash__cCs|jS)N)rb)rIrJrJrKÚ__int__•
szFlagValue.__int__cCs|j| |¡kS)N)rbrÆ)rIrªrJrJrKr«™
szFlagValue.__eq__cCs|j| |¡kS)N)rbrÆ)rIrªrJrJrKÚ__lt__
szFlagValue.__lt__cCs|j| |¡kS)N)rbrÆ)rIrªrJrJrKÚ__le__¡
szFlagValue.__le__cCs|j| |¡kS)N)rbrÆ)rIrªrJrJrKÚ__gt__¥
szFlagValue.__gt__cCs|j| |¡kS)N)rbrÆ)rIrªrJrJrKÚ__ge__©
szFlagValue.__ge__cCs|j| |¡kS)N)rbrÆ)rIrªrJrJrKr¬­
szFlagValue.__ne__cCs| |j| |¡@|j¡S)N)r\rbrÆr¼)rIrªrJrJrKÚ__and__±
szFlagValue.__and__cCs| |j| |¡B|j¡S)N)r\rbrÆr¼)rIrªrJrJrKÚ__or__¶
szFlagValue.__or__cCs|j| |¡>S)N)rbrÆ)rIrªrJrJrKÚ
__lshift__»
szFlagValue.__lshift__cCs|j| |¡?S)N)rbrÆ)rIrªrJrJrKÚ
__rshift__¿
szFlagValue.__rshift__cCs
t|jƒS)N)r©rb)rIrJrJrKÚ__nonzero__Ã
szFlagValue.__nonzero__cCst dt¡t|ƒS)Nz1obj.flagrepr() is obsolete. Use str(obj) instead.)r¹rºÚDeprecationWarningrM)rIrJrJrKÚflagreprÈ
szFlagValue.flagreprcCsxd}g}t|ƒ}xR|rb|d@rPy|j|}Wntk
rDd}YnX| |¡|d7}|dL}qW|jrndnd |¡S)Nrr~ú?rÂr)rr¼Ú
IndexErrorr]rÁr•)rIrrør|rlrJrJrKrNÐ
s

zFlagValue.__str__cCst|ƒS)N)r¸)rIrJrJrKr»à
szFlagValue.__iter__cCsd||fS)Nz<Flag %d (%s)>rJ)rIrJrJrKrRä
szFlagValue.__repr__cCs| t|ƒ|j¡S)N)r\rr¼)rIÚmemorJrJrKÚ__deepcopy__è
szFlagValue.__deepcopy__cs¨|ˆjkrttˆƒ |¡Sy8ˆjr>tdˆj |¡tˆƒ@ƒSt	‡fdd„|DƒƒSt
k
r¢d|kr’yˆ | dd¡¡St
k
rYnXttˆƒ |¡SXdS)Nr!c3s*|]"}tdˆj |¡tˆƒ@ƒVqdS)r!N)r©r¼rÅr)r“Úflag)rIrJrKr”ó
sz(FlagValue.__getattr__.<locals>.<genexpr>rÇú-)rŸrYrÀÚ__getattribute__rÁr©r¼rÅrràrur§Úreplacerã)rIr¦)r\)rIrKr§ì
s

zFlagValue.__getattr__cs–|dkrt|tjƒst|ƒ‚||jkr8tt|ƒ ||¡S||jkr€|rb|j	d|j 
|¡O_	q’|j	d|j 
|¡M_	ntt|ƒ ||¡SdS)Nrbr!)rtrár6rurŸrYrÀÚ__setattr__r¼rbrÅ)rIr¦rb)r\rJrKrÜý
s

zFlagValue.__setattr__cCs| |j|j¡S)N)r\rbr¼)rIrJrJrKrszFlagValue.copy)rSrTrUrŸrÆrLr­rÈr«rÉrÊrËrÌr¬rÍÚ__rand__rÎÚ__ror__rÏrÐrÑÚ__bool__rÓrNr»rRr×r§rÜrrhrJrJ)r\rKrÀ{
s6

rÀcs^eZdZdZdZdgZ‡fdd„Zdd„Z‡fdd	„Z‡fd
d„Z	‡fdd
„Z
dd„Z‡ZS)Ú
FlagsFielda4 Handle Flag type field

   Make sure all your flags have a label

   Example (list):
       >>> from scapy.packet import Packet
       >>> class FlagsTest(Packet):
               fields_desc = [FlagsField("flags", 0, 8, ["f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7"])]  # noqa: E501
       >>> FlagsTest(flags=9).show2()
       ###[ FlagsTest ]###
         flags     = f0+f3

    Example (str):
       >>> from scapy.packet import Packet
       >>> class TCPTest(Packet):
               fields_desc = [
                   BitField("reserved", 0, 7),
                   FlagsField("flags", 0x2, 9, "FSRPAUECN")
               ]
       >>> TCPTest(flags=3).show2()
       ###[ FlagsTest ]###
         reserved  = 0
         flags     = FS

    Example (dict):
       >>> from scapy.packet import Packet
       >>> class FlagsTest2(Packet):
               fields_desc = [
                   FlagsField("flags", 0x2, 16, {
                       1: "1",  # 1st bit
                       8: "2"   # 8th bit
                   })
               ]

   :param name: field's name
   :param default: default value for the field
   :param size: number of bits in the field (in bits)
   :param names: (list or str or dict) label for each flag
       If it's a str or a list, the least Significant Bit tag's name
       is written first.
   Tr¼cs^t|tƒr@dd„t|ƒDƒ}xt |¡D]\}}|||<q(W|}||_tt|ƒ |||¡dS)NcSsg|]}d|‘qS)zbit_%drJ)r“rrJrJrKróFsz'FlagsField.__init__.<locals>.<listcomp>)	rtr$r5ráÚ	viewitemsr¼rYràrL)rIrlrnr†r¼ÚtmprrZ)r\rJrKrL=s
zFlagsField.__init__cCs*t|ttfƒr|S|dkrdSt||jƒS)zkReturns a FlagValue instance when needed. Internal method, to be
used in *2i() and i2*() methods.

        N)rtrÀrr¼)rIr|rJrJrKÚ
_fixup_valNs
zFlagsField._fixup_valcs| tt|ƒ ||¡¡S)N)rãrYràrw)rIr{r|)r\rJrKrwZszFlagsField.any2ics| tt|ƒ ||¡¡S)N)rãrYràr‚)rIr{r|)r\rJrKr‚^szFlagsField.m2ics| tt|ƒ ||¡¡S)N)rãrYràr)rIr{r|)r\rJrKrbszFlagsField.i2hcsFt|ttfƒr,tt|ƒ‡fdd„|DƒƒƒS|dkr8dStˆ |¡ƒS)Nc3s(|] }|dkrdntˆ |¡ƒVqdS)NÚNone)rMrã)r“rZ)rIrJrKr”msz$FlagsField.i2repr.<locals>.<genexpr>rä)rtrr¼r„r´rMrã)rIr{r|rJ)rIrKr…fszFlagsField.i2repr)
rSrTrUrVr¡rŸrLrãrwr‚rr…rhrJrJ)r\rKràs)ràZMultiFlagEntryÚshortÚlongcsHeZdZejdgZ‡fdd„Zdd„Zdd„Zdd	„Zd
d„Z	‡Z
S)ÚMultiFlagsFieldr®cs$||_||_tt|ƒ |||¡dS)N)r¼r®rYrçrL)rIrlrnr†r¼r®)r\rJrKrLxszMultiFlagsField.__init__cCsÌt|ttfƒstdƒ‚|dk	r¸t|tƒr4| ||¡S| |¡}|dk	r¸||jksXtdƒ‚|j|}tƒ}xJ|D]B}x<t 	|¡D]}|j
|kr~| |¡Pq~Wdsntd |¡ƒ‚qnqnW|St|tƒrÈtƒS|S)Nzset expectedzinvalid dependencyFz&Unknown flag "{}" with this dependency)
rtÚsetrrur‚r®r¼ÚAssertionErrorráÚ
itervaluesråÚaddr%)rIr{r|rZÚthese_namesrˆrrHrJrJrKrw„s*






zMultiFlagsField.any2ic	Cs†| |¡}|j |i¡}d}|dkr(|SxX|D]P}xJt |¡D] \}}|j|kr>|d|>O}Pq>W|dt|tdƒd…ƒ>O}q.W|S)Nrr~zbit )r®r¼rßrárârårrP)	rIr{r|rZrìrøÚflag_setrrHrJrJrKrƒŸs


 zMultiFlagsField.i2mcCsr| |¡}|j |i¡}tƒ}d}xJ|rl|d@rZ||krJ| ||j¡n| d |¡¡|dL}|d7}q$W|S)Nrr~zbit {})r®r¼rßrèrërår%)rIr{r|rZrìrørrJrJrKr‚°s
zMultiFlagsField.m2icCst| |¡}|j |i¡}tƒ}xL|D]D}x>t |¡D]&}|j|kr4| d |j	|j¡¡Pq4W| |¡q$Wt
|ƒS)Nz{} ({}))r®r¼rßrèrárêrårër%rær„)rIr{r|rZrìrørírrJrJrKr…Ás


zMultiFlagsField.i2repr)rSrTrUràrŸrLrwrƒr‚r…rhrJrJ)r\rKrçusrçcs<eZdZdgZd‡fdd„	Zdd„Zdd„Zd	d
„Z‡ZS)ÚFixedPointFieldÚ	frac_bitsécs||_tt|ƒ |||¡dS)N)rïrYrîrL)rIrlrnr†rï)r\rJrKrLÔszFixedPointField.__init__cCs8|dkr|St|ƒ}t||d|jƒ}||j>|BS)Nr!)rrï)rIr{rHrŒZfractrJrJrKrwÙs
zFixedPointField.any2icCsJ||j?}d|j}t|d|j>d@ƒ}||}|| tt |¡ƒ¡S)Ng@r~)rïr)Ú	normalizerÚmathÚlog10)rIr{rHZint_partÚpwZ	frac_partrJrJrKrás


zFixedPointField.i2hcCst| ||¡ƒS)N)rMr)rIr{rHrJrJrKr…êszFixedPointField.i2repr)rð)	rSrTrUrŸrLrwrr…rhrJrJ)r\rKrîÑs
	rîc@sleZdZdddddgZddd„Zd	d
„Zdd„Zd
d„Zdd„Zdd„Z	dd„Z
dd„Zdd„Zdd„Z
dS)Ú_IPPrefixFieldBaseÚ	wordbytesÚmaxbytesÚatonÚntoarPNcCsH||_||_||_||_t |||d|j¡|dkr>dd„}||_dS)Nz%iscSsdS)NrrJ)r|rJrJrKr#rGz-_IPPrefixFieldBase.__init__.<locals>.<lambda>)rör÷rørùrkrLrP)rIrlrnrör÷rørùrPrJrJrKrLôsz_IPPrefixFieldBase.__init__cCs |jd}||d||jS)Nr‰r~)rö)rIÚpfxlenÚwbitsrJrJrKÚ	_numbytess
z_IPPrefixFieldBase._numbytescCs$| d¡\}}| |¡|t|ƒfS)Nú/)rÄrør)rIr{r|ÚpfxrúrJrJrKr€
s
z_IPPrefixFieldBase.h2icCs|\}}d||fS)Nz%s/%irJ)rIr{r|rþrúrJrJrKrsz_IPPrefixFieldBase.i2hcCs:|dkrd\}}n|\}}| |¡}|d| |¡…|fS)N)rr)rørü)rIr{r|rþrúrˆrJrJrKrƒs


z_IPPrefixFieldBase.i2mcCs:|\}}t|ƒ|jkr,|d|jt|ƒ}| |¡|fS)NrÌ)rPr÷rù)rIr{r|rˆrúrJrJrKr‚'sz_IPPrefixFieldBase.m2icCs(|dkr| d|j¡dfS| ||¡S)NrÌr~)rùr÷r€)rIr{r|rJrJrKrw0sz_IPPrefixFieldBase.any2icCs|\}}|S)NrJ)rIr{r|rÇrúrJrJrKr}7sz_IPPrefixFieldBase.i2lencCs.| ||¡\}}d| |¡}|t ||¡S)Nz!%is)rƒrürqr†)rIr{rˆrHZrawpfxrúrmrJrJrKrŠ<sz_IPPrefixFieldBase.addfieldc
CsL| |¡}| |¡}d|}||d…| |t ||d|…¡d|f¡fS)Nz!%isr)rPrür‚rqr‹)rIr{rˆrúÚnumbytesrmrJrJrKrŒBs

z_IPPrefixFieldBase.getfield)N)rSrTrUrŸrLrür€rrƒr‚rwr}rŠrŒrJrJrJrKrõñs


	rõc@seZdZddd„ZdS)Ú
IPPrefixFieldr~Nc
Cst ||||dtt|¡dS)Nr
)rõrLr$r%)rIrlrnrörPrJrJrKrLKszIPPrefixField.__init__)r~N)rSrTrUrLrJrJrJrKrJsrc@seZdZddd„ZdS)ÚIP6PrefixFieldr~Nc
Cs$t ||||ddd„dd„|¡dS)NrðcSsttj|ƒS)N)r#rôr)ÚarJrJrKr#mrGz)IP6PrefixField.__init__.<locals>.<lambda>cSsttj|ƒS)N)r"rôr)ròrJrJrKr#nrG)rõrL)rIrlrnrörPrJrJrKrL_szIP6PrefixField.__init__)r~N)rSrTrUrLrJrJrJrKr^src@s6eZdZddddddgZdd
d„Zdd
„Zdd„ZdS)ÚUTCTimeFieldÚepochÚdeltaÚstrfÚuse_msecÚ	use_microÚuse_nanoFNú%a, %d %b %Y %H:%M:%S %zc	CsRt |||d¡|dkrtnt |¡}||_|t|_||_||_||_	||_
dS)Nri)rkrLrÚcalendarÚtimegmrrrrrr	)	rIrlrnrrr	rrZmk_epochrJrJrKrLys

zUTCTimeField.__init__cCsj|dkrd}n.|jr|d}n|jr.|d}n|jr<|d}t|ƒ|j}t |jt |¡¡}d||fS)Nrg@@g€„.AgeÍÍAz%s (%d))	rrr	rrÚtimeÚstrftimerÚgmtime)rIr{r|ÚtrJrJrKr…Œs

zUTCTimeField.i2reprcCs|dk	rt|ƒSdS)Nr)r)rIr{r|rJrJrKrƒšszUTCTimeField.i2m)FFFNr
)rSrTrUrŸrLr…rƒrJrJrJrKrss

rc@s(eZdZdddgZd
dd„Zdd„Zd	S)ÚSecondsIntFieldrrr	FcCs&t |||d¡||_||_||_dS)Nri)rkrLrrr	)rIrlrnrrr	rJrJrKrL¤szSecondsIntField.__init__cCsJ|dkrd}n4|jr|d}n$|jr.|d}n|jr>|d}n|}d|S)Nrg@@g€„.AgeÍÍAz%s sec)rrr	)rIr{r|rìrJrJrKr…®s


zSecondsIntField.i2reprN)FFF)rSrTrUrŸrLr…rJrJrJrKrŸs


rc@s>eZdZddd„Zdd	„Zd
d„Zdd
„Zdd„Zdd„ZdS)Ú
_ScalingFieldr~rrrr—cCs,||_||_||_||_t ||||¡dS)N)ÚscalingÚunitÚoffsetÚndigitsrkrL)rIrlrnrrrrrmrJrJrKrL¾s

z_ScalingField.__init__cCsD|dkrd}||j|j}t|tƒr@|jddkr@tt|ƒƒ}|S)Nrr–r=)rrrtrrmrÚround)rIr{r|rJrJrKrƒÎsz_ScalingField.i2mcCs8||j|j}t|tƒr4|jddkr4t||jƒ}|S)Nr–r=)rrrtrrmrr)rIr{r|rJrJrKr‚Úsz_ScalingField.m2icCsJt|ttfƒr0t |jt|ƒ¡d}| ||¡}t|tt	fƒsFt
dƒ‚|S)NrzUnknown type)rtrMrîrqr‹rmr!r‚rrru)rIr{r|rJrJrKrwász_ScalingField.any2icCsd| ||¡|jfS)Nz%s %s)rr)rIr{r|rJrJrKr…ês
z_ScalingField.i2reprcCs`t |¡}|dk	r\t|j|j|j|jƒ}t|j|j|j|jƒ}tt||ƒt||ƒƒSdS)N)	rkržrrþrrrÚmaxr)rIrbZmin_valZmax_valrJrJrKržñs
z_ScalingField.randvalN)r~rrrr—)	rSrTrUrLrƒr‚rwr…ržrJrJrJrKr½s
		rc@seZdZdZdS)ÚScalingFielda Handle physical values which are scaled and/or offset for communication

       Example:
           >>> from scapy.packet import Packet
           >>> class ScalingFieldTest(Packet):
                   fields_desc = [ScalingField('data', 0, scaling=0.1, offset=-1, unit='mV')]  # noqa: E501
           >>> ScalingFieldTest(data=10).show2()
           ###[ ScalingFieldTest ]###
             data= 10.0 mV
           >>> hexdump(ScalingFieldTest(data=10))
           0000  6E                                               n
           >>> hexdump(ScalingFieldTest(data=b"m"))
           0000  6D                                               m
           >>> ScalingFieldTest(data=b"m").show2()
           ###[ ScalingFieldTest ]###
             data= 9.9 mV

        bytes(ScalingFieldTest(...)) will produce 0x6E in this example.
        0x6E is 110 (decimal). This is calculated through the scaling factor
        and the offset. "data" was set to 10, which means, we want to transfer
        the physical value 10 mV. To calculate the value, which has to be
        sent on the bus, the offset has to subtracted and the scaling has to be
        applied by division through the scaling factor.
        bytes = (data - offset) / scaling
        bytes = ( 10  -  (-1) ) /    0.1
        bytes =  110 = 0x6E

        If you want to force a certain internal value, you can assign a byte-
        string to the field (data=b"m"). If a string of a bytes object is
        given to the field, no internal value conversion will be applied

       :param name: field's name
       :param default: default value for the field
       :param scaling: scaling factor for the internal value conversion
       :param unit: string for the unit representation of the internal value
       :param offset: value to offset the internal value during conversion
       :param ndigits: number of fractional digits for the internal conversion
       :param fmt: struct.pack format used to parse and serialize the internal value from and to machine representation # noqa: E501
       N)rSrTrUrVrJrJrJrKrýs(rc@seZdZdZdd„ZdS)ÚBitScalingFieldz+
    A ScalingField that is a BitField
    cOs*tj|||f|ž|Žt ||||¡dS)N)rrLrŽ)rIrlrnr†rZÚkwargsrJrJrKrL,
szBitScalingField.__init__N)rSrTrUrVrLrJrJrJrKr(
src@seZdZdZdd„ZdS)ÚOUIFieldz3
    A field designed to carry a OUI (3 bytes)
    cCsVt d|pd¡dd…}t|dƒdd…}tjrRtj |¡}||krRd||fS|S)Nz!Irr~sr‰z%s (%s))rqr†r(rrðZ
_get_manuf)rIr{rHZby_valZouiZfancyrJrJrKr…6
szOUIField.i2reprN)rSrTrUrVr…rJrJrJrKr2
src@sdeZdZdZdgZdZdZdZeeefZefdd„Z	dd	„Z
d
d„Zdd
„Zdd„Z
edd„ƒZdS)Ú	UUIDFielda±Field for UUID storage, wrapping Python's uuid.UUID type.

    The internal storage format of this field is ``uuid.UUID`` from the Python
    standard library.

    There are three formats (``uuid_fmt``) for this field type:

    * ``FORMAT_BE`` (default): the UUID is six fields in big-endian byte order,
      per RFC 4122.

      This format is used by DHCPv6 (RFC 6355) and most network protocols.

    * ``FORMAT_LE``: the UUID is six fields, with ``time_low``, ``time_mid``
      and ``time_high_version`` in little-endian byte order. This *doesn't*
      change the arrangement of the fields from RFC 4122.

      This format is used by Microsoft's COM/OLE libraries.

    * ``FORMAT_REV``: the UUID is a single 128-bit integer in little-endian
      byte order. This *changes the arrangement* of the fields.

      This format is used by Bluetooth Low Energy.

    Note: You should use the constants here.

    The "human encoding" of this field supports a number of different input
    formats, and wraps Python's ``uuid.UUID`` library appropriately:

    * Given a bytearray, bytes or str of 16 bytes, this class decodes UUIDs in
      wire format.

    * Given a bytearray, bytes or str of other lengths, this delegates to
      ``uuid.UUID`` the Python standard library. This supports a number of
      different encoding options -- see the Python standard library
      documentation for more details.

    * Given an int or long, presumed to be a 128-bit integer to pass to
      ``uuid.UUID``.

    * Given a tuple:

      * Tuples of 11 integers are treated as having the last 6 integers forming
        the ``node`` field, and are merged before being passed as a tuple of 6
        integers to ``uuid.UUID``.

      * Otherwise, the tuple is passed as the ``fields`` parameter to
        ``uuid.UUID`` directly without modification.

        ``uuid.UUID`` expects a tuple of 6 integers.

    Other types (such as ``uuid.UUID``) are passed through.
    Úuuid_fmtrr~r!cCs"||_| ¡t |||d¡dS)Nr)rÚ_check_uuid_fmtrkrL)rIrlrnrrJrJrKrL€
szUUIDField.__init__cCs |jtjkrtd |j¡ƒ‚dS)z=Checks .uuid_fmt, and raises an exception if it is not valid.zUnsupported uuid_fmt ({})N)rrÚFORMATSrr%)rIrJrJrKr†
szUUIDField._check_uuid_fmtcCs`| ¡|dkrdS|jtjkr&|jS|jtjkr8|jS|jtjkrT|jddd…Stdƒ‚dS)Nsr–zUnknown fmt)	rrrÚ	FORMAT_BErîÚ	FORMAT_LEÚbytes_leÚ
FORMAT_REVr)rIr{r|rJrJrKrƒ
sz
UUIDField.i2mcCs`| ¡|jtjkrt|dS|jtjkr4t|dS|jtjkrTt|ddd…dStdƒ‚dS)N)rî)r#r–zUnknown fmt)rrrr!rr"r$r)rIr{r|rJrJrKr‚›
s

z
UUIDField.m2icCsæt|tƒrt|ƒ}t|tƒr(t|d}nºt|tƒr”t|ƒdkrˆd}x |dd…D]}|d>|B}qPW|d|d|d|d|d	|f}t|d
}nNt|ttfƒrÎt|ƒdkrÀ| 	|t|ƒ¡}qâtt
|ƒƒ}nt|tƒrÞ|}ndS|S)N)rérér‰r~r!rr
)Úfieldsrð)rtÚ	bytearrayr!rrr¼rPrMrîr‚r)rIr{r|ÚuÚnoderrJrJrKrwª
s&


$
zUUIDField.any2icCstƒS)N)rrJrJrJrKržÍ
szUUIDField.randvalN)rSrTrUrVrŸr!r"r$r rLrrƒr‚rwÚstaticmethodržrJrJrJrKrA
s4
#rc@sXeZdZdZdgZdd„Zddd„Zdd	„Zd
d„Zdd
„Z	dd„Z
dd„Zdd„ZdS)ÚBitExtendedFielda³
    Bit Extended Field

    This type of field has a variable number of bytes. Each byte is defined
    as follows:
    - 7 bits of data
    - 1 bit an an extension bit:

      + 0 means it is last byte of the field ("stopping bit")
      + 1 means there is another byte after this one ("forwarding bit")

    To get the actual data, it is necessary to hop the binary data byte per
    byte and to check the extension bit until 0
    Ú
extension_bitcCsZt|ƒ}|d|j@|j?}|d|jd@}||jd?}||jd>|d>|}|S)Nr!r~)rr-)rIr|Zfx_bitZlsb_bitsZmsb_bitsrJrJrKÚprepare_byteå
szBitExtendedField.prepare_byterGcCszd}d}d}xTt|ƒD]H}| |¡}|d>t|ƒd?B}t|ƒd@sV||dd…}P|d}qW|dkrndS||fSdS)Nrér~)rGN)r(r.r)rIr|ÚbitsÚendrrWrJrJrKÚstr2extendedï
s
zBitExtendedField.str2extendedcCsî|dkrdSt|ƒ}g}d}d}d}d}x†|dks6|r®|dkrVd}| |¡d}d}q*|d|jkrŒ|rz|d|>B}d}n|d|>B}d}n||d@|>B}|d?}|d}q*W| |¡d ¡}x&|ddd…D]}|t d	|¡}qÒW|S)
NrGTrr‰Fr~rr–z>B)rr]r-rCrqr†)rIr|rˆZLSByteZ
FX_Missingr0rÚresultrJrJrKÚextended2str
s8

zBitExtendedField.extended2strcCst |||d¡||_dS)Nr—)rkrLr-)rIrlrnr-rJrJrKrL0szBitExtendedField.__init__cCs
| |¡S)N)r4)rIr{r|rJrJrKrƒ5szBitExtendedField.i2mcCs| |¡dS)Nr~)r2)rIr{r|rJrJrKr‚9szBitExtendedField.m2icCs|| ||¡S)N)rƒ)rIr{rˆrHrJrJrKrŠ=szBitExtendedField.addfieldcCs
| |¡S)N)r2)rIr{rˆrJrJrKrŒAszBitExtendedField.getfieldN)rG)
rSrTrUrVrŸr.r2r4rLrƒr‚rŠrŒrJrJrJrKr,Ó
s

&r,c@seZdZdd„ZdS)ÚLSBExtendedFieldcCstj|||dddS)Nr)r-)r,rL)rIrlrnrJrJrKrLHszLSBExtendedField.__init__N)rSrTrUrLrJrJrJrKr5Fsr5c@seZdZdd„ZdS)ÚMSBExtendedFieldcCstj|||dddS)Nr/)r-)r,rL)rIrlrnrJrJrKrLOszMSBExtendedField.__init__N)rSrTrUrLrJrJrJrKr6Msr6)árVÚ
__future__rrÚcollectionsrrÀròrôrqr
r¹ÚtypesrÚuuidrZscapy.configrZscapy.dadictrZscapy.volatilerrr	r
rrr
rrrrrrrrrrrZ
scapy.datarZscapy.errorrrZscapy.compatrrrrr r!Zscapy.pton_ntopr"r#Zscapy.utilsr$r%r&r'r(r)Zscapy.utils6r*r+r,r-r.r/Zscapy.base_classesr0r1r2r3r4Zscapy.modules.sixÚmodulesráZscapy.modules.six.movesr5r6r7r8r9r:r;r<r=r>r?r@rArBrCrDrMrErFrrMrWrirjÚ
add_metaclassrkÚobjectr£ZAnyFieldr¨r®r±rµrÉrÐrÒrîrÚrêrñrùrrrr	r
rrrrrrrrrrrr*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r:r;r<r>r?rArBrErFrNrOrTr[r_rdrkrmrnrorprqrrrsrvrxr|rr‚rrƒr„rŽrrr”r•r¡r¢r¤r¥r¦r§r¨r©rªr«r¬r­r²r³r´rµr¶r·r¸rÀràÚ
namedtupleZMultiFlagsEntryrçrîrõrrrrrrrrrr,r5r6rJrJrJrKÚ<module>
s@P   @!" 	7.''' :&$7"(r2-N. 
 Q%$n&+
 b\ (Y,@*
 s