grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026U iÛfZPã @sdZddlZddlZddlZddlZddlTddlmZddddd d d d d ddg eZ[ejej ej e e e fZedZdedfedfedffZedZdZdd„ZdVdddœdd„ZdWddœdd„Zdddd d!d"d#d$d%d&d'œ Zd(d)„Zd*d+„Zd,d„Zd-d.„Zddœd/d „Ze  d0d1¡Z!d2e!j"_d3e!j_d4e!j#_d5e!j$_d6e!j%_d7e!j&_d8e!j'_d9e!j(_d:Z)d;Z*Gdd „Z,d?d@„Z-dAdB„Z.dXdCdD„Z/dYddœdFd„Z0dddœdGdH„Z1dZdddIœdJdK„Z2dLdM„Z3e0Z4dNdO„Z5dPd „Z6dQd „Z7GdRd„dƒZ8dSdT„Z9e:dUk�re9ƒdS)[z0Disassembler of Python byte code into mnemonics.éN)Ú*)Ú__all__Ú code_infoÚdisÚ disassembleÚdistbÚdiscoÚfindlinestartsÚ findlabelsÚ show_codeÚget_instructionsÚ InstructionÚBytecodeÚ FORMAT_VALUE)NÚÚstrÚreprÚasciiÚ MAKE_FUNCTION)ÚdefaultsZ kwdefaultsZ annotationsZclosurecCs6zt||dƒ}Wn tk r0t||dƒ}YnX|S)zßAttempts 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 ÚevalÚexec)ÚcompileÚ SyntaxError)ÚsourceÚnameÚc©rú(/opt/alt/python38/lib64/python3.8/dis.pyÚ _try_compiles r©ÚfileÚdepthc Csh|dkrt|d�dSt|dƒr&|j}t|dƒr8|j}n4t|dƒrJ|j}n"t|dƒr\|j}nt|dƒrl|j}t|dƒrüt|j  ¡ƒ}|D]p\}}t |t ƒrˆt d ||d�zt |||d �Wn0tk rì}zt d ||d�W5d}~XYnXt |d�qˆnht|d ƒ�rt|||d �nLt |ttfƒ�r6t||d�n.t |tƒ�rRt|||d �ntd t|ƒjƒ‚dS)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. N©r!Ú__func__Ú__code__Úgi_codeÚag_codeÚcr_codeÚ__dict__zDisassembly of %s:r zSorry:Úco_codeú(don't know how to disassemble %s objects)rÚhasattrr$r%r&r'r(Úsortedr)ÚitemsÚ isinstanceÚ _have_codeÚprintrÚ TypeErrorÚ_disassemble_recursiveÚbytesÚ bytearrayÚ_disassemble_bytesrÚ_disassemble_strÚtypeÚ__name__)Úxr!r"r.rZx1Úmsgrrrr+s@             ÿr#cCsX|dkr@z tj}Wntk r0tdƒd‚YnX|jr@|j}q2t|jj|j|d�dS)z2Disassemble a traceback (default: last traceback).Nz no last traceback to disassembler#) ÚsysÚlast_tracebackÚAttributeErrorÚ RuntimeErrorÚtb_nextrÚtb_frameÚf_codeÚtb_lasti)Útbr!rrrrXs Z OPTIMIZEDZ NEWLOCALSZVARARGSZ VARKEYWORDSZNESTEDZ GENERATORZNOFREEZ COROUTINEZITERABLE_COROUTINEZASYNC_GENERATOR) éééééé é@é€éicCs`g}tdƒD]:}d|>}||@r | t |t|ƒ¡¡||N}|s qVq | t|ƒ¡d |¡S)z+Return pretty representation of code flags.rJrEú, )ÚrangeÚappendÚCOMPILER_FLAG_NAMESÚgetÚhexÚjoin)ÚflagsÚnamesÚiÚflagrrrÚ pretty_flagsrs rYcCsŽt|dƒr|j}t|dƒr"|j}n4t|dƒr4|j}n"t|dƒrF|j}nt|dƒrV|j}t|tƒrjt|dƒ}t|dƒrx|St dt |ƒj ƒ‚d S) zDHelper to handle methods, compiled or raw code objects, and strings.r$r%r&r'r(z r*r+N) r,r$r%r&r'r(r/rrr2r8r9©r:rrrÚ_get_code_object€s"        ÿr[cCs tt|ƒƒS)z1Formatted details of methods, functions, or code.)Ú_format_code_infor[rZrrrr—scCs„g}| 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|j�rH| d¡t |jƒD]}| d |¡�q2|j�rz| d¡t |jƒD]}| 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:Ú )rPÚco_nameÚ co_filenameÚ co_argcountÚco_posonlyargcountÚco_kwonlyargcountÚ co_nlocalsÚ co_stacksizerYÚco_flagsÚ co_constsÚ enumerateÚco_namesÚ co_varnamesÚ co_freevarsÚ co_cellvarsrT)ÚcoÚlinesZi_cZi_nrrrr\›s<     r\cCstt|ƒ|d�dS)z}Print details of methods, functions, or code to *file*. If *file* is not provided, the output is printed on stdout. r#N)r1r)rlr!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 Falseééc@seZdZdZddd„ZdS) r aKDetails 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 éFrGcCsàg}|r:|jdk r,d|}| ||j¡n| d|¡|rJ| d¡n | d¡|jrf| d¡n | d¡| t|jƒ |¡¡| |j t¡¡|j dk rÒ| t|j ƒ t ¡¡|j rÒ| d|j d ¡d  |¡  ¡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>>z ú(ú))Ú starts_linerPÚis_jump_targetrÚoffsetÚrjustÚopnameÚljustÚ _OPNAME_WIDTHÚargÚ _OPARG_WIDTHÚargreprrTÚrstrip)ÚselfÚ lineno_widthZmark_as_currentÚ offset_widthZfieldsZ lineno_fmtrrrÚ _disassembleßs&      zInstruction._disassembleN)rqFrG)r9Ú __module__Ú __qualname__Ú__doc__rƒrrrrr Ñs )Ú first_linecCsTt|ƒ}|j|j}tt|ƒƒ}|dk r4||j}nd}t|j|j|j |j |||ƒS)a«Iterator 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) r[rkrjÚdictr Úco_firstlinenoÚ_get_instructions_bytesr*rirhrf)r:r‡rlÚ cell_namesÚ linestartsÚ line_offsetrrrr s    þcCs |}|dk r||}|t|ƒfS)zÕHelper to get optional details about const references Returns the dereferenced constant and its repr if the constant list is defined. Otherwise returns the constant index and its repr(). N©r)Z const_indexZ const_listÚargvalrrrÚ_get_const_infosr�cCs*|}|dk r||}|}nt|ƒ}||fS)zÓ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 name index and its repr(). NrŽ)Z name_indexZ name_listr�r~rrrÚ_get_name_info's r‘c #sŽt|ƒ}d}t|ƒD�]r\} } ‰|dk rD| | d¡}|dk rD||7}| |k} d} d} ˆdk �rlˆ} | tkrztˆ|ƒ\} } nò| tkr’tˆ|ƒ\} } nÚ| tkr´| dˆ} dt| ƒ} n¸| t krÌtˆ|ƒ\} } n | t krât ˆ} | } nŠ| t krútˆ|ƒ\} } nr| t k�rFtˆd@\} } | tˆd@ƒf} | d�rl| �r<| d7} | d 7} n&| tk�rld ‡fd d „ttƒDƒ¡} tt| | ˆ| | | || ƒVqdS) 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, constants) can be specified using optional arguments. NrrFzto rqrGrErNz with formatc3s"|]\}}ˆd|>@r|VqdS)rENr)Ú.0rWÚs©r|rrÚ gs ÿz*_get_instructions_bytes..)r Ú_unpack_opargsrRZhasconstr�Zhasnamer‘ÚhasjrelrZhaslocalZ hascompareZcmp_opZhasfreerÚFORMAT_VALUE_CONVERTERSÚboolrrTrgÚMAKE_FUNCTION_FLAGSr ry)ÚcodeÚvarnamesrVÚ constantsÚcellsrŒr�ÚlabelsrurwÚoprvr�r~rr”rrŠ7sV         þrŠéÿÿÿÿc Cs<|j|j}tt|ƒƒ}t|j||j|j|j|||d�dS)zDisassemble a code object.r#N) rkrjrˆr r6r*rirhrf)rlÚlastir!r‹rŒrrrrms  ÿcCspt||d�|dks|dkrl|dk r,|d}|jD]8}t|dƒr2t|d�td|f|d�t|||d�q2dS)Nr#rrEr*zDisassembly of %r:r )rrfr,r1r3)rlr!r"r:rrrr3ts    r3)r!r�c CsÈ|dk } | r8t| ¡ƒ|} | dkr2tt| ƒƒ} qN)r3r)rÚkwargsrrrr7�sr7ccsdd}tdt|ƒdƒD]J}||}|tkrN||d|B}|tkrH|d>nd}nd}|||fVqdS)NrrFrErH)rOr¦Z HAVE_ARGUMENTZ EXTENDED_ARG)r›Z extended_argrWr r|rrrr–£sr–cCs\g}t|ƒD]J\}}}|dk r |tkr4|d|}n|tkr |}nq ||kr | |¡q |S)z`Detect all offsets in a byte code which are jump targets. Return the list of offsets. NrF)r–r—ZhasjabsrP)r›rŸrwr r|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)z”Find the offsets in a byte code which are start of lines in the source. Generate pairs (offset, lineno) as described in Python/compile.c. rNrFrErLrM)Ú co_lnotabr¦r*r‰Úzip) r›Zbyte_incrementsZline_incrementsZ bytecode_lenZ lastlinenoÚlinenoZaddrZ byte_incrZ line_incrrrrr Ás&   c@sLeZdZdZdddœdd„Zdd„Zdd „Zed d „ƒZd d „Z dd„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. N)r‡Úcurrent_offsetcCsdt|ƒ|_}|dkr&|j|_d|_n||_||j|_|j|j|_tt |ƒƒ|_ ||_ ||_ dS)Nr) r[Úcodeobjr‰r‡Ú _line_offsetrkrjÚ _cell_namesrˆr Ú _linestartsÚ_original_objectr«)r€r:r‡r«rlrrrÚ__init__çs zBytecode.__init__c Cs*|j}t|j|j|j|j|j|j|jd�S)Nr£) r¬rŠr*rirhrfr®r¯r­)r€rlrrrÚ__iter__ôsýzBytecode.__iter__cCsd |jj|j¡S)Nz{}({!r}))ÚformatÚ __class__r9r°©r€rrrÚ__repr__ûs ÿzBytecode.__repr__cCs |jr|j}q||jj|jd�S)z/ Construct a Bytecode from the given traceback )r«)r@rArBrC)ÚclsrDrrrÚfrom_tracebackÿszBytecode.from_tracebackcCs t|jƒS)z3Return formatted information about the code object.)r\r¬rµrrrÚinfosz Bytecode.infoc Csl|j}|jdk r|j}nd}t ¡�>}t|j|j|j|j|j |j |j ||d� |  ¡W5QR£SQRXdS)z3Return a formatted view of the bytecode operations.Nr¡)rœrVr�ržrŒr�r!r¢) r¬r«ÚioÚStringIOr6r*rirhrfr®r¯r­Úgetvalue)r€rlrwÚoutputrrrr s   úz Bytecode.dis) r9r„r…r†r±r²r¶Ú classmethodr¸r¹rrrrrrßs  c Csfddl}| ¡}|jd| d¡ddd�| ¡}|j�}| ¡}W5QRXt||jjdƒ}t |ƒdS) z*Simple test program to disassemble a file.rNÚinfileÚrbú?ú-)r8ÚnargsÚdefaultr) ÚargparseÚArgumentParserÚ add_argumentZFileTypeÚ parse_argsr¿Úreadrrr)rÅÚparserÚargsr¿rr›rrrÚ_testsrÌÚ__main__)N)N)NNNNNr)r¡)r¡NNNNN);r†r<ÚtypesÚ collectionsrºZopcoderZ _opcodes_allÚ MethodTypeÚ FunctionTypeÚCodeTyper¾Ú staticmethodr8r0Zopmaprrrrr˜rršrrrrQrYr[rr\r Ú namedtuplernryr|r�r~rwrurvr{r}r r r�r‘rŠrr3r6r7rr–r r rrÌr9rrrrÚs´  þþ ÿü -ö  ÿ4 ÿ 6 ÿþ  =