\d!q dZddlZddlZddlZddlZddlTddlmZmZm Z m Z m Z m Z gdezZ[ej ejejeeefZedZdedfed fed ffZed Zd Zed ZedZedZedZedZ e!e"Z#e$eZ%de&e#DZ'e(e'e D]\Z)Z*e*e#e)<e)e%e*<de j+DZ,dZ-d`ddddddZ.d`dddddZ/ddddddd d!d"d#d$ Z0d%Z1Gd&d'Z2e2Z3d(Z4d)Z5d*Z6d+Z7d,Z8dd-d.Z9ej:d/gd0dgd1z2Z;ej:d3gd4dg2Z_d9ed?ZDd@ZEdAZFGdBdCe<ZGddddDdEZHdFZIdGZJdHZKdIZLdJZMdKZN dadMZOdbdddddOZPddddddPZQ dcdddLdddQdRZRdSZSePZTdTZUdUeUdVz zZVdWZWdXZXdYZYdZZZd[Z[Gd\d]Z\d^Z]e^d_kr e]dSdS)dz0Disassembler of Python byte code into mnemonics.N)*)__all__ _cache_format_inline_cache_entries_nb_ops_specializations_specialized_instructions) code_infodis disassembledistbdiscofindlinestarts findlabels show_codeget_instructions InstructionBytecode FORMAT_VALUE)Nstrreprascii MAKE_FUNCTION)defaults kwdefaults annotationsclosure LOAD_CONST LOAD_GLOBAL BINARY_OP JUMP_BACKWARDCACHEcBg|]\}}|d|S)<) startswith).0slotnames ..\python\lib\dis.py r+-s.UUU dPS@T@TUtUUUc$i|] \}}|D]}||Sr.)r'basefamily specializeds r* r23s@   &$V\  GRK    r,cn t||d}n!#t$rt||d}YnwxYw|S)zAttempts to compile the given source, first as an expression and then as a statement if the first approach fails. Utility function to accept strings in functions that otherwise expect code objects evalexec)compile SyntaxError)sourcer)cs r* _try_compiler:7sO* FD& ) ) *** FD& ) )* Hs 22Ffiledepth show_cachesadaptivec|t|||dSt|dr|j}t|dr|j}nGt|dr|j}n/t|dr|j}nt|dr|j}t|drt|j }|D]}\}}t|trctd |z|  t||||| n)#t$r}td || Yd}~nd}~wwxYwt| ~dSt|d rt||||| dSt|t t"frt%|||dSt|t&rt)||||| dStdt+|jz)a0Disassemble classes, methods, functions, and other compiled objects. With no argument, disassemble the last traceback. Compiled objects currently include generator objects, async generator objects, and coroutine objects, all of which store their code object in a special attribute. Nr<r>r?__func____code__gi_codeag_codecr_code__dict__zDisassembly of %s:r<r;zSorry:co_code)r<r>(don't know how to disassemble %s objects)r hasattrrBrCrDrErFsortedrGitems isinstance _have_codeprintr TypeError_disassemble_recursivebytes bytearray_disassemble_bytesr_disassemble_strtype__name__) xr<r=r>r?rMr)x1msgs r*r r DsP y 4[8DDDDq* Jq* J I   I I   I I   Iq**qz''))** ! !HD""j)) !*T1====4U V^_____ 444(Cd33333333344     ! ! I  *qt5k\deeeeee Ay) * **14[AAAAAA As  *U V^______BQ()** *s4D  D/D**D/rAc|A tj}n#t$rtddwxYw|jr|j}|jt |jj|j|||dS)z2Disassemble a traceback (default: last traceback).Nz no last traceback to disassemblerA) syslast_tracebackAttributeError RuntimeErrortb_nextr tb_framef_codetb_lasti)tbr<r>r?s r*r r qs z M#BB M M MABB L Mj)rz"bj) "BKd ^fggggggs , OPTIMIZED NEWLOCALSVARARGS VARKEYWORDSNESTED GENERATORNOFREE COROUTINEITERABLE_COROUTINEASYNC_GENERATOR)  @ic 4g}tdD]P}d|z}||zrD|t|t |||z}|sn#Q|t |d|S)z+Return pretty representation of code flags.rurp, )rangeappendCOMPILER_FLAG_NAMESgethexjoin)flagsnamesiflags r* pretty_flagsrs E 2YY!!!t 4<  LL,00s4yyAA B B B TME  SZZ   99U  r,ceZdZdZdS)_UnknowncdS)Nz r.selfs r*__repr__z_Unknown.__repr__s{r,N)rX __module__ __qualname__rr.r,r*rrs#r,rct|dr|j}t|dr|j}nGt|dr|j}n/t|dr|j}nt|dr|j}t |trt|d}t|dr|Stdt|j z) zDHelper to handle methods, compiled or raw code objects, and strings.rBrCrDrErFz rIrJ) rKrBrCrDrErFrNrr:rQrWrXrYs r*_get_code_objectrsq* Jq* J I   I I   I I   I!S- O , ,q) >GG$% & &&r,cbt|}|tvrtt|n|SN) _all_opnamedeoptmap _all_opmap)opr)s r*_deoptoprs) r?D)-)9)9:htn % %rAr,c"|r|jn|jSr)_co_code_adaptiverI)cor?s r*_get_code_arrayrs#+ ;2  ;r,c:tt|S)z1Formatted details of methods, functions, or code.)_format_code_inforrs r*r r s -a00 1 11r,cg}|d|jz|d|jz|d|jz|d|jz|d|jz|d|jz|d|jz|dt|j z|j rD|d t|j D]}|d |z|j rD|d t|j D]}|d |z|j rD|d t|j D]}|d |z|jrD|dt|jD]}|d |z|jrD|dt|jD]}|d |zd|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: )r|co_name co_filename co_argcountco_posonlyargcountco_kwonlyargcount co_nlocals co_stacksizerco_flags co_consts enumerateco_names co_varnames co_freevars co_cellvarsr)rlinesi_ci_ns r*rrs| E LL(2:5666 LL(2>9::: LL(2>9::: LL023HHIII LL(2+??@@@ LL(2=8999 LL(2?:;;; LL(< +D+DDEEE |* \"""R\** * *C LLS ) ) ) ) {* XR[)) * *C LLS ) ) ) ) ~* &'''R^,, * *C LLS ) ) ) ) ~* &'''R^,, * *C LLS ) ) ) ) ~* &'''R^,, * *C LLS ) ) ) ) 99U  r,rHcBtt||dS)z}Print details of methods, functions, or code to *file*. If *file* is not provided, the output is printed on stdout. rHN)rPr )rr<s r*rrs#  )B--d######r, Positions)lineno end_lineno col_offsetend_col_offsetrr)r _Instruction) opnameopcodeargargvalargreproffset starts_lineis_jump_target positionsz!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 FalsezPdis.Positions object holding the span of source code covered by this instruction_ExceptionTableEntryzstart end target depth lasticeZdZdZddZdS)raDetails for a bytecode operation Defined fields: opname - human readable name for operation opcode - numeric code for operation arg - numeric argument to operation (if any), otherwise None argval - resolved arg value (if known), otherwise same as arg argrepr - human readable description of operation argument offset - start index of operation within bytecode sequence starts_line - line started by this opcode (if any), otherwise None is_jump_target - True if other code jumps to here, otherwise False positions - Optional dis.Positions object holding the span of source code covered by this instruction FrrcLg}|rB|j#d|z}|||jzn|d|z|r|dn|d|jr|dn|d|t|j|||jt|j f|t|j t|j r |d|j zd zd | S) a%Format instruction details for inclusion in disassembly output *lineno_width* sets the width of the line number field (0 omits it) *mark_as_current* inserts a '-->' marker arrow as part of the line *offset_width* sets the width of the instruction offset field Nz%%%dd z-->z z>> ())rr|rrrrjustrljust _OPNAME_WIDTHr _OPARG_WIDTHrrrstrip)r lineno_widthmark_as_current offset_widthfields lineno_fmts r* _disassemblezInstruction._disassemble$s{  2+$|3  j4+;;<<<< cL0111  ! MM% MM%   MM$     MM$    d4;''--l;;<<< dk'' 66777 8  MM$tx....|<< = = =| 8 cDL036777xx&&(((r,N)rFrr)rXrr__doc__rr.r,r*rrs2  #)#)#)#)#)#)r,r) first_liner>r?c t|}tt|}| ||jz }nd}t t |||j|j|j||| |S)aIterator for the opcodes in methods, functions or code Generates a series of Instruction named tuples giving the details of each operations in the supplied code. If *first_line* is not None, it indicates the line number that should be reported for the first source line in the disassembled code. Otherwise, the source line information (if any) is taken directly from the disassembled code object. Nr) co_positionsr>) rdictrco_firstlineno_get_instructions_bytesr_varname_from_opargrrr)rYrr>r?r linestarts line_offsets r*rrJs !  BnR(())J 2#44  "?2x#@#@#%#9#%; #-{020A0A/:  < < <>>> F Z  s^F Mr,c`t|||}|turt|nd}||fS)aHelper to get optional details about const references Returns the dereferenced constant and its repr if the value can be calculated. Otherwise returns the sentinel value dis.UNKNOWN for the value and an empty string for its repr. r)rrr)rrrrrs r*_get_const_inforqs8b#y 1 1F$G33d6lllG 7?r,c 2| ||fi|}||fStdfS)a Helper to get optional details about named references Returns the dereferenced name as both value and repr if the name list is defined. Otherwise returns the sentinel value dis.UNKNOWN for the value and an empty string for its repr. Nr)r) name_indexget_name extrainfors r*_get_name_infor}s5*22 22v~{r,czt|}|dz}|dzr!|dz}t|}||dzz}|dz!|S)N?rv)next)iteratorbvals r* _parse_varintrsX XA b&C B$   NN qt  B$ Jr,c ft|j}g} t|dz}t|dz}||z}t|dz}t|}|dz }t|dz} |t ||||| #t $r|cYSwxYw)NTrqrp)iterco_exceptiontablerboolr|r StopIteration) coderentriesstartlengthendtargetdlr=lastis r*_parse_exception_tablersD*++HG  S!(++A-E"8,,Q.F&.C"8,,Q.Fx((B!GEAJJE NN/sFE5QQ R R R S sB B!! B0/B0c dt|vS)Nr")r)rs r*_is_backward_jumprs fRj ((r,r.c #HK|ptd}|dn|j} tt|} |D]0\} } } }}t | | D]}| | 1d}t |D] \}}|||d}|||z }|| v}d}d}tt|d}t|}}|tvrt||\}}n|tvrD|tkr$tdz| \}}dzr|rd|z}nRt| \}}n=|t vrdz}dt#|z}n|t$vr2t'|r n}|dz|dzz}dt#|z}n|t(vs |t*vrt|\}}n|t,vrt.}|}n|t0krkrt@\}}tCtD|||||||| VtF|}|s7|s$t |D]}t|d]tHtJ|&D]\}}t |D]}|dz }|d krA||kr;|||d|zz}|dtN(|tRj*}nd}tCdtVd d||ddtt|d V"dS)a&Iterate over the instructions in a bytecode string. Generates a sequence of Instruction namedtuples giving the details of each opcode. Additional information about the code's runtime environment (e.g. variable names, co_consts) can be specified using optional arguments. r.NrrqrpzNULL + zto rrrrzz with formatc32K|]\}}d|zz |VdS)rpNr.)r'rsrs r* z*_get_instructions_bytes..sG$5$5$!Q'*ad|$5A$5$5$5$5$5$5r,rz: r#F),r __getitem__setrr{add_unpack_opargsr~rrrrrhasnamer rhasjabsrhasjrelrhaslocalhasfree hascomparecmp_oprFORMAT_VALUE_CONVERTERSrrrrMAKE_FUNCTION_FLAGSr!rrrrrrrMint from_bytesr] byteorderr#)rvarname_from_opargrrrrexception_entriesrr>rlabelsrrr_rrrrrrrrdeop signed_argcachesr)sizedatars @r*rrs| +488L}tt%*;H D!! " "F$5 sFAquc""  A JJv     K)$//JJC  !$..66K&{* 6)tL"556 || ? Fx"1$Y"G"G;&&&4S!VX&F&FOFGa6W6"+g"5&4S(&C&COFGGQ$v,,.%6t%<%<EcTT# !jl2$v,,.!!TW__"06H"I"I## %%"9#)"D $sSy//2!9-(4},G&&))$5$5$5$5)N) rrrrUrrrrr)rrr<r>r?rrs r*r r snR(())J.r22r844b4{BL*4):$&OO$5$5; PPPPPPr,ct||||||dkrZ||dz }|jD]M}t|dr9t|td|d|t |||||LdSdS) NrArrprIrHzDisassembly of :r;)r rrKrPrR)rr<r=r>r?rYs r*rRrRs;JJJJ }  AIE  Aq)$$ 4    aaa1====&D;QY"   r,)r<rrrr>c t|} | rJt||z} | dkrtt | } nd} nd} t|dz }|dkrtt |}nd}t |||||||| |  D][}| o|jduo |jdk}|rt||j|k}t| | |||\|rZtd ||D]H}|j rd nd }|j dz }td |j d |d|j d|jd| |GdSdS)Nirrrqi'rrrrrr>rHzExceptionTable:z lastirrz to z -> z [])rmaxvalueslenrrrrrPrrrrrr=)rrrrrrr<rrrr> show_lineno maxlinenor maxoffsetrinstrnew_source_lineis_current_instrentryrs r*rUrUs z""K ))++,,{:   s9~~..LLLL D A IE3y>>**  (/A5)2J5@;L6B5@ BBB   ', ,D8, N)rRr:)r8kwargss r*rVrVFs(<88CCFCCCCCr,rurqrpc#JKd}d}tdt|dD]}}|r|dz} ||}t|}t|}|tkr9||dz|z}|t kr|dznd}|t kr |dt zz}nd}d}|||fV~dS)Nrrqrprs)r{r)rr HAVE_ARGUMENT EXTENDED_ARG _INT_OVERFLOW)r extended_argrrrrrs r*r r RsL F 1c$ii # #   aKF  !W||&t, = qs)l*C)-)=)=C1HH1L},,M 11 CL"cl'r,cg}t|D]X\}}}|P|tvrt|r| }|dz|dzz}n|tvr|dz}n?||vr||Y|S)z`Detect all offsets in a byte code which are jump targets. Return the list of offsets. Nrq)r r rr r|)rrrrrlabels r*rrjs F)$// % %C ?W}}$R(($C SU*wAF"" e$$$ Mr,c#dKd}|D]\}}}|||kr|}||fVdS)zqFind the offsets in a byte code which are start of lines in the source. Generate pairs (offset, lineno) N)co_lines)rlastlinerrlines r*rrsV H MMOOsD   0 0H+    Fr,c#Ktd}td}|j}|j}dt|jD}t |D]\}\}}||kr|dkr{||dz } ||dz } | dt vrV| dt vrGt| d| d|} t| d| d|} ||| | fVdS)zFind import statements in the code Generate triplets (name, level, fromlist) where name is the imported module and level, fromlist are the corresponding args to __import__. IMPORT_NAMErc4g|]\}}}|tk||fSr.)r5)r'rrrs r*r+z!_find_imports..s6)))JAr3<''3i'''r,rqrprN)opmaprrr rIrrr) rr?rconstsropargsrropargfrom_oplevel_oplevelfromlists r* _find_importsrIs &K|$J \F KE)).*D*D)))F#F++66;B   aQqSkGac{H h&&8A;(+B+B(!hqk6JJ+GAJ FKKU|UH555566r,c#Ktdtdh}|j}t|jD]\}}}||vr ||VdS)z\Find names of variables which are written in the code Generate sequence of strings STORE_NAME STORE_GLOBALN)rArr rI)r STORE_OPSrrrrs r*_find_store_namesrNsk l nI KE$RZ00 2s ??*   r,cZeZdZdZddddddZdZdZedddd Zd Z d Z dS) raThe bytecode operations of a piece of code Instantiate this with a function, method, other compiled object, string of code, or a code object (as returned by compile()). Iterating over this yields the bytecode operations as Instruction instances. NF)rcurrent_offsetr>r?c,t|x|_}||j|_d|_n||_||jz |_t t ||_||_||_ t||_ ||_ ||_ dS)Nr)rcodeobjrr _line_offsetrr _linestarts_original_objectrPrrr>r?)rrYrrPr>r?rs r*__init__zBytecode.__init__s,Q/// r   /DO !D  (DO *R-> >D r 2 233 !,!7!;!;&  r,c |j}tt||j|j|j|j|j|j|j | |j  S)Nr%) rRrrr?rrrrTrSrrr>)rrs r*__iter__zBytecode.__iter__sf \&r4='I'I')'='){BL'+'7373D9=9O46OO4E4E373CEEE Er,cLd|jj|jS)Nz{}({!r}))format __class__rXrUrs r*rzBytecode.__repr__s'  !8!%!688 8r,)r>r?ch|jr|j}|j||jj|j||S)z/ Construct a Bytecode from the given traceback )rPr>r?)rarbrcrd)clsrer>r?s r*from_tracebackzBytecode.from_tracebacksKj Bj s K r{ ^f    r,c*t|jS)z3Return formatted information about the code object.)rrRrs r*infoz Bytecode.infos ...r,cx|j}|j|j}nd}tj5}t t ||j|j|j|j |j |j |||j | |j |cdddS#1swxYwYdS)z3Return a formatted view of the bytecode operations.Nr ) rrrrrr<rrrr>)rRrPioStringIOrUrr?rrrrTrSrrr>getvalue)rrroutputs r*r z Bytecode.diss \   *(FFF []] %f r4=AA242H%'[BL*.*:+/+<$*%+151G,.OO,=,=+/+; = = = =??$$ % % % % % % % % % % % % % % % % % %sA6B//B36B3) rXrrrrVrXr classmethodr^r`r r.r,r*rrs)-Tu_d ! ! ! ! ! E E E888/4u    [ ///%%%%%r,rcpddl}|}|d|ddd|}|j5}|}dddn #1swxYwYt||jjd}t|dS) z*Simple test program to disassemble a file.rNinfilerb?-)rWnargsdefaultr5) argparseArgumentParser add_argumentFileType parse_argsrhreadr6r)r )rnparserargsrhr8rs r*_testrvsOOO  $ $ & &F x'8'8'>'>cSVWWW     D  64;+V 4 4DIIIIIs BBB__main__r)NNNNrr.NF)r )r NNNN)_rr]types collectionsrbrr _opcodes_allrrrrr MethodType FunctionTypeCodeTyperf staticmethodrWrOrArrrrrrrrr r!r"r#listrrrrr _empty_slotzipspec_opr1rMrr:r r r}rrrrrrr rr namedtuplerrrrrrrrrrrrrrrrrrrrrr rRrUrVr _INT_BITSr6r rrrIrNrrvrXr.r,r*rs@66   : : :B&c#b$(e&c&c&c&c&cPDDD   i!m$ 0*    666.    E%E%E%E%E%E%E%E%P    z EGGGGGr,