U
    Ծ|e                     @   s<   d Z ddlmZmZ ddlZddlZddlmZ dd ZdS )zMiscellaneous inspection tools
    )NamedTemporaryFileTemporaryDirectoryN)NumbaWarningc                    sV   zddl W n tk
r(   tdY nX d fdd	G fdddt}| S )	z
    Gets the CFG of the disassembly of an ELF object, elf, at mangled name,
    mangled_symbol, and renders it appropriately depending on the execution
    environment (terminal/notebook).
    r   Nz$r2pipe package needed for disasm CFGc                    s  ddl m} | d krtdt z}td|d}|  |  W 5 Q R X d}zDtj	|j
 d}tj||}| }|||j
f |}d}W nB tk
r }	 z$d|	 d	}
tt|
 |j
}W 5 d }	~	X Y nX zxd
ddddg}j||d}|d |r<d d }|d |d| d |d |d|  }|  W nD tk
r }	 z$dt|	krd}
t|
n|	W 5 d }	~	X Y nX W 5 Q R X |S )Nr   )	ToolchainzNo command givenF)deletedirz.soTzALinking the ELF object with the distutils toolchain failed with: z\. Disassembly will still work but might be less accurate and will not use DWARF information.z-2z-e io.cache=truez-e scr.color=1z-e asm.dwarf=truez-e scr.utf8=true)flagsZaaaaaa=   ze bin.demangle=falsezs `is~ z[1]`ze bin.demangle=truez%szradare2 in PATHzThis feature requires 'radare2' to be installed and available on the system see: https://github.com/radareorg/radare2. Cannot find 'radare2' in $PATH.)Znumba.pycc.platformr   
ValueErrorr   r   writeflushospathbasenamenamejoinZlink_shared	Exceptionwarningswarnr   opencmdquitstrRuntimeError)r   r   tmpdirfZlinkedZraw_dso_nameZ
linked_dsotcZobj_to_analyseemsgr   rZmangled_symbol_61chardata)elfmangled_symbolr2pipe R/var/www/website-v5/atlas_env/lib/python3.8/site-packages/numba/misc/inspection.pyget_rendering   sR    





 z-disassemble_elf_to_cfg.<locals>.get_renderingc                       s$   e Zd Z fddZ fddZdS )z)disassemble_elf_to_cfg.<locals>.DisasmCFGc                    sZ   zdd l }W n tk
r(   tdY nX  dd}|dd ||}|ddS )	Nr   z&graphviz package needed for disasm CFGZagfdr   zfontname="Courier",zfontname="Courier",fontsize=6,svgzUTF-8)graphvizImportErrorr   replaceSourcepipedecode)selfr)   Zjupyter_renderingsrcr&   r$   r%   
_repr_svg_X   s    

z4disassemble_elf_to_cfg.<locals>.DisasmCFG._repr_svg_c                    s
    ddS )NZagfr'   r$   )r/   r1   r$   r%   __repr__d   s    z2disassemble_elf_to_cfg.<locals>.DisasmCFG.__repr__N)__name__
__module____qualname__r2   r3   r$   r1   r$   r%   	DisasmCFGV   s   r7   )N)r#   r*   r   object)r!   r"   r7   r$   )r!   r&   r"   r#   r%   disassemble_elf_to_cfg
   s    Ar9   )	__doc__tempfiler   r   r   r   numba.core.errorsr   r9   r$   r$   r$   r%   <module>   s
   