grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026 þ“qcÆCã@stdZddlZddlZddlZddlZddlTddlmZddddd d d d d ddg eZ[ejej ej e e e fZdd„Zddddd„Zddddd„Zdddddddddddd d!d"d#d$d%d&i Zd'd(„Zd)d*„Zd+d„Zd,d-„Zddd.d „Zejd/d0ƒZGd1d„deƒZd2dd3d „Zd4d5„Zd6d7„Zddddddd8d9„ZdHddd:d„ZdIdddddddd;dd<d=„Z ddd>d?„Z!eZ"d@dA„Z#dBd „Z$dCd „Z%GdDd„dƒZ&dEdF„Z'e(dGkrpe'ƒdS)Jz0Disassembler of Python byte code into mnemonics.éN)Ú*)Ú__all__Ú code_infoÚdisÚ disassembleÚdistbÚdiscoÚfindlinestartsÚ findlabelsÚ show_codeÚget_instructionsÚ InstructionÚBytecodec CsAyt||dƒ}Wn$tk r<t||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/python35/lib64/python3.5/dis.pyÚ _try_compiles  rÚfilecCs«|dkrtd|ƒdSt|dƒr5|j}t|dƒrM|j}t|dƒre|j}t|dƒr"t|jjƒƒ}x|D]‹\}}t|t ƒr�t d|d|ƒyt |d|ƒWn8t k r }zt d|d|ƒWYdd}~XnXt d|ƒq�Wn…t|d ƒrDt |d|ƒnct|ttfƒrlt|d|ƒn;t|tƒrŽt|d|ƒnt d t|ƒjƒ‚dS) zzDisassemble classes, methods, functions, generators, or code. With no argument, disassemble the last traceback. NrÚ__func__Ú__code__Úgi_codeÚ__dict__zDisassembly of %s:zSorry:Úco_codez(don't know how to disassemble %s objects)rÚhasattrrrrÚsortedrÚitemsÚ isinstanceÚ _have_codeÚprintrÚ TypeErrorrÚbytesÚ bytearrayÚ_disassemble_bytesÚstrÚ_disassemble_strÚtypeÚ__name__)Úxrr!rZx1Úmsgrrrr s6     &c Css|dkrSy tj}Wntk r9tdƒ‚YnXx|jrR|j}q=Wt|jj|jd|ƒ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)ÚtbrrrrrCs    éZ OPTIMIZEDéZ NEWLOCALSéZVARARGSéZ VARKEYWORDSéZNESTEDé Z GENERATORé@ZNOFREEé€Z COROUTINEéZITERABLE_COROUTINEcCs�g}xktdƒD]J}d|>}||@r|jtj|t|ƒƒƒ||N}|sPqW|jt|ƒƒdj|ƒS)z+Return pretty representation of code flags.r=r8z, )ÚrangeÚappendÚCOMPILER_FLAG_NAMESÚgetÚhexÚjoin)ÚflagsÚnamesÚiZflagrrrÚ pretty_flags\s   rJcCs–t|dƒr|j}t|dƒr0|j}t|dƒrH|j}t|tƒrft|dƒ}t|dƒry|Stdt|ƒj ƒ‚dS)zMHelper to handle methods, functions, generators, strings and raw code objectsrrrz rz(don't know how to disassemble %s objectsN) rrrrr"r)rr%r+r,)r-rrrÚ_get_code_objectjs   rKcCstt|ƒƒS)z1Formatted details of methods, functions, or code.)Ú_format_code_inforK)r-rrrryscCsêg}|jd|jƒ|jd|jƒ|jd|jƒ|jd|jƒ|jd|jƒ|jd|jƒ|jdt|jƒƒ|j rÙ|jdƒx(t |j ƒD]}|jd |ƒq¾W|j r|jd ƒx(t |j ƒD]}|jd |ƒqÿW|j r[|jd ƒx(t |j ƒD]}|jd |ƒq@W|j rœ|jd ƒx(t |j ƒD]}|jd |ƒq�W|jrÝ|jdƒx(t |jƒD]}|jd |ƒqÂWdj|ƒS)NzName: %szFilename: %szArgument count: %szKw-only arguments: %szNumber of locals: %szStack size: %szFlags: %sz Constants:z%4d: %rzNames:z%4d: %szVariable names:zFree variables:zCell variables:Ú )rBÚco_nameÚ co_filenameÚ co_argcountÚco_kwonlyargcountÚ co_nlocalsÚ co_stacksizerJÚco_flagsÚ co_constsÚ enumerateÚco_namesÚ co_varnamesÚ co_freevarsÚ co_cellvarsrF)ÚcoÚlinesZi_cZi_nrrrrL}s:          rLcCstt|ƒd|ƒdS)z}Print details of methods, functions, or code to *file*. If *file* is not provided, the output is printed on stdout. rN)r$r)r[rrrrr œsÚ _InstructionzBopname opcode arg argval argrepr offset starts_line is_jump_targetc@s(eZdZdZdddd„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 éFcCs0g}|rM|jdk r<d|}|j||jƒn|jd|ƒ|rc|jdƒn |jdƒ|jr‰|jdƒn |jdƒ|jt|jƒjdƒƒ|j|jjd ƒƒ|jdk r|jt|jƒjd ƒƒ|j r|jd |j d ƒdj |ƒj ƒS) zß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 Nz%%%ddú z-->z z>>z r:ééú(ú)) Ú starts_linerBÚis_jump_targetÚreprÚoffsetÚrjustÚopnameÚljustÚargÚargreprrFÚrstrip)ÚselfÚ lineno_widthZmark_as_currentZfieldsZ lineno_fmtrrrÚ _disassemble´s&     zInstruction._disassembleN)r,Ú __module__Ú __qualname__Ú__doc__rprrrrr ¦s Ú first_linecCsxt|ƒ}|j|j}tt|ƒƒ}|dk rJ||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) rKrZrYÚdictr Úco_firstlinenoÚ_get_instructions_bytesrrXrWrU)r-rtr[Ú 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)rf)Z const_indexZ const_listÚargvalrrrÚ_get_const_infoïs  r|cCs;|}|dk r%||}|}n t|ƒ}||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(). N)rf)Z name_indexZ name_listr{rlrrrÚ_get_name_infoûs     r}c cs¾t|ƒ}d}d} xŸt|ƒD]‘\} } } |dk rh|j| dƒ}|dk rh||7}| |k} d}d}| dk r’| }| tkr¶t| |ƒ\}}nÜ| tkrÚt| |ƒ\}}n¸| tkr| d| }dt|ƒ}n‹| t kr+t| |ƒ\}}ng| t krJt | }|}nH| t krnt| |ƒ\}}n$| t kr’d| d| df}tt| | | ||| || ƒVq%WdS)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. NÚr^zto z%d positional, %d keyword pairr@)r Ú_unpack_opargsrDZhasconstr|Zhasnamer}ÚhasjrelrfZhaslocalZ hascompareZcmp_opZhasfreeZhasnargsr ri)ÚcodeÚvarnamesrHÚ constantsÚcellsryrzÚlabelsrdZfreergÚoprkrer{rlrrrrw s@                 rwc CsT|j|j}tt|ƒƒ}t|j||j|j|j||d|ƒdS)zDisassemble a code object.rN) rZrYrur r(rrXrWrU)r[Úlastirrxryrrrr:srzc Cs°|dk } | rdnd} x‹t||||||d|ƒD]h} | og| jdk og| jdk} | r}td|ƒ| j|k} t| j| | ƒd|ƒq@WdS)Nr^rrzr)rwrdrgr$rp)r�r‡r‚rHrƒr„ryrrzZ show_linenoroZinstrZnew_source_lineZis_current_instrrrrr(As    r(cCstt|dƒd|ƒdS)zrN)rr)rrrrrr*Ssr*ccs­d}t|ƒ}d}xŽ||kr¨||}|}|d}d}|tkr—||||dd|}d}|d}|tkr—|d}|||fVqWdS)Nrr8r@r9i)ÚlenZ HAVE_ARGUMENTZ EXTENDED_ARG)r�Z extended_argÚnrIr†rgrkrrrrYs       rcCs�g}xƒt|ƒD]u\}}}|dk rd}|tkrQ|d|}n|tkrc|}|dkr||kr|j|ƒqW|S)z`Detect all offsets in a byte code which are jump targets. Return the list of offsets. Nr8r^réÿÿÿÿ)rr€ZhasjabsrB)r�r…rgr†rkZlabelrrrr ls     ccs¿t|jddd…ƒ}t|jddd…ƒ}d}|j}d}xTt||ƒD]C\}}|r–||krŒ||fV|}||7}||7}q]W||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. rNr9r8)ÚlistÚ co_lnotabrvÚzip)r�Zbyte_incrementsZline_incrementsZ lastlinenoÚlinenoZaddrZ byte_incrZ line_incrrrrr s     c@speZdZdZdddddd„Zdd„Zd d „Zed d „ƒZd d„Z dd„Z dS)rzñThe bytecode operations of a piece of code Instantiate this with a function, method, string of code, or a code object (as returned by compile()). Iterating over this yields the bytecode operations as Instruction instances. rtNÚcurrent_offsetcCsŽt|ƒ|_}|dkr7|j|_d|_n||_||j|_|j|j|_tt |ƒƒ|_ ||_ ||_ dS)Nr) rKÚcodeobjrvrtÚ _line_offsetrZrYÚ _cell_namesrur Ú _linestartsÚ_original_objectr�)rnr-rtr�r[rrrÚ__init__�s     zBytecode.__init__c Cs=|j}t|j|j|j|j|j|jd|jƒS)Nrz) r�rwrrXrWrUr’r“r‘)rnr[rrrÚ__iter__ªs    zBytecode.__iter__cCsdj|jj|jƒS)Nz{}({!r}))ÚformatÚ __class__r,r”)rnrrrÚ__repr__±szBytecode.__repr__cCs2x|jr|j}qW||jjd|jƒS)z/ Construct a Bytecode from the given traceback r�)r3r4r5r6)Úclsr7rrrÚfrom_tracebackµs  zBytecode.from_tracebackcCs t|jƒS)z3Return formatted information about the code object.)rLr�)rnrrrÚinfo¼sz Bytecode.infocCs�|j}|jdk r$|j}nd }tjƒ�`}t|jd|jd|jd|jd|j d|j d|j d |d |ƒ|j ƒSWdQRXdS) z3Return a formatted view of the bytecode operations.Nr8r‚rHrƒr„ryrzrr‡rŠ) r�r�ÚioÚStringIOr(rrXrWrUr’r“r‘Úgetvalue)rnr[rgÚoutputrrrrÀs     z Bytecode.dis) r,rqrrrsr•r–r™Ú classmethodr›rœrrrrrr•s    c CsŽddl}|jƒ}|jdd|jƒddddƒ|jƒ}|j�}|jƒ}WdQRXt||jjd ƒ}t |ƒdS) z*Simple test program to disassemble a file.rNÚinfiler+Únargsú?Údefaultú-r) ÚargparseÚArgumentParserÚ add_argumentZFileTypeÚ parse_argsr¢Úreadrrr)r§ÚparserÚargsr¢rr�rrrÚ_testÒs  %  r®Ú__main__rŠrŠ))rsr/ÚtypesÚ collectionsr�ZopcoderZ _opcodes_allÚ MethodTypeÚ FunctionTypeÚCodeTyper¡Ú staticmethodr+r#rrrrCrJrKrrLr Ú namedtupler]r r r|r}rwrr(r*rrr r rr®r,rrrrÚsd       #       3  .     =