o
    i                     @   s   d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d d	lmZ d d
lmZ ddddejfdee dee dee dee dedefddZdS )    N)chain)Any)Iterable)Optional)Span)_asm_request_context)STACK_TRACE)core)configmessagespan
crop_stackstack_id	namespacereturnc                    s  t jsdS |tjkrt jrt jsdS |tjkrt jsdS |tjkr(t jr(t	
 }|du r0t }|du s8|du r:dS |tjpAi }||g }t|}t jrV|t jkrVdS t  |durzt D ]\}}	 | jjj|kry |d d   nqbd|d}
| dur| |
d< t t j  krdkrn n tt jt j d }t j| }tt|tt | t }ntt } fd	d
|D }||
d< ||
 |||< |tj| dS )z
    Report a stack trace to the current span.
    This is used to report stack traces for exploit prevention.
    Return the stack id for the reported stack trace to link it in triggers.
    FN   python)languageidr   r   d   c                    s@   g | ]}|t  | jjd  | jjj | j | jdqS )co_qualname)r   functionfileline)getattrframef_codeco_namefilenamelineno).0istack c/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/appsec/_exploit_prevention/stack_traces.py
<listcomp>F   s    z report_stack.<locals>.<listcomp>framesT)
asm_config_ep_stack_trace_enabledr   RASP_asm_enabled_ep_enabledIAST_iast_enabled_iast_use_root_spanr	   get_root_spanr   get_entry_span_get_struct_tagTAGgetlen_ep_max_stack_tracesinspectr#   	enumerater   r   r   _ep_max_stack_trace_depthint_ep_stack_top_percentr   rangeappend_set_struct_tag)r   r   r   r   r   appsec_tracescurrent_listtotal_lengthr!   r   res	top_stackbottom_stackiteratorr'   r$   r"   r%   report_stack   sT   
"
	
rF   )r7   	itertoolsr   typingr   r   r   ddtrace._trace.spanr   ddtrace.appsecr   ddtrace.appsec._constantsr   ddtrace.internalr	   ddtrace.internal.settings.asmr
   r(   r*   strboolrF   r$   r$   r$   r%   <module>   s8    