
    h~t                        d Z ddlZddlmZ ddlmZmZ ddlmZ ddl	m
Z
mZmZmZmZ ddlmZmZmZmZmZmZ ddlmZ dd	lmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ dd
l%m&Z& 	 ddl'Z'n# e($ r Y nw xY we$rddl)m*Z*  edde&fde&fg          Z+ e"de&e+          Z, G d dee,         e          Z- G d de-e&         ee&         e          Z.e#ee&         e&ee&         e-e&         f         Z/ G d de-e+         ee+         e          Z0dS )zH
PacketList: holds several packets and allows to do operations on them.
    N)defaultdict)Sequence
NamedTuple)conf)
BasePacketBasePacketListPacketList_metaclassSetGen_CanvasDumpExtended)do_graphhexdump
make_tablemake_lined_tablemake_tex_table	issubtypereduce)AnyCallableDefaultDictDictGenericIteratorListOptionalTupleTypeTypeVarUnionTYPE_CHECKING)Packet)Line2DQueryAnswerqueryanswer_Innerc                   @   e Zd Zg dZ	 	 	 d*dZd Zd Zd Zd Zd	 Z	d
 Z
d Zd Zd Zd Z eddd          Zd Z	 	 d+dZ	 	 d+dZd Zd Zd Zd Zd Z	 	 d,dZ	 	 d-dZ	 	 d,dZd Zd.dZd.d Zd.d!Zd.d"Z 	 d.d#Z!	 	 	 d/d$Z"d0d&Z#	 d.d'Z$d( Z%	 	 	 	 d1d)Z&dS )2_PacketList)statsreslistnameN
PacketListc                     |t           j        }|| _        |g | _        n)t	          |t
                    r|j        | _        n|| _        || _        dS )zcreate a packet list from a list of packets
           res: the list of packets
           stats: a list of classes that will appear in the stats (defaults to [TCP,UDP,ICMP])N)r   stats_classic_protocolsr)   r*   
isinstancer(   r+   )selfr*   namer)   s       O/mounts/lovelace/software/anaconda3/lib/python3.11/site-packages/scapy/plist.py__init__z_PacketList.__init__E   sU     =0E
;DHH[)) 	wDHHDH    c                 *    t          | j                  S N)lenr*   r0   s    r2   __len__z_PacketList.__len__Y   s    48}}r4   c                     |S r6    r0   elts     r2   _elt2pktz_PacketList._elt2pkt]   s    
r4   c                 *    |                                 S r6   summaryr<   s     r2   _elt2sumz_PacketList._elt2suma   s    {{}}r4   c                 ,    |                      |          S r6   )rB   r<   s     r2   	_elt2showz_PacketList._elt2showe   s    }}S!!!r4   c           	         d | j         D             }d}| j        D ]L}d}|D ]>}|                     |                              |          r||xx         dz  cc<   d} n?|s|dz  }Md}t          j        }| j         D ]R}|d|                    |j                  |                    d          |	                    ||                   z  }S|d|                    d          |                    d          |	                    |          z  }|                    d          |
                    | j                  |                    d          ||                    d	          S )
Nc                     i | ]}|d S )r   r;   .0xs     r2   
<dictcomp>z(_PacketList.__repr__.<locals>.<dictcomp>k   s    ***!A***r4   r        :Other<>)r)   r*   r>   haslayerr   color_themepacketlist_proto_namepunctpacketlist_valuepacketlist_namer+   )r0   r)   otherrfpscts           r2   __repr__z_PacketList.__repr__i   s   **tz*** 	 	AA  ==##,,Q// !HHHMHHHAE  
 	= 	=AAb11!'::: hhsmmm 11%(;;;= =AA 	
"--g666((3-----e4446 	6  "xx}}}!11$-@@@!xx}}} q!xx}}}	. 	.r4   c                 0    | j         | j        | j        d}|S )z
        Creates a basic representation of the instance, used in
        conjunction with __setstate__() e.g. by pickle

        :returns: dict representing this instance
        r*   r)   r+   ra   r0   states     r2   __getstate__z_PacketList.__getstate__   s&     8Z
 

 r4   c                 T    |d         | _         |d         | _        |d         | _        dS )z
        Sets instance attributes to values given by state, used in
        conjunction with __getstate__() e.g. by pickle

        :param state: dict representing this instance
        r*   r)   r+   Nra   rb   s     r2   __setstate__z_PacketList.__setstate__   s*     <7^
j)r4   c                 4    | j                                         S r6   )r*   __iter__r8   s    r2   rh   z_PacketList.__iter__   s    x  """r4   c                 ,    t          | j        |          S r6   )getattrr*   )r0   attrs     r2   __getattr__z_PacketList.__getattr__   s    tx&&&r4   c                 l    t          t                    r8                      fd j        D             j        d j                  S t          t                    r7                      j                                      d j        z            S  j                                      S )Nc                 B    g | ]}                     |          v |S r;   )r>   )rH   rI   itemr0   s     r2   
<listcomp>z+_PacketList.__getitem__.<locals>.<listcomp>   s0    "S"S"S$$--PQBRBR:R:R1:R:R:Rr4   z from r1   zmod %s)	r   r   	__class__r*   __name__r+   r/   slice__getitem__)r0   ro   s   ``r2   ru   z_PacketList.__getitem__   s    T:&& 	V>>"S"S"S"S"Sdh"S"S"S7;}}}dmm'T " V V VdE"" 	A>>$("6"6t"<"<'/$-'? " A A Ax##D)))r4   _T
SndRcvListc                 h    |                      | j        |j        z   | j        d|j                  S )N+rq   rr   r*   r+   )r0   rY   s     r2   __add__z_PacketList.__add__   s@     ~~Huy   
 
 	
r4   c                     | j         D ]A}| || s
|#t          |                     |                     /t           ||            BdS )a  prints a summary of each packet

        :param prn: function to apply to each packet instead of
                    lambda x:x.summary()
        :param lfilter: truth function to apply to each packet to decide
                        whether it will be displayed
        N)r*   printrB   )r0   prnlfilterrZ   s       r2   rA   z_PacketList.summary   sk      	 	A"w{ {dmmA&&''''cc1g	 	r4   c                    t          | j                  D ]t\  }}| || st          t          j                            |d          d           |#t          |                     |                     bt           ||            udS )a)  prints a summary of each packet with the packet's number

        :param prn: function to apply to each packet instead of
                    lambda x:x.summary()
        :param lfilter: truth function to apply to each packet to decide
                        whether it will be displayed
        N%04ifmtrM   )end)	enumerater*   r}   r   rS   idrB   )r0   r~   r   ir*   s        r2   nsummaryz_PacketList.nsummary   s      )) 	! 	!FAs"w} $"%%aV%44#>>>>{dmmC(())))cc3i    	! 	!r4   c                      | j         |i |S )zBBest way to display the packet list. Defaults to nsummary() method)r   r0   argskargss      r2   showz_PacketList.show   s     t}d,e,,,r4   c                 d    |                      fd| j        D             d| j        z            S )zReturns a packet list filtered by a truth function. This truth
        function has to take a packet as the only argument and return
        a boolean value.
        c                     g | ]	} | |
S r;   r;   )rH   rI   funcs     r2   rp   z&_PacketList.filter.<locals>.<listcomp>   s$    ???QddAh?q???r4   zfiltered %srq   rz   )r0   r   s    `r2   filterz_PacketList.filter   sF     ~~????$(???#04=#@  B B 	Br4   c                 ,    t          | j        g|R i |S )zPrints a table using a function that returns for each packet its head column value, head row value and displayed value  # noqa: E501
        ex: p.make_table(lambda x:(x[IP].dst, x[TCP].dport, x[TCP].sprintf("%flags%")) )r   r*   r   s      r2   r   z_PacketList.make_table   s$     $(3T333U333r4   c                 ,    t          | j        g|R i |S )z0Same as make_table, but print a table with lines)r   r*   r   s      r2   r   z_PacketList.make_lined_table   s$      949995999r4   c                 ,    t          | j        g|R i |S )z7Same as make_table, but print a table with LaTeX syntax)r   r*   r   s      r2   r   z_PacketList.make_tex_table  s$     dh7777777r4   Fc                     ddl m}m}m} fd| j        D             }nfd| j        D             }|i k    r|}|r |j        t          | i |}	n |j        |fi |}	|s|                                 |	S )zApplies a function to each packet to get a value that will be plotted
        with matplotlib. A list of matplotlib.lines.Line2D is returned.

        lfilter: a truth function that decides whether a packet must be plotted
        r   pltMATPLOTLIB_INLINEDMATPLOTLIB_DEFAULT_PLOT_KARGSNc                     g | ]} | S r;   r;   rH   er[   s     r2   rp   z$_PacketList.plot.<locals>.<listcomp>   s    000!1000r4   c                 $    g | ]} |  | S r;   r;   rH   r   r[   r   s     r2   rp   z$_PacketList.plot.<locals>.<listcomp>"  s*    ???!77A;?1???r4   )scapy.libs.matplotr   r   r   r*   plotzipr   )
r0   r[   r   plot_xyr   r   r   r   lst_pktsliness
    ``       r2   r   z_PacketList.plot
  s    	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 ?0000tx000HH?????tx???H B;;1E 	0CHc8n666EECHX////E " 	HHJJJr4   rK   c                 D    ddl m}m}m} 2 fdt	          t           j                  |z
            D             }n2 fdt	          t           j                  |z
            D             }|i k    r|} |j        |fi |}	|s|                                 |	S )zdiffplot(f, delay=1, lfilter=None)
        Applies a function to couples (l[i],l[i+delay])

        A list of matplotlib.lines.Line2D is returned.
        r   r   Nc                 Z    g | ]'} j         |         j         |d z                      (S rK   r*   )rH   r   r[   r0   s     r2   rp   z(_PacketList.diffplot.<locals>.<listcomp>H  sE     ? ? ? $(1+txA77 ? ? ?r4   c                     g | ]=} j         |                    j         |         j         |d z                      >S r   r   )rH   r   r[   r   r0   s     r2   rp   z(_PacketList.diffplot.<locals>.<listcomp>K  sZ     1 1 1"748A;//1$(1+txA77 1 1 1r4   )	r   r   r   r   ranger7   r*   r   r   )
r0   r[   delayr   r   r   r   r   r   r   s
   `` `      r2   diffplotz_PacketList.diffplot2  s   	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 ?? ? ? ? ?!&s48}}u'<!=!=? ? ?HH1 1 1 1 1 1!&s48}}u'<!=!=1 1 1H
 B;;1E++U++ " 	HHJJJr4   c                    ddl mm}m} fd| j        D             }nfd| j        D             }i }|D ].\  }	}
|                    |	g                               |
           /s||r"fd|                                D             }n!fd|                                D             }                    dd	
           |s	                                 |S )zUses a function that returns a label and a value for this label, then
        plots all the values label by label.

        A list of matplotlib.lines.Line2D is returned.
        r   r   Nc              3   "   K   | ]	} | V  
d S r6   r;   r   s     r2   	<genexpr>z(_PacketList.multiplot.<locals>.<genexpr>p  s)      00!1000000r4   c              3   ,   K   | ]} |  | V  d S r6   r;   r   s     r2   r   z(_PacketList.multiplot.<locals>.<genexpr>r  s4      ??!77A;?1??????r4   c           
      v    g | ]5\  }} j         t          t          |           i t          |           6S )label)r   listr   dictrH   kplr   r   s      r2   rp   z)_PacketList.multiplot.<locals>.<listcomp>~  sU     - - -B SXtCH~~Fe11E1E1EFF - - -r4   c           
      P    g | ]"\  }} j         |fi t          |           #S r   )r   r   r   s      r2   rp   z)_PacketList.multiplot.<locals>.<listcomp>  sN     - - -B SXb99Da$8$8$899 - - -r4   zcenter right)g      ?g      ?)locbbox_to_anchor)
r   r   r   r   r*   
setdefaultappenditemslegendr   )r0   r[   r   r   r   r   r   r   dr   vr   r   s    `` `       @r2   	multiplotz_PacketList.multiplotZ  sn   	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 ?0000tx000HH?????tx???H  	* 	*DAqLLB&&q))))  	21E 	-- - - - -"#''))- - -EE- - - - -"#''))- - -E

~j
AAA " 	HHJJJr4   c                 T    | D ]$}t          |                     |                     %dS )z5Prints an hexadecimal dump of each packet in the listN)r   r>   )r0   r\   s     r2   
rawhexdumpz_PacketList.rawhexdump  s:      	& 	&ADMM!$$%%%%	& 	&r4   c           
         t          | j                  D ]\  }}|                     |          }| ||          s(t          t          j                            |d          d|                    d          d|                     |                     |	                    t          j
                  r1t          |                    t          j
                  j                   dS )zSame as nsummary(), except that if a packet has a Raw layer, it will be hexdumped  # noqa: E501
        lfilter: a truth function that decides whether a packet must be displayedNr   r   rM   %.time%)r   r*   r>   r}   r   rS   r   sprintfrB   rR   	raw_layerr   getlayerloadr0   r   r   r*   r\   s        r2   hexrawz_PacketList.hexraw  s      )) 	9 	9FAsc""A"771::" 0 3 3A6 3 B B B B !		) 4 4 4 4 $c 2 2 24 5 5 5 zz$.)) 9

4>227888	9 	9r4   c           
      V   t          | j                  D ]\  }}|                     |          }| ||          s(t          t          j                            |d          d|                    d          d|                     |                     t          |           dS )zSame as nsummary(), except that packets are also hexdumped
        lfilter: a truth function that decides whether a packet must be displayedNr   r   rM   r   )
r   r*   r>   r}   r   rS   r   r   rB   r   r   s        r2   r   z_PacketList.hexdump  s      )) 	 	FAsc""A"771::" 0 3 3A6 3 B B B B !		) 4 4 4 4 $c 2 2 24 5 5 5 AJJJJ	 	r4   c           
         t          | j                  D ]\  }}|                     |          }|                    t          j                  r| ||          rt          t          j                            |d          d|	                    d          d| 
                    |                     t          |                    t          j                  j                   dS )z#Same as hexraw(), for Padding layerNr   r   rM   r   )r   r*   r>   rR   r   padding_layerr}   rS   r   r   rB   r   r   r   r   s        r2   paddingz_PacketList.padding  s      )) 		 		FAsc""Azz$,-- ?ggajj?(8(;(;A6(;(J(J(J(J()		)(<(<(<(<(,c(:(:(:< = = = 

4#566;  		 		r4   c           
      `   t          | j                  D ]\  }}|                     |          }|                    t          j                  r|                    t          j                  j        }||dd         t          |          z  k    r}| ||          rt          t          j
                            |d          d|                    d          d|                     |                     t          |                    t          j                  j                   dS )z+Same as padding() but only non null paddingNrK   r   r   rM   r   )r   r*   r>   rR   r   r   r   r   r7   r}   rS   r   r   rB   r   )r0   r   r   r*   r\   pads         r2   	nzpaddingz_PacketList.nzpadding  s"     )) 	 	FAsc""Azz$,-- 
jj!3449#bqb'CHH,,,?ggajj?(8(;(;A6(;(J(J(J(J()		)(<(<(<(<(,c(:(:(:< = = = 

4#566;  	 	r4   c                 Z   |d }|}i }| j         D ]}|                     |          }	  ||          }n# t          $ r Y 0w xY wt          |          dk    rD|                    |dd         t                                                    |d                    |                    |d          dz   ||<   d}|                                D ]K\  \  }	}
}|d|	d	|
d
t          |t
                    rd
                    d |D                       n|dz  }L|dz  }t          |fi |S )am  Graphes a conversations between sources and destinations and display it
        (using graphviz and imagemagick)

        :param getsrcdst: a function that takes an element of the list and
            returns the source, the destination and optionally
            a label. By default, returns the IP source and
            destination from IP and ARP layers
        :param type: output type (svg, ps, gif, jpg, etc.), passed to dot's
            "-T" option
        :param target: filename or redirect. Defaults pipe to Imagemagick's
            display program
        :param prog: which graphviz program to use
        Nc                     d| v r| d         j         | d         j        fS d| v r| d         j         | d         j        fS d| v r| d         j        | d         j        fS t	                      )zExtract src and dst addressesIPIPv6ARP)srcdstpsrcpdst	TypeError)pkts    r2   
_getsrcdstz-_PacketList.conversations.<locals>._getsrcdst  sn     3;;IM3t9=99S==KOS[_==C<<JOSZ_==kk!r4         r   rK   zdigraph "conv" {
z	 "z" -> "z
" [label="z, c              3   4   K   | ]}t          |          V  d S r6   )strrG   s     r2   r   z,_PacketList.conversations.<locals>.<genexpr>  s(      221A222222r4   z"]
z}
)r*   r>   	Exceptionr7   r   setaddgetr   r/   joinr   )r0   	getsrcdstr   r   convr=   r\   cgrr]   r   ls               r2   conversationsz_PacketList.conversations  s{   $ 	" 	" 	" #I8 	- 	-Cc""AIaLL     1vv{{"1"suu--11!A$7777((1a..1,Q! 	 	IFQAB111jC6H6HOdii22222222aOO BB 	e$$e$$$s   5
AAc           	         |d }|d }|d }i }i }i }| j         D ]}	  ||           ||           ||          }}
}	|	|v r1||	         \  }}|dz  }|
|vr|                    |
           ||f||	<   nd|
gf||	<   |
|v r1||
         \  }}|dz  }||vr|                    |           ||f||
<   nd|gf||
<   |                    |d          dz   ||<   # t          $ r Y w xY wd } |d |                                D                       \  }} |d	 |                                D                       \  }} ||                                          \  }}d
}|dz  }|D ]N}	||	         \  }}dt          ||z
            ||z
  z  z   }|dt          |	          t          |	          ||fz  z  }O|dz  }|D ]N}
||
         \  }}dt          ||z
            ||z
  z  z   }|dt          |
          t          |
          ||fz  z  }O|D ]K}||         }dt          ||z
            ||z
  z  z   }|dt          |          t          |          ||fz  z  }L|dz  }|D ]8}	||	         \  }}|D ](}
|dt          |	          dt          |
          dz  })9|D ]8}
||
         \  }}|D ](}|dt          |
          dt          |          dz  })9|dz  }t          |fi |S )zExperimental clone attempt of http://sourceforge.net/projects/afterglow
        each datum is reduced as src -> event -> dst and the data are graphed.
        by default we have IP.src -> IP.dport -> IP.dstNc                  (    | d         d         j         S Nr   r   )r   rI   s    r2   <lambda>z'_PacketList.afterglow.<locals>.<lambda>      QqT$Z^ r4   c                  (    | d         d         j         S r   )dportr   s    r2   r   z'_PacketList.afterglow.<locals>.<lambda>  s    qtDz/ r4   c                  (    | d         d         j         S r   )r   r   s    r2   r   z'_PacketList.afterglow.<locals>.<lambda>  r   r4   rK   r   c                 f    t          d d | D                       \  }}||k    rd}|dk    rd}||fS )Nc                 r    t          | d         |d                   t          | d         |d                   fS )Nr   rK   )minmax)abs     r2   r   z7_PacketList.afterglow.<locals>.minmax.<locals>.<lambda>-  s+    AaD!A$QqT1Q4'I r4   c              3      K   | ]}||fV  	d S r6   r;   )rH   r   s     r2   r   z8_PacketList.afterglow.<locals>.minmax.<locals>.<genexpr>.  s&      --aAq6------r4   r   rK   r   )rI   mMs      r2   minmaxz%_PacketList.afterglow.<locals>.minmax+  sQ    II--1---/ /DAqAvvAvva4Kr4   c              3       K   | ]	\  }}|V  
d S r6   r;   rH   rI   _s      r2   r   z(_PacketList.afterglow.<locals>.<genexpr>5  &      66$!QA666666r4   c              3       K   | ]	\  }}|V  
d S r6   r;   r  s      r2   r   z(_PacketList.afterglow.<locals>.<genexpr>6  r  r4   z'digraph "afterglow" {
	edge [len=2.5];
z# src nodes
zl"src.%s" [label = "%s", shape=box, fillcolor="#FF0000", style=filled, fixedsize=1, height=%.2f,width=%.2f];
z# event nodes
zp"evt.%s" [label = "%s", shape=circle, fillcolor="#00FFFF", style=filled, fixedsize=1, height=%.2f, width=%.2f];
zr"dst.%s" [label = "%s", shape=triangle, fillcolor="#0000ff", style=filled, fixedsize=1, height=%.2f, width=%.2f];
z###
z "src.z
" -> "evt.z";
z "evt.z
" -> "dst.})r*   r   r   r   valuesfloatreprr   )r0   r   eventr   r   sleldlr   r]   r   r   nlstr  minsmaxsminemaxemindmaxdr   r  lst1lst2s                            r2   	afterglowz_PacketList.afterglow  s    ;++C=//E;++C 	 	A#a&&%%((CCFFa177UFAsFA||

1HBqEEHBqE77UFAsFA||

1HBqEEHBqEq!q(1   	 	 	 V66"))++66666
dV66"))++66666
dVBIIKK((
d9
o 	] 	]Aa5DAqE!d(OOtd{33A  B  FJ  KL  FM  FM  OS  TU  OV  OV  XY  [\  E]  ]  ]BB
 	a 	aAa5DAqE!d(OOtd{33A  F  JN  OP  JQ  JQ  SW  XY  SZ  SZ  \]  _`  Ia  a  aBB 	c 	cA1AE!d(OOtd{33A  H  LP  QR  LS  LS  UY  Z[  U\  U\  ^_  ab  Kc  c  cBB
g 	F 	FAeGAt F FDGGGGT!WWWWEEF 	F 	FAeGAt F FDGGGGT!WWWWEEF 	c	$$e$$$s   B7C
C%$C%r   c           	         t           j                                        }t          | j                  }t	          | j                  D ]\  }}|                     |                              ||          }|                                }|                    |	                                |
                                dz   d||fz  t           j        j        j        g           t          j        dk    rt          j        dd           |                    t           j                            |t           j        j        j        dt           j        j        z  d                      |S )N)layer_shiftrebuildrK   z+\font\cmssfont=cmss12\cmssfont{Frame %i/%i}r      .)paperformatmargin	fittosize)pyxdocumentr7   r*   r   r>   canvas_dumpbboxtextlefttopsizeLARGEr   verboswriter   pager  A4unitt_cm)	r0   r  r  r   len_resr   r*   r   cbbs	            r2   r#  z_PacketList.canvas_dumpW  sC   L!!##dh--)) 		5 		5FAsc""..;7> / @ @A&&((CFF388::swwyy1}.\`acj_k.knqnvn{  oB  nC  D  D  DyA~~D!!!HHS\&&qcl6N6Q./#(-.?12 ' 4 4 5 5 5 5 r4   c                     |d }|}t          | j                  }| j        D ];} ||                     |                    }||                             |           <t          |          S )Nc                    d| v rd| v sd| v rJd}d}||f}d| v rd}nd| v rd	}nd
| v rd}nd| v rd}n	d| v rd}nd}|                       |j        |           S d| v r|                      d          S |                      d          S dS )zExtract sessions from packetsEtherr   r   z{IP:%IP.src%}{IPv6:%IPv6.src%}z{IP:%IP.dst%}{IPv6:%IPv6.dst%}TCPz'TCP {}:%r,TCP.sport% > {}:%r,TCP.dport%UDPz'UDP {}:%r,UDP.sport% > {}:%r,UDP.dport%ICMPz?ICMP {} > {} type=%r,ICMP.type% code=%r,ICMP.code% id=%ICMP.id%ICMPv6z8ICMPv6 {} > {} type=%r,ICMPv6.type% code=%r,ICMPv6.code%zIPv6 {} > {} nh=%IPv6.nh%zIP {} > {} proto=%IP.proto%r   zARP %ARP.psrc% > %ARP.pdst%zEthernet type=%04xr,Ether.type%rO   )r   format)r\   
ip_src_fmt
ip_dst_fmtaddr_fmtr   s        r2   _session_extractorz0_PacketList.sessions.<locals>._session_extractorm  s     a<<qyyFaKK%E
%E
$.
#; A::"KCC"aZZ"KCC#q[[#<CC%]]#9CC#q[["=CC"?C yyX)>???! yy)FGGG yy)JKKKwr4   )r   rr   r*   r>   r   r   )r0   session_extractorr>  sessionsr\   sesss         r2   r@  z_PacketList.sessionsg  s    
 $  8 !3t~.. 	% 	%A$$a   D TN!!!$$$$H~~r4   c                 b   |                     dd          }t          d| j        z            }t          |d         t                    s|f}| j        D ]}|                     |          }d}|D ]}|d         }	|d         }
|d         }|	j        D ]}||v rt          |          dk    s$||         	                    |	j
                  |
k    rJ|s,|                                }|r|                                 d	}t          ||         |	j
        |           |                    |           |S )
aN  
        lst.replace(<field>,[<oldvalue>,]<newvalue>)
        lst.replace( (fld,[ov],nv),(fld,[ov,]nv),...)
          if ov is None, all values are replaced
        ex:
          lst.replace( IP.src, "192.168.1.1", "10.0.0.1" )
          lst.replace( IP.ttl, 64 )
          lst.replace( (IP.ttl, 64), (TCP.sport, 666, 777), )
        delete_checksumsFzReplaced %srq   r   rK   r   T)r   r,   r+   r/   tupler*   r>   ownersr7   getfieldvalr1   copyrC  setattrr   )r0   r   r   rC  rI   _pr\   copiedschemefldoldnewos                r2   replacez_PacketList.replace  sQ    !99%7??MDM9:::$q'5)) 	7D( 	 	Bb!!AF 9 9QiQiRj 9 9AAvvv;;!++qt/?/?/I/IS/P/P#) .$%FFHH#3 !9$%$6$6$8$8$8)-#AaD#(C8889 HHQKKKKr4   c                      | d                      j        |j                  }| j        }i |                    |           |d<   ||d<   t          d  fd j        D             D             ||          S )a  Returns the packet list from a given layer.

        See ``Packet.getlayer`` for more info.

        :param cls: search for a layer that is an instance of ``cls``
        :type cls: Type[scapy.packet.Packet]

        :param nb: return the nb^th layer that is an instance of ``cls``
        :type nb: Optional[int]

        :param flt: filter parameters for ``Packet.getlayer``
        :type flt: Optional[Dict[str, Any]]

        :param name: optional name for the new PacketList
        :type name: Optional[str]

        :param stats: optional list of protocols to give stats on; if not
                      specified, inherits from this PacketList.
        :type stats: Optional[List[Type[scapy.packet.Packet]]]
        :rtype: scapy.plist.PacketList
        Nz{} layer {}clsnbc                     g | ]}||S r6   r;   )rH   pcs     r2   rp   z(_PacketList.getlayer.<locals>.<listcomp>  s%     ! ! ! r4   c              3   X   K   | ]$}                      |          j        di V  %d S )Nr;   )r>   r   )rH   r\   getlayer_argr0   s     r2   r   z'_PacketList.getlayer.<locals>.<genexpr>  sT        >?)a  )99L99     r4   )r:  r+   rs   r)   updater,   r*   )r0   rS  rT  fltr1   r)   rX  s   `     @r2   r   z_PacketList.getlayer  s    8 < ''s|DDD=JE?$$$!U>!#L  ! !    CG8  ! ! ! %	
 
 	
r4   )Nr,   N)NN)NF)rK   Nr6   )NNN)r   rK   )NNNN)'rs   
__module____qualname__	__slots__r3   r9   r>   rB   rD   r_   rd   rf   rh   rl   ru   r   rv   r{   rA   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r#  r@  rQ  r   r;   r4   r2   r(   r(   B   s       ,,,I "   (      " " ". . .8  
* 
* 
*# # #' ' '* * * 
|\	2	2B

 

 

    , ! ! ! !,- - -
B B B4 4 4: : :
8 8 8 & & & &T & & & &T / / / /b& & &9 9 9 9         $ !%4% 4% 4% 4%n T% T% T% T%l   $ #) ) ) )V     F 	.
 .
 .
 .
 .
 .
r4   r(   )	metaclassc                       e Zd ZddZdS )r,   FNc                    | j         dd         }g }d}||dk    rt          |          }|t          |          k     r||         }|}|t          ||z   t          |          dz
            k     r|dz  }||         }|                    |          rL|                    t          ||                     |rd||         _        d||         _        ||= ||= |dz  }n'|t          ||z   t          |          dz
            k     |dz  }|t          |          k     |rd |D             }t          |          t          |          fS )ag  
        Matches packets in the list

        :param multi: True if a packet can have multiple answers
        :param lookahead: Maximum number of packets between packet and answer.
                          If 0 or None, full remaining list is
                          scanned for answers
        :return: ( (matched couples), (unmatched packets) )
        Nr   rK   r   c                 2    g | ]}t          |d           |S )	_answered)hasattrrG   s     r2   rp   z!PacketList.sr.<locals>.<listcomp>
  s'    GGGAwq+/F/FGaGGGr4   )	r*   r7   r   answersr   r#   rb  rw   r,   )	r0   multi	lookaheadremainsrr   r]   jrZ   s	            r2   rh  zPacketList.sr  sk    !!!	QFI#f++ooq	AAc)a-Vq9999Q1I99Q<< 	IIk!Q//000 !./q	+./q	+ q	q	FA c)a-Vq9999 FA! #f++oo"  	HGGGGGF"~~z&1111r4   )FN)rs   r[  r\  rh  r;   r4   r2   r,   r,     s(        #2 #2 #2 #2 #2 #2r4   r,   c                   6     e Zd Zg Z	 	 	 d fd	Zd Zd Z xZS )rw   NResultsc                 \    t          t          |                               |||           d S r6   )superrw   r3   )r0   r*   r1   r)   rr   s       r2   r3   zSndRcvList.__init__  s-     	j$((dE:::::r4   c                     |d         S )NrK   r;   r<   s     r2   r>   zSndRcvList._elt2pkt#  s    1vr4   c                 p    |d                                          d|d                                          S )Nr   z ==> rK   r@   r<   s     r2   rB   zSndRcvList._elt2sum'  s2    !!fnn....A0@0@0@AAr4   )Nrk  N)rs   r[  r\  r]  r3   r>   rB   __classcell__)rr   s   @r2   rw   rw     st         I ; ; ; ; ; ;  B B B B B B Br4   rw   )1__doc__r+  collectionsr   typingr   r   scapy.configr   scapy.base_classesr   r   r	   r
   r   scapy.utilsr   r   r   r   r   r   	functoolsr   r   r   r   r   r   r   r   r   r   r   r   r   r    scapy.packetr!   r!  ImportErrorr   r"   r#   r&   r(   r,   _PacketIterablerw   r;   r4   r2   <module>r{     s%   
 
			 # # # # # # ' ' ' ' ' ' ' '                                                                            	JJJJ 	 	 	D	  *)))))) jv6*+ 
 
6;	/	/`

 `

 `

 `

 `

'&/-A `

 `

 `

 `

F&2 &2 &2 &2 &2V$'$&2 &2 &2R V

6NB B B B B[),$B B B B Bs   $A) )A10A1