U e5dZP @sddlZddlZddlZddlZddlTddlmZdddddd d d d d dg eZ[ejejej e e e fZ edZdedfedfedffZedZdZddZdUdddddZdVddddZddddd d!d"d#d$d%d& Zd'd(Zd)d*Zd+dZd,d-Zddd.d Zed/d0Z d1e j!_"d2e j_"d3e j#_"d4e j$_"d5e j%_"d6e j&_"d7e j'_"d8e j(_"d9Z)d:Z*Gd;d d e Z+dd<d=d Z,d>d?Z-d@dAZ.dWdBdCZ/dXdddEdZ0ddddFdGZ1dYdddHdIdJZ2dKdLZ3e0Z4dMdNZ5dOd Z6dPd Z7GdQddZ8dRdSZ9e:dTkre9dS)ZN)*)__all__ code_infodis disassembledistbdiscofindlinestarts findlabels show_codeget_instructions InstructionBytecode FORMAT_VALUE)Nstrreprascii MAKE_FUNCTION)defaultsZ kwdefaultsZ annotationsZclosurecCs6zt||d}Wn tk r0t||d}YnX|S)Nevalexec)compile SyntaxError)sourcenamecr/usr/lib64/python3.8/dis.py _try_compiles rfiledepthc Csh|dkrt|ddSt|dr&|j}t|dr8|j}n4t|drJ|j}n"t|dr\|j}nt|drl|j}t|drt|j }|D]p\}}t |t rt d||dzt |||d Wn0tk r}zt d ||dW5d}~XYnXt |dqnht|d rt|||d nLt |ttfr6t||dn.t |trRt|||d ntd t|jdS) Nr!__func____code__gi_codeag_codecr_code__dict__zDisassembly of %s:r zSorry:co_code(don't know how to disassemble %s objects)rhasattrr$r%r&r'r(sortedr)items isinstance _have_codeprintr TypeError_disassemble_recursivebytes bytearray_disassemble_bytesr_disassemble_strtype__name__)xr!r"r.rZx1msgrrrr+s@             r#cCsX|dkr@z tj}Wntk r0tddYnX|jr@|j}q2t|jj|j|ddS)Nz no last traceback to disassembler#) syslast_tracebackAttributeError RuntimeErrortb_nextrtb_framef_codetb_lasti)tbr!rrrrXs Z OPTIMIZEDZ NEWLOCALSZVARARGSZ VARKEYWORDSZNESTEDZ GENERATORZNOFREEZ COROUTINEZITERABLE_COROUTINEZASYNC_GENERATOR)  @icCs`g}tdD]:}d|>}||@r |t|t|||N}|s qVq |t|d|S)NrJrE, )rangeappendCOMPILER_FLAG_NAMESgethexjoin)flagsnamesiflagrrr pretty_flagsrs rYcCst|dr|j}t|dr"|j}n4t|dr4|j}n"t|drF|j}nt|drV|j}t|trjt|d}t|drx|St dt |j dS) Nr$r%r&r'r(z r*r+) r,r$r%r&r'r(r/rrr2r8r9r:rrr_get_code_objects"        r[cCs tt|SN)_format_code_infor[rZrrrrscCsg}|d|j|d|j|d|j|d|j|d|j|d|j|d|j|dt|j |j r|d t |j D]}|d |q|j r|d t |j D]}|d |q|j r|d t |j D]}|d |q|jrH|dt |jD]}|d |q2|jrz|dt |jD]}|d |qdd|S)NzName: %szFilename: %szArgument count: %szPositional-only arguments: %szKw-only arguments: %szNumber of locals: %szStack size: %szFlags: %sz Constants:z%4d: %rzNames:z%4d: %szVariable names:zFree variables:zCell variables: )rPco_name co_filename co_argcountco_posonlyargcountco_kwonlyargcount co_nlocals co_stacksizerYco_flags co_consts enumerateco_names co_varnames co_freevars co_cellvarsrT)colinesZi_cZi_nrrrr]s<     r]cCstt||ddSNr#)r1r)rmr!rrrr s _InstructionzBopname opcode arg argval argrepr offset starts_line is_jump_targetz!Human readable name for operationzNumeric code for operationz6Numeric argument to operation (if any), otherwise Nonez4Resolved arg value (if known), otherwise same as argz0Human readable description of operation argumentz1Start index of operation within bytecode sequencez4Line started by this opcode (if any), otherwise Nonez1True if other code jumps to here, otherwise Falsec@seZdZdddZdS)r FrGcCsg}|r:|jdk r,d|}|||jn|d||rJ|dn |d|jrf|dn |d|t|j|||jt|j dk r|t|j t |j r|d|j dd | S) Nz%%%dd z-->z z>>z ()) starts_linerPis_jump_targetroffsetrjustopnameljust _OPNAME_WIDTHarg _OPARG_WIDTHargreprrTrstrip)self lineno_widthZmark_as_current offset_widthZfieldsZ lineno_fmtrrr _disassembles&      zInstruction._disassembleN)rsFrG)r9 __module__ __qualname__rrrrrr s) first_linecCsTt|}|j|j}tt|}|dk r4||j}nd}t|j|j|j |j |||SNr) r[rlrkdictr co_firstlineno_get_instructions_bytesr*rjrirg)r:rrm cell_names linestarts line_offsetrrrr s    cCs |}|dk r||}|t|fSr\r)Z const_indexZ const_listargvalrrr_get_const_infosrcCs*|}|dk r||}|}nt|}||fSr\r)Z name_indexZ name_listrrrrr_get_name_info's rc #st|}d}t|D]r\} } |dk rD|| d}|dk rD||7}| |k} d} d} dk rl} | tkrzt|\} } n| tkrt|\} } n| tkr| d} dt| } n| t krt|\} } n| t krt } | } n| t krt|\} } nr| t krFtd@\} } | td@f} | drl| r<| d7} | d7} n&| tkrldfd d ttD} tt| | | | | || VqdS) NrrFzto rsrGrErNz with formatc3s"|]\}}d|>@r|VqdS)rENr).0rWsr~rr gs z*_get_instructions_bytes..)r _unpack_opargsrRZhasconstrZhasnamerhasjrelrZhaslocalZ hascompareZcmp_opZhasfreerFORMAT_VALUE_CONVERTERSboolrrTrhMAKE_FUNCTION_FLAGSr r{)codevarnamesrV constantscellsrrlabelsrwryoprxrrrrrr7sV         rc Cs<|j|j}tt|}t|j||j|j|j|||ddSro) rlrkrr r6r*rjrirg)rmlastir!rrrrrrms  cCspt||d|dks|dkrl|dk r,|d}|jD]8}t|dr2t|dtd|f|dt|||dq2dS)Nr#rrEr*zDisassembly of %r:r )rrgr,r1r3)rmr!r"r:rrrr3ts    r3)r!rc Cs|dk } | r8t||} | dkr2tt| } q)r3r)rkwargsrrrr7sr7ccsdd}tdt|dD]J}||}|tkrN||d|B}|tkrH|d>nd}nd}|||fVqdS)NrrFrErH)rOrZ HAVE_ARGUMENTZ EXTENDED_ARG)rZ extended_argrWrr~rrrrsrcCs\g}t|D]J\}}}|dk r |tkr4|d|}n|tkr |}nq ||kr ||q |S)NrF)rrZhasjabsrP)rrryrr~Zlabelrrrr s c cs|jddd}|jddd}t|j}d}|j}d}t||D]P\}}|rz||krd||fV|}||7}||krzdS|dkr|d8}||7}qB||kr||fVdS)NrrFrErLrM) co_lnotabrr*rzip) rZbyte_incrementsZline_incrementsZ bytecode_lenZ lastlinenolinenoZaddrZ byte_incrZ line_incrrrrr s&   c@sHeZdZdddddZddZddZed d Zd d Zd dZ dS)rN)rcurrent_offsetcCsdt||_}|dkr&|j|_d|_n||_||j|_|j|j|_tt ||_ ||_ ||_ dSr) r[codeobjrr _line_offsetrlrk _cell_namesrr _linestarts_original_objectr)rr:rrrmrrr__init__s zBytecode.__init__c Cs*|j}t|j|j|j|j|j|j|jdS)Nr) rrr*rjrirgrrr)rrmrrr__iter__szBytecode.__iter__cCsd|jj|jS)Nz{}({!r}))format __class__r9rrrrr__repr__s zBytecode.__repr__cCs |jr|j}q||jj|jdS)N)r)r@rArBrC)clsrDrrrfrom_tracebackszBytecode.from_tracebackcCs t|jSr\)r]rrrrrinfosz Bytecode.infoc Csl|j}|jdk r|j}nd}t>}t|j|j|j|j|j |j |j ||d | W5QRSQRXdS)Nr)rrVrrrrr!r) rrioStringIOr6r*rjrirgrrrgetvalue)rrmryoutputrrrr s   z Bytecode.dis) r9rrrrr classmethodrrrrrrrrs  c Csfddl}|}|jd|dddd|}|j}|}W5QRXt||jjd}t |dS)Nrinfilerb?-)r8nargsdefaultr) argparseArgumentParser add_argumentZFileType parse_argsrreadrrr)rparserargsrrrrrr_testsr__main__)N)N)NNNNNr)r)rNNNNN);r<types collectionsrZopcoderZ _opcodes_all MethodType FunctionTypeCodeTyper staticmethodr8r0ZopmaprrrrrrrrrrrQrYr[rr]r namedtuplerpr{__doc__r~rrryrwrxr}rr r rrrrr3r6r7rrr r rrr9rrrrs    -  4  6   =