Qfv dZddlZddlZddlZddlZddlddlmZmZm Z m Z m Z m Z m Z mZgdezZ[ejej ej"eeefZedZdedfed fed ffZed Zd Zed ZedZedZ edZ!edZ"edZ#edZ$edZ%edZ&edZ'edZ(edZ)e*e+Z,e-eZ.e/e,Dcgc]\}}|jads|c}}Z1e2e1eD]\Z3Z4e4e,e3<e3e.e4<e jjDcic]\}}|D]}||c}}}Z6dZ7deddddddZ8dedddddZ9d d!d"d#d$d%d&d'd(d)d* Z:d+Z;Gd,d-Z<e<Z=d.Z>d/Z?d0Z@d1ZAd2ZBdd3d4ZCejd5gd6dgd7z8ZEejd9gd:dg8ZFd;eFjV_deFj_d?eFj_d@eFj_dAeFj_dBeFj_dCeFj_ejdDdEZNdFZOdGZPGdHdIeFZQddddJdKZRdLZSdMZTdNZUdOZVdPZWdQZX dfdSZYdgdddddTZZddddddUZ[ dhdddRdddVdWZ\dXZ]eZZ^dYZ_dZe_d[z zZ`d\Zad]Zbd^Zcd_Zdd`ZeGdadbZfdcZgehddk(regyycc}}wcc}}}w)iz0Disassembler of Python byte code into mnemonics.N)*)__all__ _cache_format_inline_cache_entries_nb_ops_intrinsic_1_descs_intrinsic_2_descs_specializations_specialized_instructions) code_infodis disassembledistbdiscofindlinestarts findlabels show_codeget_instructions InstructionBytecode FORMAT_VALUE)Nstrreprascii MAKE_FUNCTION)defaults kwdefaults annotationsclosure LOAD_CONST RETURN_CONST LOAD_GLOBAL BINARY_OP JUMP_BACKWARDFOR_ITERSEND LOAD_ATTRLOAD_SUPER_ATTRCALL_INTRINSIC_1CALL_INTRINSIC_2CACHEr?r@rArBsortedrCitems isinstance _have_codeprintr TypeError_disassemble_recursivebytes bytearray_disassemble_bytesr_disassemble_strtype__name__) xr8r9r:r;rIr4x1msgs r5r r Msv y 4[8Dq* JJq* JJ I  II I  II I  IIq*qzz'')*HD""j)*T1=4U V^_4  I qt5k\de Ay) *14[A As U V^_BQ(()* *!4(Cd334s&F  F*F%%F*r=cX|a ttdrtjj}ntj}|jr|j}|jrt|jj|j|||y#t $r t ddwxYw)z2Disassemble a traceback (default: last traceback).Nlast_excz no last traceback to disassembler=) rGsysrY __traceback__last_tracebackAttributeError RuntimeErrortb_nextrtb_framef_codetb_lasti)tbr8r:r;s r5rrzs z MsJ'\\//''jjrzz"bjj ""BKKd ^fg MAB L Ms ;BB) OPTIMIZED NEWLOCALSVARARGS VARKEYWORDSNESTED GENERATORNOFREE COROUTINEITERABLE_COROUTINEASYNC_GENERATOR)  @ic g}tdD]D}d|z}||zs|jtj|t |||z}|rDn|jt |dj |S)z+Return pretty representation of code flags.rsrn, )rangeappendCOMPILER_FLAG_NAMESgethexjoin)flagsnamesiflags r5 pretty_flagsrss E 2Y!t 4< LL,00s4yA B TME   SZ 99U ceZdZdZy)_Unknowncy)Nz selfs r5__repr__z_Unknown.__repr__srN)rT __module__ __qualname__rrrr5rrsrrct|dr |j}t|dr |j}nJt|dr |j}n1t|dr |j}nt|dr |j }t |tr t|d}t|dr|Stdt|jz) zDHelper to handle methods, compiled or raw code objects, and strings.r>r?r@rArBz rErF) rGr>r?r@rArBrJrr6rMrSrTrUs r5_get_code_objectrsq* JJq* JJ I  II I  II I  II!S O ,q) >G$$% &&rcHt|}|tvrtt|S|SN) _all_opnamedeoptmap _all_opmap)opr4s r5_deoptoprs& r?D)-)9:htn %ArArc6|r |jS|jSr)_co_code_adaptiverE)cor;s r5_get_code_arrayrs#+2  ;;rc*tt|S)z1Formatted details of methods, functions, or code.)_format_code_inforrs r5r r s -a0 11rcg}|jd|jz|jd|jz|jd|jz|jd|jz|jd|j z|jd|j z|jd|jz|jdt|jz|jr?|jd t|jD]}|jd |z|jr?|jd t|jD]}|jd |z|jr?|jd t|jD]}|jd |z|jr?|jdt|jD]}|jd |z|jr?|jdt|jD]}|jd |zdj!|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: )rzco_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 r5rrs E LL(2::56 LL(2>>9: LL(2>>9: LL023H3HHI LL(2+?+??@ LL(2==89 LL(2??:; LL(< +DDE || \"R\\*C LLS )+ {{ XR[[)C LLS )* ~~ &'R^^,C LLS )- ~~ &'R^^,C LLS )- ~~ &'R^^,C LLS )- 99U rrDc0tt||y)z}Print details of methods, functions, or code to *file*. If *file* is not provided, the output is printed on stdout. rDN)rLr )rr8s r5rrs  )B-d#r Positions)lineno end_lineno col_offsetend_col_offsetrp)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 lasticeZdZdZddZy)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 cg}|rD|j$d|z}|j||jzn|jd|z|r|jdn|jd|jr|jdn|jd|jt|jj ||j|j jt|jd|jt|jj t|jr!|jd|jzdzdj|jS) 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 z%%%dd z-->z z>> ())rrzrrrrjustrljust _OPNAME_WIDTHr _OPARG_WIDTHrr~rstrip)r lineno_widthmark_as_current offset_widthfields lineno_fmts r5 _disassemblezInstruction._disassemble0s# +$|3  j4+;+;;< cL01  MM% MM%    MM$  MM$  d4;;'--l;< dkk'' 67 88  MM$txx...|< =|| cDLL0367xx&&((rN)Frp)rTrr__doc__rrrr5rr s  #)rr) first_liner:r;c t|}tt|}|||jz }nd}t t |||j |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. r) co_positionsr:) rdictrco_firstlineno_get_instructions_bytesr_varname_from_opargrrr)rUrr:r;r linestarts line_offsets r5rrVsv ! BnR()J 2#4#44  "?2x#@#%#9#9#%;; #-{020A/:  <z*_get_instructions_bytes..s($52P$!Q'*ad|%&2Psrz: r,F)2r __getitem__setrryadd_unpack_opargsr|rrrrhasconstrhasnamer#rr(r)hasjabsrhasjrelrhaslocalhasfree hascomparecmp_oprFORMAT_VALUE_CONVERTERSrrr~rMAKE_FUNCTION_FLAGSr$rr*rr+r rrrrrIint from_bytesrZ byteorderr,)rvarname_from_opargrrrrexception_entriesrr:rlabelsrrr_rrrrrrrrdeopcaches signed_argr4sizedatars @r5rrs +48L}t%*;*;H D! "F$5 sFAquc"A JJv #%6K)$/C  !$..6K&{* 6)tL"56 |&t, ? Fx"1$Y"G;&&4S!VX&FOFGaW"+g"5Y&&4S!VX&FOFGaW"07":_,&4S!VX&FOFGaW"07":&4S(&COFGQ$v,.%6t%U0sNNc tt|}t|}tt ||||j |j |j||||j| y)zDisassemble a code object.)r8rrr:N) rrrrQrrrrr)rrr8r:r;rrs r5rrsYnR()J.r2r84b44{{BLL*4):$&OO$5; Prct||||||dkDrS||dz }|jD]<}t|dst|td|d|t |||||>yy) Nr=rrnrErDzDisassembly of :r7)rrrGrLrN)rr8r9r:r;rUs r5rNrN)sp;J }  AIEAq)$4 a1=&D;QY "r)r8rrrr:c Dt|} | r9t|j|z} | dk\rtt | } nd} nd} t|dz }|dk\rtt |}nd}t |||||||| |  D]}| xr|j duxr|jdkD}|r t|| r|j|k(}nD|j|cxkxr/|jdtt|jzzknc}t|j| ||||rntd ||D][}|jrd nd }|jdz }td |jd |d|j d|j"d| |]yy)Nirrroi'rprrrr:rDzExceptionTable:z lastirrz to z -> z [])rmaxvalueslenrrrrrLrrrrrrrrr9)rrrrrrr8rrrr: show_lineno maxlinenor maxoffsetrinstrnew_source_lineis_current_instrentryrs r5rQrQ6s z"K ))+,{:  s9~.LL D A IE3y>*  (/A5)2J5@;L6B5@ B ', ,,D8, <N)rNr6)r3kwargss r5rRrRcs<8CFCrrsrornc#Kd}d}tdt|dD]g}|r|dz} ||}t|}t|}|tvr1||dz|z}|t k(r|dznd}|t k\r|dt zz}nd}d}|||fiyw)Nrrornrq)ryr*rrhasarg EXTENDED_ARG _INT_OVERFLOW)r extended_argrrrrrs r5r r osL F 1c$i #  aKF  !W|&t, 6>qs)l*C)-)=C1H1L},M 11 CL"cl'$sBBcg}t|D]l\}}}| t|}t|}|tvr"t |r| }|dz|dzz}|d|zz }n|t vr|dz}nW||vs\|j |n|S)z`Detect all offsets in a byte code which are jump targets. Return the list of offsets. ro)r rrrrrrz)rrrrrrrlabels r5rrs F)$/C ?B-> >D r 23 !,!7!;&  rc |j}tt||j|j|j |j |j|j|j|j|j S)Nr&) rRrrr;rrrrTrSrrr:)rrs r5__iter__zBytecode.__iter__sk \\&r4=='I')'='='){{BLL'+'7'7373D3D9=9O9O46OO4E373C3CE Ercbdj|jj|jS)Nz{}({!r}))format __class__rTrUrs r5rzBytecode.__repr__s*  !8!8!%!6!68 8r)r:r;c|jr|j}|jr||jj|j||S)z/ Construct a Bytecode from the given traceback )rPr:r;)r_r`rarb)clsrcr:r;s r5from_tracebackzBytecode.from_tracebacksBjjBjj KK  r{{ ^f  rc,t|jS)z3Return formatted information about the code object.)rrRrs r5infoz Bytecode.infos ..rc|j}|j |j}nd}tj5}t t ||j |j|j|j|j|j|||j|j|j |jcdddS#1swYyxYw)z3Return a formatted view of the bytecode operations.N) rrrrrr8rrrr:)rRrPioStringIOrQrr;rrrrTrSrrr:getvalue)rrroutputs r5r z Bytecode.diss \\    *((FF [[]f r4==A242H2H%'[[BLL*.*:*:+/+<+<$*%+151G1G,.OO,=+/+;+; =??$ % %]]s BCC) rTrrrrVrXr classmethodr^r`r rrr5rrsF)-Tu_d ! E8/4u  /%rrcNddl}|j}|jd|jddd|j }|j 5}|j }dddt|j jd}t|y#1swY6xYw)Nrinfilerb?-)rSnargsdefaultr0) argparseArgumentParser add_argumentFileType parse_argsrireadr1r4r )roparserargsrir3rs r5mainrws  $ $ &F x'8'8'>cSVW    D   64;;++V 4DI s BB$__main__r)NNNNrrNF)rb)rbNNNN)irrZtypes collectionsrcrr _opcodes_allrrrrr r r MethodType FunctionTypeCodeTyperg staticmethodrSrKrArrrrrrrr!r"r#r$r%r&r'r(r)r*r+r,listrrrrr startswith _empty_slotzipspec_op specializedrIrr6r rr{rrrrrrr rr namedtuplerrrrrrrrrrrrrrrrrrrrrrrNrQrRr _INT_BITSr7r rrrIrNrrwrT)slotr4basefamilyrs00000r5rs@6      :B+c#b$(e+cZD   i!m$ 00  6,  E%E%P  zF]V  s K)#K)K/