
    d(                        d dl mZ d dlmZ ddlmZmZmZ  edi ddddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~ddddddddddddddddddddddddddddddddddZ	d Z
 e
e	dd d8d        e
e	dd d8d        e
e	dd d8d        ed e	j                         D              Z edd      Z G d de      Zd Zy)    )
namedtuple)BytesIO   )struct_parsebytelist2string	read_blob
DW_OP_addr   DW_OP_deref   DW_OP_const1u   DW_OP_const1s	   DW_OP_const2u
   DW_OP_const2s   DW_OP_const4u   DW_OP_const4s   DW_OP_const8u   DW_OP_const8s   DW_OP_constu   DW_OP_consts   	DW_OP_dup   
DW_OP_drop   
DW_OP_over   
DW_OP_pick   
DW_OP_swap   	DW_OP_rot   DW_OP_xderef   	DW_OP_abs   	DW_OP_and   	DW_OP_div   DW_OP_minus   	DW_OP_mod   	DW_OP_mul   	DW_OP_neg   	DW_OP_not    DW_OP_or!   
DW_OP_plus"   DW_OP_plus_uconst#   	DW_OP_shl$   	DW_OP_shr%   
DW_OP_shra&   	DW_OP_xor'   	DW_OP_bra(   DW_OP_eq)   DW_OP_ge*   DW_OP_gt+   DW_OP_le,   DW_OP_lt-   DW_OP_ne.   
DW_OP_skip/   
DW_OP_regx   DW_OP_fbreg   DW_OP_bregx   DW_OP_piece   DW_OP_deref_size   DW_OP_xderef_size   	DW_OP_nop   DW_OP_push_object_address   DW_OP_call2   DW_OP_call4   DW_OP_call_ref   DW_OP_form_tls_address   DW_OP_call_frame_cfa   DW_OP_bit_piece   DW_OP_implicit_value   DW_OP_stack_value   DW_OP_implicit_pointer   DW_OP_addrx   DW_OP_constx   DW_OP_entry_value   DW_OP_const_type   DW_OP_regval_type   DW_OP_deref_type   DW_OP_xderef_type   DW_OP_convert   DW_OP_reinterpret   DW_OP_lo_user   DW_OP_GNU_push_tls_addressDW_OP_GNU_implicit_pointer   DW_OP_GNU_entry_value   DW_OP_GNU_const_type   DW_OP_GNU_regval_type   DW_OP_GNU_deref_type   DW_OP_GNU_convert   DW_OP_GNU_parameter_ref   DW_OP_hi_user   c                 R    t        ||dz         D ]  }||}||z   |z
  }|| |<    y)z Generate values in a map (dict) dynamically. Each key starts with
        a (string) prefix, followed by an index in the inclusive range
        [index_start, index_end]. The values start at value_start.
       N)range)mapprefixindex_start	index_endvalue_startindexnamevalues           ;/usr/lib/python3/dist-packages/elftools/dwarf/dwarf_expr.py_generate_dynamic_valuesr   a   s@    
 {IM2 'e#k1D	    	DW_OP_lit0   	DW_OP_regP   
DW_OP_bregp   c              #   *   K   | ]  \  }}||f  y wN ).0kvs      r   	<genexpr>r   p   s     FDAq!QFs   DWARFExprOpzop op_name args offsetc                       e Zd ZdZd Zd Zy)DWARFExprParserzDWARF expression parser.

    When initialized, requires structs to cache a dispatch table. After that,
    parse_expr can be called repeatedly - it's stateless.
    c                 $    t        |      | _        y r   )_init_dispatch_table_dispatch_table)selfstructss     r   __init__zDWARFExprParser.__init__   s    3G<r   c                 H   t        t        |            }g }	 |j                         }|j                  d      }t	        |      dk(  r	 |S t        |      }t        j                  |d|z        }| j                  |   } ||      }	|j                  t        |||	|             )zs Parses expr (a list of integers) into a list of DWARFExprOp.

        The list can potentially be nested.
        r   r   zOP:0x%x)opop_nameargsoffset)r   r   tellreadlenordDW_OP_opcode2namegetr   appendr   )
r   exprstreamparsedr   byter   r   
arg_parserr   s
             r   
parse_exprzDWARFExprParser.parse_expr   s    
 ./ [[]F;;q>D4yA~  TB'++B	B?G --b1Jf%DMM+W4PVWX! r   N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   x   s    =r   r   c           	      
    i fd}d } fd}d }d } fd} fd} fd} |d	 |               |d
 | j                  d                    |d | j                  d                    |d | j                  d                    |d | j                  d                    |d | j	                  d                    |d | j                  d                    |d | j                  d                    |d | j                  d                    |d | j                  d                    |d | j                  d                    |d | j                  d                    |d | j                  d                    |d | j                  d                    |d | j	                  d                    |d | j	                  d                   dD ]  }	 ||	 |               t        dd      D ]E  }
 |d|
z   |               |d|
z   |               |d|
z   | j                  d                   G  |d  | j                  d                    |d! | j                  d                    |d" | j                  d       j                  d                    |d# | j                  d                    |d$ | j                  d       j                  d                    |d% | j                  d                    |d& | j                  d                    |d' | j                  d                    |d( | j                  d                    |d) | j                  d                    |d* |               |d+ |               |d, |               |d- | j                  d       j                  d                    |d. | j                  d       j                  d                    |d/ | j                  d       j                  d                    |d0 | j                  d                    |d1 |               |d2 |               |d3 | j                  d       j                  d                    |d4 | j                  d       j                  d                    |d5 | j                  d       j                  d                    |d6 | j                  d                    |d7 | j                  d                   S )8a  Creates a dispatch table for parsing args of an op.

    Returns a dict mapping opcode to a function. The function accepts a stream
    and return a list of parsed arguments for the opcode from the stream;
    the stream is advanced by the function as needed.
    c                     |t         |    <   y r   )DW_OP_name2opcode)opcode_namefunctables     r   addz!_init_dispatch_table.<locals>.add   s    04,-r   c                      d S )Nc                     g S r   r   )r   s    r   <lambda>z<_init_dispatch_table.<locals>.parse_noargs.<locals>.<lambda>   s    b r   r   r   r   r   parse_noargsz*_init_dispatch_table.<locals>.parse_noargs   s      r   c                       fdS )Nc                 <    t        j                  d      |       gS N )r   Dwarf_target_addrr   r   s    r   r   z=_init_dispatch_table.<locals>.parse_op_addr.<locals>.<lambda>   s!    |G,E,Eb,I,2 4 5 r   r   r   s   r   parse_op_addrz+_init_dispatch_table.<locals>.parse_op_addr   s    5 	5r   c                       fdS )Nc                     t        |       gS r   r   )r   
arg_structs    r   r   z@_init_dispatch_table.<locals>.parse_arg_struct.<locals>.<lambda>   s    |J?@ r   r   )r   s   `r   parse_arg_structz._init_dispatch_table.<locals>.parse_arg_struct   s	    @@r   c                       fdS )Nc                 4    t        |       t        |       gS r   r   )r   arg1_structarg2_structs    r   r   zA_init_dispatch_table.<locals>.parse_arg_struct2.<locals>.<lambda>   s    |K@+K@B r   r   )r   r   s   ``r   parse_arg_struct2z/_init_dispatch_table.<locals>.parse_arg_struct2   s    B 	Br   c                      fd} | S )Nc                     t        j                  d      |       }t        | |      }t              j	                  |      gS r   )r   Dwarf_uleb128r   r   r   )r   sizenested_expr_blobr   s      r   parsez=_init_dispatch_table.<locals>.parse_nestedexpr.<locals>.parse   sA     5 5b 96BD(6#G,778HIJJr   r   )r   r   s    r   parse_nestedexprz._init_dispatch_table.<locals>.parse_nestedexpr   s    	K r   c                       fdS )Nc                 P    t        | t        j                  d      |             gS r   )r   r   r   r   s    r   r   z:_init_dispatch_table.<locals>.parse_blob.<locals>.<lambda>   s%    yg>S>STV>WY_1`ab r   r   r   s   r   
parse_blobz(_init_dispatch_table.<locals>.parse_blob   s	    bbr   c                       fdS )Nc           	          t        j                  d      |       t        | t        j                  d      |             gS r   )r   r   r   Dwarf_uint8r   s    r   r   z?_init_dispatch_table.<locals>.parse_typedblob.<locals>.<lambda>   s\    |G,A,A",EvNPYZ`bnov  pC  pC  DF  pG  IO  cP  QQ  R r   r   r   s   r   parse_typedblobz-_init_dispatch_table.<locals>.parse_typedblob   s     R  	Rr   r	   r   r   r   r   r   r   r   r   r   r   r   r   r'   rC   rM   r[   )"r   r!   r#   r%   r)   r)   r+   r-   r/   r1   r3   r5   r7   r9   r;   r=   r?   rA   rE   rG   rI   rK   rO   rQ   rS   rU   rW   rY   ri   rk   rs   ru   r{   r   r   r>   zDW_OP_lit%szDW_OP_reg%szDW_OP_breg%sr_   r]   ra   rc   rw   re   rg   rm   ro   rq   ry   r   r   r   r   r}   r   r   r   r   r   r   r   r   )r   r  
Dwarf_int8Dwarf_uint16Dwarf_int16Dwarf_uint32Dwarf_int32Dwarf_uint64Dwarf_int64Dwarf_sleb128r   Dwarf_offset)r   r   r   r   r   r   r  r  r  opnamenr   s   `          @r   r   r      sO    E5!5AB
cR mo&'(=(=b(ABC)'*=*=b*ABC)'*<*<R*@AB)'*>*>r*BCD)'*=*=b*ABC)'*>*>r*BCD)'*=*=b*ABC)'*>*>r*BCD)'*=*=b*ABC()>)>r)BCD()>)>r)BCD&w':':2'>?@-g.C.CB.GHI%g&9&9"&=>?&w':':2'>?@	2 
$ 	FLN#
$ 1b\ MMA|~.MA|~.NQ 01F1Fr1J KLM
 '(=(=b(ABC&w'<'<R'@AB()>)>r)B)0)>)>r)BD E'(=(=b(ABC,W-B-B2-F-4-B-B2-FH I,W-?-?-CDE-g.@.@.DEF'(<(<R(@AB'(<(<R(@AB*7+?+?+CDE
--/0O-..w/D/DR/H3:3H3H3LN O-g.A.A".E.5.C.CB.GI J "3G4H4H4L8?8M8Mb8Q#S T)'*?*?*CDE!1!34 12!273H3H3L3:3H3H3L"N O 1'2E2Eb2I3:3H3H3L!N O$&78L8LR8P8?8M8Mb8Q'S T!#3G4H4H4L#MN-g.C.CB.GHILr   Nr   )collectionsr   ior   common.utilsr   r   r   dictr   r   itemsr   r   objectr   r   r   r   r   <module>r     sO   #  C C  OOO O 	O
 O O O O O O O O O O O  !O" #O$ %O& 'O( )O* +O, -O. /O0 1O2 3O4 5O6 7O8 9O: ;O< =O> ?O@ AOB COD EOF GOH IOJ KOL MON OOP QOR SOT UOV WOX YOZ [O\ ]O^ _O` aOb cOd #eOf gOh iOj kOl  mOn oOp qOr sOt uOv  wOx yOz {O| }O~ O@ AOB COD EOF GOH IOJ KOL  $MON  $OOP QOR SOT UOV WOX YOZ ![O\ ]O b *KB E *KB E *L!R F F,=,C,C,EFF 
 (@A$f $Nlr   