
    >gjj                   L   S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKJ	r	  S SK
JrJrJr  \R                  R                  S S5        S SKJr  S SKJr  S SKJr  S S	KJr  S S
KJr  S SKJr  S SKJr  S SKJrJ r J!r!  S SK"J#r#J$r$J%r%  S SK&J'r'  S SK(J)r)J*r*J+r+J,r,J-r-J.r.J/r/J0r0J1r1J2r2J3r3J4r4J5r5J6r6J7r7J8r8J9r9J:r:J;r;J<r<J=r=J>r>J?r?J@r@  S SKAJBrB  S SKAJCrC  S SKAJDrD  S SKAJErE  S SKFJGrGJHrHJIrIJJrJJKrKJLrLJMrM  S SKNJOrOJPrPJQrQ  S SKRJSrSJTrTJUrUJVrWJXrX  S SKYJZrZJVr[J\r\  S SK]J^r^J_r_J`r`  S SKaJbrbJcrcJdrd  S SKeJfrf  \(       a.  S SKgJhrh  S SKiJjrj  S SKkJlrl  S SKJmrm   " S  S!\5      rn " S" S#\5      roS.S$ jrp\R                  " S%5      rrS/S& jrs " S' S(5      rtS)ruS*\-  rvS0S1S+ jjrwS2S, jrx\yS-:X  a  \w" 5         gg)3    )annotationsN)cached_property)IOTYPE_CHECKING	TypedDict.)__version__)ELFError)	bytes2str)ELFFile)DynamicSection)
ENUM_D_TAG)InterpSegment)NoteSectionSymbolTableSectionSymbolTableIndexSection)GNUVerSymSectionGNUVerDefSectionGNUVerNeedSection)RelocationSection)describe_ei_classdescribe_ei_datadescribe_ei_versiondescribe_ei_osabidescribe_e_typedescribe_e_machinedescribe_e_version_numericdescribe_p_typedescribe_p_flagsdescribe_rh_flagsdescribe_sh_typedescribe_sh_flagsdescribe_symbol_typedescribe_symbol_binddescribe_symbol_shndxdescribe_reloc_typedescribe_dyn_tagdescribe_dt_flagsdescribe_dt_flags_1describe_ver_flagsdescribe_notedescribe_attr_tag_armdescribe_attr_tag_riscvdescribe_symbol_other)E_FLAGS)E_FLAGS_MASKS)SH_FLAGS)SHN_INDICES)describe_reg_namedescribe_attr_valueset_global_machine_archdescribe_CFI_instructionsdescribe_CFI_register_ruledescribe_CFI_CFA_ruledescribe_DWARF_expr)DW_LNS_copyDW_LNS_set_fileDW_LNE_define_file)LocationParserLocationEntryLocationViewPairBaseAddressEntryLocationListsPair)
RangeEntryr@   RangeListsPair)CIEFDEZERO)CorruptEHABIEntryCannotUnwindEHABIEntryGenericEHABIEntry)
ENUM_DW_UT)	Container)CompileUnit)	DWARFInfo)Sectionc                  >    \ rS rSr% S\S'   S\S'   S\S'   S\S	'   S
rg)VersionInfoI   zGNUVerSymSection | NoneversymzGNUVerDefSection | NoneverdefzGNUVerNeedSection | Noneverneed
str | Nonetype N__name__
__module____qualname____firstlineno____annotations____static_attributes__rW       e/home/sebas/work/tasks/T-ballbox-rebrand-v3/venv/lib/python3.13/site-packages/../../../bin/readelf.pyrP   rP   I   s    ''''))r_   rP   c                  >    \ rS rSr% S\S'   S\S'   S\S'   S\S'   S	rg
)SymbolVersionO   zstr | int | NoneindexrU   namefilenamezbool | NonehiddenrW   NrX   rW   r_   r`   rb   rb   O   s    r_   rb   c                $   U R                  5       nUR                  nSU;   a  US   R                  $ SU;   a  US   R                  $ SU;   a  U R                  R	                  5       R                  US   R                  U 5      nS nU Hk  n[        U[        5      (       a  UR                  nO5[        U[        5      (       a  UR                  (       a  UR                  nOS nUc  M_  Ub  Xd:  d  Mi  UnMm     Uc  [        S5      eU$ [        S5      e)NDW_AT_low_pcDW_AT_entry_pcDW_AT_rangesz(Can't find the base IP (low_pc) for a CU)get_top_DIE
attributesvalue	dwarfinforange_listsget_range_list_at_offset
isinstanceRangeBaseAddressEntrybase_addressrB   is_absolutebegin_offset
ValueError)cutop_dieattrrlbase_iprips          r`   _get_cu_baser   V   s    nnGDN#)))	T	!$%+++	4	 \\%%'@@nAUA[A[]_`A!233^^Az**q}}^^~7?bl  ?GHHCDDr_   z[\x01-\x1f]c                0    [         R                  S U 5      $ )Nc                <    S[        S[        U S   5      -   5      -   $ )N^@   r   )chrord)matchs    r`   <lambda>%_format_symbol_name.<locals>.<lambda>w   s    cCs58}8L4M.Mr_   )_CONTROL_CHAR_REsub)ss    r`   _format_symbol_namer   v   s     MqQQr_   c                  b   \ rS rSrSrS3S jrS4S jrS5S jrS6S7S jjrS6S7S jjr	S4S jr
S4S	 jrS4S
 jrS4S jrS4S jrS4S jrS4S jrS8S jrS8S jrS9S jr    S:           S;S jjr  S<       S=S jjr\S>S j5       rS?S jrS@S jrS r\SAS j5       rSBS jr\SCS j5       rS4S jrS4S jrS4S jr S4S jr!S4S  jr"SDS! jr#S4S" jr$S4S# jr%S4S$ jr&S4S% jr'SES& jr(SFS' jr)SGS( jr*S4S) jr+SHS* jr,SES+ jr-              SIS, jr.S4S- jr/S4S. jr0S4S/ jr1SJSKS0 jjr2SJSKS1 jjr3S2r4g)LReadElfy   zEdisplay_* methods are used to emit output into the output stream
    c                0    [        U5      U l        X l        g)zYfile:
    stream object with the ELF file to read

output:
    output stream to write to
N)r   elffileoutput)selffiler   s      r`   __init__ReadElf.__init__|   s     t}r_   c                   U R                  S5        U R                  S5        U R                  SR                  S U R                  R                   5       5      5        U R                  S5        U R                  R
                  nUS   nU R                  S[        US   5      -  5        U R                  S	[        US
   5      -  5        U R                  S[        US   5      -  5        U R                  S[        US   5      -  5        U R                  SUS   -  5        U R                  S[        US   U R                  5      -  5        U R                  S[        US   5      -  5        U R                  S[        US   5      -  5        U R                  SU R                  US   5      -  5        U R                  SUS   -  5        U R                  S5        U R                  SUS   -  5        U R                  S5        U R                  SU R                  US   5      < U R                  US   5      < 35        U R                  SUS    -  5        U R                  S!US"   -  5        U R                  S#US$   -  5        U R                  S%US&   -  5        U R                  S'US(   -  5        US(   S):X  aK  U R                  R                  5       S):w  a-  U R                  S*U R                  R                  5       -  5        OU R                  S+5        U R                  S,US-   -  5        US-   [         R"                  :X  a-  U R                  S*U R                  R%                  5       -  5        g.U R                  S+5        g.)/z$Display the ELF file header
        zELF Header:z  Magic:    c              3  ,   #    U  H
  nS U-  v   M     g7f)%2.2xNrW   ).0bs     r`   	<genexpr>.ReadElf.display_file_header.<locals>.<genexpr>   s      64q $aK4         e_identz'  Class:                             %sEI_CLASSz'  Data:                              %sEI_DATAz'  Version:                           %s
EI_VERSIONz'  OS/ABI:                            %sEI_OSABIz'  ABI Version:                       %dEI_ABIVERSIONz'  Type:                              %se_typez'  Machine:                           %s	e_machine	e_versionz'  Entry point address:               %se_entryz'  Start of program headers:          %se_phoffz (bytes into file)z'  Start of section headers:          %se_shoffz%  Flags:                             e_flagsz/  Size of this header:               %s (bytes)e_ehsizez/  Size of program headers:           %s (bytes)e_phentsizez'  Number of program headers:         %se_phnumz/  Size of section headers:           %s (bytes)e_shentsizez'  Number of section headers:         %se_shnumr   z (%d) z'  Section header string table index: %s
e_shstrndxN)	_emitline_emitjoinr   e_ident_rawheaderr   r   r   r   r   r   r   _format_hexdecode_flagsnum_sectionsr2   
SHN_XINDEXget_shstrndx)r   r   r   s      r`   display_file_headerReadElf.display_file_header   s^    	}%

=!

388 6 LL446 6 	7x $$#@!'*"567 	8@ !345 	6@#GL$9:; 	<@!'*"567 	8@() 	*@x 0$,,?@ 	A@"6+#678 	9@*6++>?@ 	A@  	!234 	5

<y!" 	#+,

<y!" 	#+,!!&"34!!&"346 	7 	Hz"# 	$H}%& 	'@y!" 	#H}%& 	'

<y!" 	#)!dll&?&?&AQ&FNN7T\\%>%>%@@ANN2

<|$% 	&,;#9#99NN7T\\%>%>%@@ANN2r_   c                @   SnU R                   S   S:X  GaC  U[        R                  -  nU[        R                  ) -  nU[        R                  -  (       a  US-  nU[        R                  ) -  nU[        R                  :X  a  [        R
                  [        R                  -  [        R                  -  [        R                  -  nUS-  nU[        R
                  -  (       a  US-  nOU[        R                  -  (       a  US-  nU[        R                  -  (       a  US-  nOU[        R                  -  (       a  US	-  nX) -  (       a  US
-  nU$ US-  n U$ U R                   S   S:X  a  U[        R                  -  (       a  US-  nU$ U R                   S   S:X  Ga  U[        R                  -  (       a  US-  nU[        R                  -  (       a  US-  nU[        R                  -  (       a  US-  nU[        R                  -  (       a  US-  nU[        R                  -  (       a  US-  nU[        R                   -  (       a  US-  nOYU[        R"                  -  (       a  US-  nO;U[        R$                  -  (       a  US-  nOU[        R&                  -  (       a  US-  nU[        R(                  -  [        R*                  :X  a  US-  nU[        R(                  -  [        R,                  :X  a  US-  nU[        R(                  -  [        R.                  :X  a  US-  nU[        R(                  -  [        R0                  :X  a  US-  nU[        R(                  -  [        R2                  :X  a  US-  nU[        R(                  -  [        R4                  :X  a  US-  nU[        R(                  -  [        R6                  :X  a  US-  nU[        R(                  -  [        R8                  :X  a  US-  nU[        R(                  -  [        R:                  :X  a  US -  nU$ U R                   S   S!:X  Ga  U[        R<                  -  (       a  US"-  nU[        R>                  -  (       a  US#-  nU[        R@                  -  (       a  US$-  nU[        RB                  -  [        RD                  :X  a  US-  nU[        RB                  -  [        RF                  :X  a  US%-  nU[        RB                  -  [        RH                  :X  a  US&-  nU[        RB                  -  [        RJ                  :X  a  US'-  nU$ U R                   S   S(:X  a  U[        RL                  -  [        RN                  :X  a  US)-  nU[        RL                  -  [        RP                  :X  a  US*-  nU[        RL                  -  [        RR                  :X  a  US+-  nU[        RT                  -  [        RV                  :X  a  US,-  nU[        RT                  -  [        RX                  :X  a  US--  nU$ ).Nr   r   EM_ARMz, relocatable executablz, Version5 EABIz, soft-float ABIz, hard-float ABIz, BE8z, LE8z, <unknown>z, <unrecognized EABI>EM_PPC64z, abiv2EM_MIPSz, noreorderz, picz, cpicz, abi2z, 32bitmodez, o32z, o64z, eabi32z, eabi64z, mips1z, mips2z, mips3z, mips4z, mips5z
, mips32r2z
, mips64r2z, mips32z, mips64EM_RISCVz, RVCz, RVEz, TSOz, single-float ABIz, double-float ABIz, quad-float ABIEM_LOONGARCHz, SOFT-FLOATz, SINGLE-FLOATz, DOUBLE-FLOATz, OBJ-v0z, OBJ-v1)-r   r/   EF_ARM_EABIMASKEF_ARM_RELEXECEF_ARM_EABI_VER5EF_ARM_ABI_FLOAT_SOFTEF_ARM_ABI_FLOAT_HARD
EF_ARM_LE8
EF_ARM_BE8EF_PPC64_ABI_V2EF_MIPS_NOREORDEREF_MIPS_PICEF_MIPS_CPICEF_MIPS_ABI2EF_MIPS_32BITMODEr0   EFM_MIPS_ABI_O32EFM_MIPS_ABI_O64EFM_MIPS_ABI_EABI32EFM_MIPS_ABI_EABI64EF_MIPS_ARCHEF_MIPS_ARCH_1EF_MIPS_ARCH_2EF_MIPS_ARCH_3EF_MIPS_ARCH_4EF_MIPS_ARCH_5EF_MIPS_ARCH_32R2EF_MIPS_ARCH_64R2EF_MIPS_ARCH_32EF_MIPS_ARCH_64EF_RISCV_RVCEF_RISCV_RVEEF_RISCV_TSOEF_RISCV_FLOAT_ABIEF_RISCV_FLOAT_ABI_SOFTEF_RISCV_FLOAT_ABI_SINGLEEF_RISCV_FLOAT_ABI_DOUBLEEF_RISCV_FLOAT_ABI_QUADEF_LOONGARCH_ABI_MODIFIER_MASKEF_LOONGARCH_ABI_SOFT_FLOATEF_LOONGARCH_ABI_SINGLE_FLOATEF_LOONGARCH_ABI_DOUBLE_FLOATEF_LOONGARCH_OBJABI_MASKEF_LOONGARCH_OBJABI_V0EF_LOONGARCH_OBJABI_V1)r   flagsdescriptioneabiEF_ARM_KNOWN_FLAGSs        r`   r   ReadElf.decode_flags   sp   <<$07222Dg----Ew---88'0000w///%,%B%B7C`C`%`ahasas%st{  uG  uG  &G"007888#55KW:::#55K7---7*KW///7*K..=0KT Q 66P M \\+&*4w...y(H E \\+&)3w000},w***w&w+++x',,,x'111},666w&-888w&-;;;z)-;;;z),,,1G1GGy(,,,1G1GGy(,,,1G1GGy(,,,1G1GGy(,,,1G1GGy(,,,1J1JJ|+,,,1J1JJ|+,,,1H1HHz),,,1H1HHz)< 9 \\+&*4w+++w&,,,w&,,,w&222w7V7VV11222w7X7XX33222w7X7XX33222w7V7VV11  \\+&.8>>>7CfCff~->>>7ChChh//>>>7ChChh//888W=[=[[z)888W=[=[[z)r_   c                   U R                  5         U R                  R                  5       S:X  a  U R                  S5        gU R                  R                  nU(       a  U R                  S[	        US   U R                  5      -  5        U R                  SU R                  US   5      -  5        U R                  SU R                  R                  5       < S	US
   < 35        U R                  5         U R                  S5        U R                  R                  S:X  a  U R                  S5        O"U R                  S5        U R                  S5        U R                  R                  5        GH  nU R                  S[        US   5      -  5        U R                  R                  S:X  a  U R                  U R                  US   SS9< SU R                  US   SS9< SU R                  US   SS9< SU R                  US   SS9< SU R                  US   SS9< S[        US   5      <S SU R                  US   5      < 35        OU R                  U R                  US   SS9< SU R                  US   SS9< SU R                  US   SS9< 35        U R                  S U R                  US   SS9< SU R                  US   SS9< S![        US   5      <S S"U R                  US   S#S$9< 35        [        U[        5      (       d  GM  U R                  S%UR                  5       -  5        GM     U R                  R                  5       S:X  a  gU R                  S&5        U R                  S'5        [        U R                  R                  5       5       H  u  pCU R                  S(U-  5        U R                  R!                  5        H~  nUR#                  5       (       a  M  US)   [$        R&                  -  S:w  a  US*   S+:X  a  US   S,:w  a  MH  UR)                  U5      (       d  M`  U R                  S-UR*                  -  5        M     U R                  S.5        M     g)/zzDisplay the ELF program headers.
If show_heading is True, displays the heading for this information
(Elf file type is...)
r   z*There are no program headers in this file.NzElf file type is %sr   zEntry point is %sr   
There are z% program headers, starting at offset r   zProgram Headers:    zI  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Alignz?  Type           Offset             VirtAddr           PhysAddrzD                 FileSiz            MemSiz              Flags  Alignz  %-14s p_typep_offset   	fieldsizer   p_vaddrT)fullhexp_paddrp_filesz   p_memszp_flags3p_alignz                       Flead0xz*      [Requesting program interpreter: %s]z
 Section to Segment mapping:z  Segment Sections...z   %2.2d     sh_flagssh_type
SHT_NOBITSPT_TLSz%s r   )r   r   num_segmentsr   r   r   elfclassiter_segmentsr   r   r   rr   r   get_interp_namer   	enumerateiter_sectionsis_nullr1   SHF_TLSsection_in_segmentre   )r   show_heading	elfheadersegmentnsegsections         r`   display_program_headersReadElf.display_program_headers$  s   
 	<<$$&!+NNGHLL''	NN0	( 3T\\BC DNN.  9!567 8 NN))+Yy-AC DNN)* <<  B&NNfgNN\]NNab ||113GJJzOGH4E$FFG||$$*$$WZ%8A$F$$WY%7$F$$WY%7$F$$WZ%8A$F$$WY%71$E$WY%78$$WY%78 : ; $$WZ%8$$G$$WY%7$F$$WY%7$F H I $$WZ%8$$G$$WY%7$F$WY%78 $$WY%7$F H I '=11K++- . /5 4> <<$$&!+78./&t||'A'A'CDMDJJ-.<<557#OO--%j1H4D4DDJ$Y/<?$X.(:227;;JJuw||34 8 NN2 Er_   c                z   U R                   R                  nU(       a.  U R                  SUS   < SU R                  US   5      < 35        U R                   R	                  5       S:X  a  U R                  S5        gU R                  SU R                   R	                  5       S	:  a  S
OS-  5        U R                   R
                  S:X  a  U R                  S5        O"U R                  S5        U R                  S5        [        U R                   R                  5       5       GH  u  p4U R                  SX4R                  [        US   5      4-  5        U R                   R
                  S:X  a  U R                  U R                  US   SSS9< SU R                  US   SSS9< SU R                  US   SSS9< SU R                  US   SSS9< S[        US   5      <S SUS   <S SUS    <S SUS!   <S 35        M  U R                  SU R                  US   S"SS#9< S$U R                  US   US   S%:  a  S&OSSS9< 35        U R                  S'U R                  US   S"SS#9< S$U R                  US   S"SS#9< S[        US   5      <S S(US   <S S)US    <S S*US!   < 35        GM     U R                  S+5        U R                  S,5        U R                  S-5        U R                  S.5        U R                  S$5        U R                   S/   S0:X  a  U R                  S15        U R                  S25        g)3z(Display the ELF section headers
        r   r   z% section headers, starting at offset r   r   z#There are no sections in this file.Nz
Section Header%s:   r   r   r   zP  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf AlzB  [Nr] Name              Type             Address           OffsetzB       Size              EntSize          Flags  Link  Info  Alignz  [%2u] %-17.17s %-15.15s r  sh_addr   Fr   r
  r   	sh_offsetr   sh_size
sh_entsize   r  z>3sh_linkz>2sh_infosh_addralignTr   r
  r  l       z       r      z     zKey to Flags:zF  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),zG  L (link order), O (extra OS processing required), G (group), T (TLS),z<  C (compressed), x (unknown), o (OS specific), E (exclude),r   r   zy (purecode), zp (processor specific))r   r   r   r   r   r  r  r  r   re   r!   r"   )r   r  r  nsecr  s        r`   display_section_headersReadElf.display_section_headers}  s    LL''	NN)$d&6&6y7K&LN O <<$$&!+NN@A,<<,,.2C< 	=
 <<  B&NNmnNN_`NN_` 't||'A'A'CDMDJJ3ll$4WY5G$H7J J K ||$$*$$WY%71U$S$$W[%9Qu$U$$WY%71U$S$$W\%:aPU$V%gj&9:I&	(:N+ - . $$WY%7e$T$$W[%9(/(<z(I"q$ % & ' (
 $$WY%7e$T$$W\%:DQV$W%gj&9:I&	(:N+ - .' E4 	' 1 	2 . 	/ ' 	(

4<<$0JJ'(/0r_   c                   [        U R                  R                  5       5       VVs/ s H  u  p[        U[        5      (       d  M  X4PM!     nnnU(       d@  U R                  R                  5       S:X  a"  U R                  S5        U R                  S5        U GHh  u  pE[        U[        5      (       d  M  US   S:X  a   U R                  SUR                  -  5        MF  U R                  SUR                  UR                  5       UR                  5       S:X  a  SOS	4-  5        U R                  R                  S
:X  a  U R                  S5        OU R                  S5        [        UR                  5       5       GH  u  pgSnUS   S:X  ae  U R                  S   S:X  aR  U R                  U5      n	U	S   UR                  :w  a.  U	S   S;  a%  U	S   (       a  SU	-  nOU	S   (       a  SU	-  nOSU	-  nUR                  n
US   S   S:X  a[  US   S:w  aR  US   U R                  R                  5       :  a1  US   S:X  a(  U R                  R                  US   5      R                  n
U R                  SUU R                  US   S S!S"9US#   S$:  a  S%US#   -  O[        US#   5      [!        US   S   5      [#        US   S&   5      [%        US'   5      ['        U R)                  UUU5      5      [+        U
5      U4	-  5        GM     GMk     g(s  snnf ))z8Display the symbol tables contained in the file
        r   r   zCDynamic symbol information is not available for displaying symbols.r&  z,
Symbol table '%s' has a sh_entsize of zero!z"
Symbol table '%s' contains %d %s:r   entryentriesr   z7   Num:    Value  Size Type    Bind   Vis      Ndx Namez?   Num:    Value          Size Type    Bind   Vis      Ndx Namer  
SHT_DYNSYMrV   GNUre   rd   VER_NDX_LOCALVER_NDX_GLOBALrf   z@%(name)s (%(index)i)rg   z	@%(name)sz
@@%(name)sst_infoSTT_SECTIONst_shndx	SHN_UNDEFst_namez%%6d: %s %s %-7s %-6s %-7s %4s %.25s%sst_valueTFr+  st_sizei z%5dbindst_otherN)r  r   r  rr   r   r   r   re   num_symbolsr  iter_symbols_versioninfo_symbol_versionget_sectionr   hexr#   r$   r.   r%   _get_symbol_shndxr   )r   idxr   symbol_tablessection_indexr  nsymsymbolversion_infoversionsymbol_names              r`   display_symbol_tablesReadElf.display_symbol_tables  s    1:$,,:T:T:V0W ?0Wfc&q*<= "#0W ? !:!:!<!ANN2NN 2 3 '4"Mg'9::|$)NLL " #NN@##%"..0A59DF F G
 ||$$*XY`a )'*>*>*@ A!I&,6))&1U:"2248G6;;6( 1C C":.+BW+LL  'x0/:W/D/;g/E$kk9%f->z*k9z*T\\-F-F-HHy)Q."&,,":":6*;M"N"S"SK F$$z*D % H17	1BV1KEF9--QTU[\eUfQg(	):6)BC(	):6)BC)&*<=)$*@*@AEAN+P Q (4 J"  " #9 !B' '4?s   LLc                   SnU R                   R                  5        GH  n[        U[        5      (       d  M  SnU R	                  SU R                  US   5      UR                  5       UR                  5       S:X  a  SOS4-  5        U R	                  S5        S	U R                   R                  S
:X  a  SOS-   nUR                  5        GH  nUR                  R                  S:X  a  SUR                  -  nGOTUR                  R                  S:X  a  SUR                  -  nGO)UR                  R                  S:X  a  SUR                  -  nGOUR                  R                  S:X  a  SUR                  -  nGOUR                  R                  R                  S5      (       a
  SUS   -  nGOUR                  R                  S:X  a!  [!        UR                  R"                  5      nGOdUR                  R                  S:X  a$  S[%        UR                  R"                  5      -  nGO&UR                  R                  R                  S5      (       a	  SUS   -  nOUR                  R                  S:X  a@  ['        UR                  R"                  5      nUR)                  S5      (       a  USS  nS!U-  nOUR                  R                  S":X  a   [+        UR                  R"                  5      nO_UR                  R                  S#;   a   [-        UR                  R"                  5      nO%UR                  R                  S$:X  a  S%nOS&US   -  nU R	                  S'U R                  [.        R0                  " UR                  R                  UR                  R                  5      SSS(9US)UR                  R                  SS  < S*3U4-  5        GM     GM     U(       d  U R	                  S+5        g g ),z7Display the dynamic tags contained in the file
        FTz-
Dynamic section at offset %s contains %d %s:r$  r   r2  r3  z4  Tag        Type                         Name/Value   r   r"  r   	DT_NEEDEDzShared library: [%s]DT_RPATHzLibrary rpath: [%s]
DT_RUNPATHzLibrary runpath: [%s]	DT_SONAMEzLibrary soname: [%s])SZENTz
%i (bytes)d_valDT_FLAGS
DT_FLAGS_1z	Flags: %s)NUMCOUNTz%i	DT_PLTRELDT_   Nz%sDT_MIPS_FLAGS)DT_MIPS_SYMTABNODT_MIPS_LOCAL_GOTNODT_AARCH64_BTI_PLTr   z%#xz %s %-*s %sr+  ()z*
There is no dynamic section in this file.)r   r  rr   r   r   r   num_tagsr  	iter_tagsr2  d_tagneededrpathrunpathsonameendswithr(   r[  r)   r'   
startswithr    strr   get)r   has_dynamic_sectionsr  paddingtagparsedr   s          r`   display_dynamic_tagsReadElf.display_dynamic_tags  s     %||113Gg~66#' NNK  !56  ""++-2	OC C D NNQR!6!6"!<A!DG((*99??k13cjj@FYY__
22SYY>FYY__44s{{BFYY__33cjj@FYY__--m<<)CL8FYY__
2.syy?FYY__4(+>syy+OOFYY__--.>??!CL0FYY__3(9A||E**abE!AXFYY__7.syy?FYY__ )@ @ 1FYY__(<<F"S\1F}$$Z^^CIIOOSYY__%U $T % 3!iiooab130   A + 4d $NNHI $r_   c                   U R                   R                  5        H  n[        U[        5      (       d  M  UR	                  5        H  nU R                  SR                  UR                  5      5        U R                  S5        U R                  SUS   R                  S5      < SU R                  US   SS	9< S
[        X R                   R                  R                  5      < 35        M     M     g)z0Display the notes contained in the file
        z
Displaying notes found in: {}z3  Owner                Data size        Descriptionr  n_namerT  r   n_descszr"  r   	N)r   r  rr   r   
iter_notesr   formatre   ljustr   r+   r   r   )r   r  notes      r`   display_notesReadElf.display_notes=  s     ||113G';//#..0Dnn%F%M%M!,,&( )nn%Z[nnx...r2**4
+;q*I'll.A.A.K.KL&N O	 1 4r_   c                   SnU R                   R                  5        GH  n[        U[        5      (       d  M  SnU R	                  SUR
                  U R                  US   5      UR                  5       UR                  5       S:X  a  SOS4-  5        UR                  5       (       a  U R	                  S5        OU R	                  S	5        U R                   R                  US
   5      nUR                  5        GH  nU R                   R                  S:X  a  SOSnU R                  U R                  US   USS9< SU R                  US   USS9< S[        US   U R                   5      <S 35        US   S:X  at  UR                  5       (       aM  U R                   R                  S:X  a  SOSnU R                  US   SS9nU R                  SSU-  < SU< 35        U R	                  5         GO2UR                  US   5      nUS   S:X  aC  U R                  UUS   US
   5      n	U R                   R                  U	5      n
U
R
                  nSnO8UR
                  nU R!                  US   5      nU(       a  US   (       a  US   OSnSU-  nU(       a  USU-   -  nU R                  SU R                  US    SSS!9< S[#        U5      < 35        UR                  5       (       a-  U R                  S"US   S:  a  S#OS$[%        US   5      4-  5        U R	                  5         U R                   R                  S%:X  d  GMF  U R                   S&   S':X  d  GM\  S( HG  nUS)U-     nU R                  S*U< S+[        XR                   5      < 35        U R	                  5         MI     GM     GM     U(       d  U R	                  S,5        g-g-).z6Display the relocations contained in the file
        FTz9
Relocation section '%.128s' at offset %s contains %d %s:r$  r   r2  r3  zP  Offset          Info           Type           Sym. Value    Sym. Name + Addendz8 Offset     Info    Type            Sym.Value  Sym. Namer(  r   r"     r_offsetr#  r  r_infor   r_info_typez17.17
r_info_symr   r,  r_addendr	  r-  r=  r   re   z%.22s@r>  r+  z %s %x+-r   r   r   )r'  rb  zr_info_type%sz                    Typez: z'
There are no relocations in this file.N)r   r  rr   r   r   re   r   num_relocationsis_RELArF  iter_relocationsr  r   r&   
get_symbolrH  rE  r   abs)r   has_relocation_sectionsr  symtablerelhexwidthr   addendrM  	symsecidxsymsecrP  rO  irtypes                  r`   display_relocationsReadElf.display_relocationsK  s    #(||113Gg'899&*#NNW  !56'')"2249y	[J J K
   qrYZ ||//	0BCH//1 $ 5 5 ;1

$$S_"*5 % :$$S]"*5 % :'M*DLL:; < |$)(()-)>)>")DA"	!%!1!1#j/%!1!P

y&#IJNN$ &00\1BCF
 i(A-$($:$:6;>|;L;B9;M%O	 "&!9!9)!D&,kk"$&,kk"&"6"6s<7H"I&-'&/ $+6?GI  ")K"7K#sW}4JJ((":.$( ) 8 ,K8	 : ;
 ((

8#&z?a#7CSJ0/2 $2 3 NN$ LL))R/LL-:# #Oa$7 8

#$#6ull#K$M N ( $m 2% 4^ 'NNEF 'r_   c           	        U R                   R                  5       (       d  U R                  S5        g U R                   R                  5        GH  nU R                  SUR	                  5       UR                  5       UR                  5       UR                  5       S:X  a  SOS4-  5        [        UR                  5       5       GH  nUR                  U5      nU R                  5         U R                  SU-  5        [        U[        5      (       a   U R                  SUR                  -  5        Mn  U R                  SUR                  -  5        [        U[        5      (       a  U R                  S	5        M  UR                  (       a  U R                  S
UR                  -  5        OU R                  S5        [        U[         5      (       a!  U R                  SUR"                  -  5        GM+  U R                  SUR"                  -  5        UR%                  5        H%  nU R                  S5        U R                  U5        M'     GM     GM     g )Nz,There are no .ARM.idx sections in this file.z2
Unwind section '%s' at offset 0x%x contains %d %sr   r2  r3  z	Entry %d:z    [corrupt] %sz    Function offset 0x%x: z[cantunwind]z@0x%xzCompact (inline)z    Personality: 0x%xz    Compact model index: %dr  )r   has_ehabi_infor   get_ehabi_infossection_namesection_offset	num_entryrange	get_entryrr   rG   reasonr   function_offsetrH   eh_table_offsetrI   personalitymnmemonic_array)r   
ehabi_infor  r2  mnemonic_items        r`   display_arm_unwindReadElf.display_arm_unwind  s   ||**,,NNIJ,,668JNNP'')))+$$&%//1Q6I	TG G H ://12",,Q/ {Q/e%677NN#5#DE

7%:O:OOPe%;<<NN>2**NN7U-B-B#BCNN#56e%677NN#:U=N=N#NONN#@5CTCT#TU).)>)>)@

6*}5 *A' 3 9r_   c                v   U R                   S   (       d  U R                  S5        gU R                  R                  5        GH  n[	        U[
        5      (       a  U R                  US5        UR                  5       n[        SUS5       H  nU R                  SU-  5        [        U[        US-   U5      5       H^  nU R                  U5      nUS   S	:X  a  SnS
nOUS   S:X  a  SnSnO
US   nSU-  nUS   (       a  SOSnU R                  SXhU4-  5        M`     U R                  5         M     M  [	        U[        5      (       a  U R                  USSS9  Sn	UR                  5        H  u  p[        U5      nUR                  nU
S   (       a  [!        U
S   5      nUS-  nOSnU R                  SU R#                  U	SSS9U
S   XS   U
S   U4-  5        XS   -   US    -   n[%        USS!9 H:  u  pLU R                  S"U R#                  USS#9XLR                  4-  5        XS    -  nM<     XS$   -  n	M     GM  [	        U[&        5      (       d  GM  U R                  US%5        Sn	UR                  5        H  u  nnU R                  S&U R#                  U	SSS9US'   UR                  US(   4-  5        U	US)   -   n[%        USS!9 Ha  u  nnUS*   (       a  [!        US*   5      nUS-  nOSnU R                  S+U R#                  USS#9UR                  UUS,   4-  5        UUS-   -  nMc     U	US.   -  n	M     GM     g)/z7Display the version info contained in the file
        rV   z+
No version information found in this file.NzVersion symbolsr      z  %03x:rd   r7  z	(*local*)r8  r   z
(*global*)z
(%(name)s)rg   hr   z
%4x%s%-13szVersion definitionr'  )indentvd_flagsnonez6  %s: Rev: %i  Flags: %s  Index: %i  Cnt: %i  Name: %sr   T)r   	alternate
vd_versionvd_ndxvd_cntvd_auxvda_next)startz  %s: Parent %i: %sr   vd_nextzVersion needsz$  %s: Version: %i  File: %s  Cnt: %i
vn_versionvn_cntvn_aux	vna_flagsz(  %s:   Name: %s  Flags: %s  Version: %i	vna_othervna_nextvn_next)rD  r   r   r  rr   r   _print_version_section_headerrB  r  r   minrE  r   iter_versionsnextre   r*   r   r  r   )r   r  rB  idx_by_4rI  symbol_versionversion_indexversion_name
visibilityoffsetrS   verdaux_iterverdauxre   r   verdaux_offsetrT   verneed_itervernaux_offsetvernauxs                       r`   display_version_infoReadElf.display_version_info  s      (NNIJ||113G'#344227<MN%113 !&aa 8HJJy834$Xs8a</MN)-)=)=c)B)'2oE,-M+6L+G48HH,-M+7L,:7,CM+7.+HL,:8,DS#


<)|3E $E F  O$ NN$- !90 G%566221! 3 = ,3,A,A,C(F"<0G"<<Dj) 26*3E F &NN $9 ,,Vq7; - ="<0%9I"8,d	<4$4 5 #H%55
8KK #(1,a(H'<!--n-J.1<<A(A B '**==	 )I Y//F5 -D8 G%677227OL-4-B-B-D)G\NN#I ,,Vq7; - =#L17<<#H-	M/ $/ 0 &,gh.?%?N(1,a(HW";/$6w{7K$LE!SLE$*EF $ 0 01 0 M 'e ' 4J6 67 ''**== )I  gi00F3 .EG 4r_   c                    U R                   S   S:X  a  U R                  5         gU R                   S   S:X  a  U R                  5         gg)zFDisplay the architecture-specific info contained in the file.
        r   r   r   N)r   _display_arch_specific_arm_display_arch_specific_riscvr   s    r`   display_arch_specificReadElf.display_arch_specific)  sC     <<$0++-\\+&*4--/ 5r_   c                   U R                  U5      nUc#  [        R                  R                  SU-  5        gUS   S:X  d  UR	                  5       =n(       d  U R                  SU-  5        gU R                  SUR                  -  5        U R                  U5        US   nSnU[        U5      :  Ga(  [        U5      U-
  nUS	:  a  S	OUnU R                  S
U R                  USS9-  5        [        S	5       HO  nX:  a  U R                  SX5U-      -  5        OU R                  S5        US-  S:X  d  M>  U R                  S5        MQ     [        U5       HW  nX5U-   XX-   S-    n	U	S   S:  a%  U	S   S:  a  U R                  [        U	5      5        M=  U R                  [        S5      5        MY     U R                  5         XG-  nXW-  nU[        U5      :  a  GM(  U R                  5         g)zTDisplay a hex dump of a section. section_spec is either a section
number or a name.
NzIreadelf: Warning: Section '%s' was not dumped because it does not exist!
r  r  z!Section '%s' has no data to dump.z
Hex dump of section '%s':r!  r   r,  z  %s r"  r   r   r  r  rb  r   r   r         .)_section_from_specsysstderrwritedatar   re   _note_relocs_for_sectionlenr   r   r  r   )
r   section_specr  r  addrdataptr	bytesleft	linebytesr  cs
             r`   display_hex_dumpReadElf.display_hex_dump1  s    )),7? JJk 9-glln6Ld6LNN> 4w||CD%%g.y!D	!D	G+I'"n)IJJw!1!1$!!1!DDE2Y=JJwk)::;JJt$q5A:JJsO  9%1w{Q7Q42:!A$+JJy|,JJy/ & NND G/ D	!2 	r_   c           	        U R                  U5      nUc#  [        R                  R                  SU-  5        gUS   S:X  a  U R	                  SU-  5        gU R	                  SUR
                  -  5        SnUR                  5       nSnU[        U5      :  a  U[        U5      :  a9  S	XE   s=::  a  S
::  d*  O  US-  nU[        U5      :  a  S	XE   s=::  a  S
::  d  M%  O  N(U[        U5      :  a  OmUnU[        U5      :  a&  XF   S:w  a  US-  nU[        U5      :  a
  XF   S:w  a  M  SnU R	                  SU[        XEU 5      4-  5        UnU[        U5      :  a  M  U(       d  U R	                  S5        gU R	                  5         g)zXDisplay a strings dump of a section. section_spec is either a
section number or a name.
NzLreadelf.py: Warning: Section '%s' was not dumped because it does not exist!
r  r  z"
Section '%s' has no data to dump.z
String dump of section '%s':Fr   r   r  r   Tz  [%6x]  %sz#  No strings found in this section.)	r  r  r  r  r   re   r  r  r   )r   r  r  foundr  r  endptrs          r`   display_string_dumpReadElf.display_string_dumpa  s    )),7? JJn 9-NN@ 7',,FG||~D	!c$i't}331 c$i't}333 #d)#F3t9$):! 3t9$): ENN=4#78,: : ; G! D	!$ NN@ANNr_   c                    U R                   c  g[        U R                  R                  5       5        US:X  a!  U R	                  5         U R                  5         gUS:X  a  U R                  5         gUS:X  a  U R                  5         gUS:X  a  U R                  5         gUS:X  a  U R                  5         gUS;   a  U R                  U5        gUS:X  a  U R                  5         gUS	:X  a  U R                  5         gU R                  S
U-  5        g)zDump a DWARF section
        Ninfodecodedlineframeszframes-interparanges>   pubnamespubtypeslocRangesz%debug dump not yet supported for "%s")
_dwarfinfor5   r   get_machine_arch_dump_debug_info_dump_debug_types_dump_debug_line_programs_dump_debug_frames_dump_debug_frames_interp_dump_debug_aranges_dump_debug_namelut_dump_debug_locations_dump_debug_rangesr   )r   	dump_whats     r`   display_debug_dumpReadElf.display_debug_dump  s     ??" = = ?@!!#""$-'**,("##%/)**,)#$$&44$$Y/%&&(("##%NNBYNOr_   Nc                    U(       a  US:X  a  SnO
SnUb  US-  nU(       a  SOSnU(       a  U R                   R                  S:X  a  SOS	nUc  S
nOSSU-  -   nXgU-  -   $ )ah  Format an address into a hexadecimal string.

fieldsize:
    Size of the hexadecimal field (with leading zeros to fit the
    address into. For example with fieldsize=8, the format will
    be %08x
    If None, the minimal required field size will be used.

fullhex:
    If True, override fieldsize to set it to the maximal size
    needed for the elfclass

lead0x:
    If True, leading 0x is added

alternate:
    If True, override lead0x to emulate the alternate
    hexadecimal form specified in format string with the #
    character: only non-zero values are prefixed with 0x.
    This form is used by readelf.
r   FTr'  0xr   r   r"  r,  z%x%z0%sx)r   r  )r   r  r   r   r
  r  r   fields           r`   r   ReadElf._format_hex  sr    : qy(NID!\\22b8bIE&9,,E4<r_   c                   [        US5      (       a  UR                  5       nOUR                  5       nU R                  SX!R                  UUS:X  a  SOS4-  5        U R                  SSU-  U R                  US   S	US
9U R                  US   SSS
9US   U R                  R                  US   5      R                  4-  5        g)zPrint a section header of one version related section (versym,
verneed or verdef) with some options to accomodate readelf
little differences between each header (e.g. indentation
and 0x prefixing).
num_versionsz 
%s section '%s' contains %d %s:r   r2  r3  z%%sAddr: %s  Offset: %s  Link: %i (%s)r   r!  r,  r#  r$  r"  Tr(  N)hasattrr  rB  r   re   r   r   rF  )r   version_sectionre   r
  r  num_entriess         r`   r  %ReadElf._print_version_section_header  s     ?N33)668K)557K:&&"a'GY>8 8 	9 	>&L	*b  I,$  HI&(()CDIIB  		
r_   c                   SSSSS.nU R                   R                  5        H  n[        U[        5      (       a  X!S'   M  [        U[        5      (       a  X!S'   M9  [        U[
        5      (       a  X!S'   MT  [        U[        5      (       d  Mk  UR                  5        H  nUS   S:X  d  M  SUS	'     M     M     US	   (       d  US   (       d
  US   (       a  S
US	'   U$ )ztSearch and initialize informations about version related sections
and the kind of versioning used (GNU or Solaris).
N)rR   rS   rT   rV   rR   rS   rT   rk  	DT_VERSYMr5  rV   Solaris)r   r  rr   r   r   r   r   rj  )r   r  r  rv  s       r`   rD  ReadElf._versioninfo  s    
 $(,d< ||113G'#344!(XG%566!(XG%677")YG^44",,.C7|{2',V / 4 F|iDN$DLr_   c                   [         R                  S5      nU R                  S   (       a   XR                  S   R                  5       :  a  gU R                  S   R	                  U5      nUR
                  S   nUS;  a  [        U5      nU R                  S   S:X  a  US-  (       a
  US	-  nS
US'   U R                  S   (       aY  X@R                  S   R                  5       ::  a9  U R                  S   R                  U5      u  pV[        U5      R                  US'   O>U R                  S   R                  U5      u  pxUR                  US'   UR                  US'   XBS'   U$ )z[Return a dict containing information on the
or None if no version information is available
)rd   re   rf   rg   rR   Nndxr6  rV   r5  i   iTrg   rS   re   rT   rf   rd   )dictfromkeysrD  rB  r  r2  intr  get_versionr  re   )	r   rL  r  rM  rd   _r  rT   r  s	            r`   rE  ReadElf._symbol_version  sR    'NO!!(+))(3??AA""8,77=U#;;JE  (E1 6>W$E/3N8,!!(+..x8EEGG))(3??F  )-l);)@)@v& )))4@@G !)0v&-4\\z*"'wr_   c                     [        U5      nX R                  R                  5       :  a  U R                  R                  U5      $ g! [         a    U R                  R                  U5      s $ f = f)znRetrieve a section given a "spec" (either number or name).
Return None if no such section exists in the file.
N)r  r   r   rF  rw   get_section_by_name)r   specnums      r`   r  ReadElf._section_from_spec5  s_    	:d)C\\..00||//44 	:<<33D99	:s   AA %A.-A.c                t    US   nU[         R                  :w  a  U$ U R                  U   R                  U5      $ )zGet the index into the section header table for the "symbol"
at "symbol_index" located in the symbol table with section index
"symtab_index".
r;  )r2   r   _shndx_sectionsget_section_index)r   rM  symbol_indexsymtab_indexsymbol_shndxs        r`   rH  ReadElf._get_symbol_shndxC  s>    
 j);111##L1CCLQQr_   c                    U R                   R                  5        Vs0 s H'  n[        U[        5      (       d  M  UR                  U_M)     sn$ s  snf N)r   r  rr   r   symboltable)r   secs     r`   r'  ReadElf._shndx_sectionsN  sL     ||113
3#67 !COOS 3
 	
 
s
   AAc                    U R                   R                  5        HQ  n[        U[        5      (       d  M  US   nU R                   R	                  U5      U:X  d  M@  U R                  S5          g   g)zVIf there are relocation sections pointing to the givne section,
emit a note about it.
r)  z^  Note: This section has relocations against it, but these have NOT been applied to this dump.N)r   r  rr   r   rF  r   )r   r  relsecinfo_idxs       r`   r   ReadElf._note_relocs_for_sectionV  s`     ll002F&"344!),<<++H5@NN  $D  E 3r_   c                x    U R                   R                  5       (       a  U R                   R                  5       $ S$ )zvInitialize the DWARF info contained in the file.
Leave self._dwarfinfo at None if no DWARF info was found in the file
N)r   has_dwarf_infoget_dwarf_infor  s    r`   r  ReadElf._dwarfinfoa  s/    
 150K0K0M0Mt||**,WSWWr_   c           
     t   U R                   R                  (       d  gU R                  SU R                   R                  R                  -  5        U R                   R                  R
                  nU R                   R                  5        GH  nU R                  SU R                  UR                  SS9-  5        U R                  SU R                  US   5      < SS	UR                  5       -  < S
35        U R                  SUS   -  5        US   S:  Ga  UR                  R                  SS5      (       a  UR                  R                  nU R                  SU[        R                  " UR                  R                  S5      4-  5        U R                  SU R                  US   SS9-  5        U R                  SUS   -  5        US;   a  U R                  SUS   -  5        OrUS;   a.  U R                  SUS   -  5        U R                  SUS   -  5        O=U R                  SU R                  US   SS9-  5      4  U R                  SUS   -  5        SnSnUR                  5        GH2  nUR                  S:X  a  UnU R                  SUUR                   UR"                  UR%                  5       (       d  S UR                  -  OS4-  5        UR%                  5       (       a  US!-  nM  UR&                  R)                  5        Hy  nUR                  n[+        U[,        5      (       a  S"U-  n[/        XvU5      n	S#U	;   a  U(       a  S$UR&                  ;  a  S%n
OSn
U R                  S&UR                   UU	U
4-  5        M{     UR0                  (       d  GM-  US!-  nGM5     GM     U R                  5         g)'z)Dump the debugging info section.
        NContents of the %s section:
  Compilation Unit @ offset %s:Tr     Length:        unit_length (%s-bitrh     Version:       %srO  r  	unit_typer   z   Unit Type:     %s (%d)r      Abbrev Offset: %sdebug_abbrev_offset   Pointer Size:  %saddress_size)DW_UT_skeletonDW_UT_split_compilez   Dwo id:        %sdwo_id)
DW_UT_typeDW_UT_split_type   Signature:     0x%xtype_signature   Type Offset:   0x%xtype_offsetDW_TAG_subprogram <%s><%x>: Abbrev Number: %s%s (%s)r   Unknown AT value: %xDW_OP_fbregDW_AT_frame_basez [without dw_at_frame_base]z    <%x>   %-18s: %s%s)r  has_debug_infor   debug_info_secre   global_offsetiter_CUsr   	cu_offsetdwarf_formatr   rs  rC  rJ   	iter_DIEsrv  r  abbrev_coder  rm   valuesrr   r  r4   has_children)r   r  rx   rC  	die_depthcurrent_functiondierz   re   	attr_descpostfixs              r`   r  ReadElf._dump_debug_infoh  s}    --69W9W9\9\\] 77EE//**,BNN<   >? @NN  M!232??,,. / NN1ByMAB)}!99==b11 "		 3 3INN#>!:>>"))2E2Eq#IBK $K LNN#9((,A)Bd(S$U VNN#9B~<N#NO $MM'=8'LM"&HH'?"EUBV'VW'?"]BS'ST5$$R(=%>$$O Q R S5>8JJK I#||~7711'*$?JJOO/2{{}}Wsww&"	CF  F G
 ;;==NINN113D99D!$,,5< 3D~ NI$	16FK]eu  fA  fA  LA"?"$NN#;!	?! $! " 4& ###NIA &C -F 	r_   c           
     l   U R                   R                  (       d  gU R                   R                  c  gU R                  SU R                   R                  R                  -  5        U R                   R                  R
                  nU R                   R                  5        GH  nU R                  SU R                  UR                  SS9-  5        U R                  SU R                  US   5      < SS	UR                  5       -  < S
35        U R                  SUS   -  5        U R                  SU R                  US   SS9-  5        U R                  SUS   -  5        U R                  SUS   -  5        U R                  SUS   -  5        SnUR                  5        H  nU R                  SUUR                  UR                  UR                  5       (       d  SUR                  -  OS4-  5        UR                  5       (       a  US-  nMo  UR                  R!                  5        HV  nUR                  n[#        U[$        5      (       a  SU-  n['        XTU5      nU R                  SUR                  UU4-  5        MX     UR(                  (       d  M  US-  nM     GM     U R                  5         g)z%Dump the debug types section
        Nr;  r<  Tr=  r>  r?  r@  rA  rh  rB  rO  rD  rE  rF  rG  rM  	signaturerO  rP  r   rR  rS  r   r   rT  z    <%x>   %-18s: %s)r  rW  debug_types_secr   re   rY  iter_TUsr   	tu_offsetr\  r]  r  r^  r  rv  rm   r_  rr   r  r4   r`  )r   r  tura  rc  rz   re   rd  s           r`   r  ReadElf._dump_debug_types  s\    --??**269X9X9]9]]^ 88FF//**,BNN<++BLLD+IJ KNN$:J:J2mK\:]:BR__EV:VX YNN1ByMABNN1T5E5EbI^F_ko5E5pqrNN1B~4FFGNN3boEFNN3b6GGHI||~?JJOO/2{{}}Wsww&"	CF  F G
 ;;==NINN113D99D!$,,5< 3D~ NINN#9!=# $# $ 4 ###NI1 & -L 	r_   c                B   U R                   R                  (       d  gU R                  SU R                   R                  R                  -  5        U R                  5         / nU R                   R                  5        GH  nU R                   R                  U5      nUb  X1;   a  M)  UR                  U5        [        US   S   R                  5      nUS   (       a  U R                  SU-  5        OU R                  SU-  5        U R                  S5        UR                  5        GH  nUR                  nUGc   UR                  [        :X  a  US   UR                  S   S	-
     nUR                  S:X  a)  U R                  S
[        UR                  5      -  5        GORU R                  S[        US   UR                  S	-
     5      < S[        UR                  5      < S35        GOUR                  [        :X  a:  U R                  S[        US   UR                  S   R                     5      -  5        GOUS   S:  d  U R                   S   S:X  a  U R                  [        US   UR"                  S	-
     R                  5      <S SUR$                  (       d  UR&                  OS<S SUR(                  S:X  a  SOU R+                  UR(                  5      <S SUR,                  (       a  UR$                  (       d  SOS< 35        OU R                  [        US   UR"                  S	-
     R                  5      <S SUR$                  (       d  SUR&                  4-  OS< SUR(                  S:X  a  SOU R+                  UR(                  5      <S UR.                  R0                  S	:X  a  SOSUR2                  4-  < SUR,                  (       a  UR$                  (       d  SOS< 35        UR                  [4        :X  d  GM  U R                  5         GM     GM     g)zrDump the (decoded) line programs from .debug_line
The programs are dumped in the order of the CUs they belong to.
NContents of the %s section:
file_entryr   include_directoryz%s:zCU: %s:zLFile name                            Line number    Starting address    Stmtr   z

./%s:[++]
/:rO  r  r   r   35r  r  z>110z>18r  xr   z%11dz[%d]r   )r  rW  r   debug_line_secre   rZ  line_program_for_CUappendr   get_entriesstatecommandr;   args	dir_indexr<   r   r   end_sequencelineaddressr   is_stmtr   "maximum_operations_per_instructionop_indexr:   )r   lineprogram_listrx   lineprogramcu_filenamer2  r|  rp  s           r`   r   !ReadElf._dump_debug_line_programs  sF    --4t7U7U7Z7ZZ[//**,B//==bAK"k&E##K0#K$=a$@$E$EFK./u{23y;67NNij %002=}}7%0%>uzz!}q?P%Q
%//14 NN= )*// :,< = !NN )+6I*J:K_K_bcKc*d e )*// :,< = *<<u%k2E&FuzzRS}G^G^&_`(b c +a/4<<3LPZ3ZNN!+l";EJJN"K"P"PQ*/*<*<

#E$}}1t7G7G7VV$}}U5G5GRO	$Q R NN!+l";EJJN"K"P"PQ6;6H6H%**.cQ$}}1t7G7G7VV)00SSWXX^dhmhvhvgx^xx$}}U5G5GRO$Q R ==K/NN$E 3- -r_   c                   U R                  SUR                  -  5        U GH  n[        U[        5      (       GaH  U R                  SUR                  U R                  US   SSS9U R                  US   SSS	94-  5        U R                  S
US   -  5        U R                  S[        US   5      -  5        US   S:  a.  U R                  SUS   -  5        U R                  SUS   -  5        U R                  SUS   -  5        U R                  SUS   -  5        U R                  SUS   -  5        UR                  (       a-  U R                  SUR                  R                  S5       35        U R                  5         GOG[        U[        5      (       a  UR                  R                  UR                  :  a  US   OUR                  S   nU R                  SUR                  U R                  USSS9U R                  US   SSS	9UR                  R                  U R                  US   SSS9U R                  US   US   -   SSS94-  5        UR                  (       a-  U R                  SUR                  R                  S5       35        O8[        U[        5      (       d   eU R                  SUR                  -  5        GM  U R                  [        U5      5        GM     U R                  5         g )!zDump the raw call frame info in a section.

`section` is the Section instance that contains the call frame info
while `cfi_entries` must be an iterable that yields the sequence of
CIE or FDE instances.
ro  z
%08x %s %s CIElengthTFr+  CIE_idr"  r#  z  Version:               %drO  z  Augmentation:          "%s"augmentationr  z  Pointer Size:          %drG  z  Segment Size:          %dsegment_sizez  Code alignment factor: %ucode_alignment_factorz  Data alignment factor: %ddata_alignment_factorz  Return address column: %dreturn_address_registerz  Augmentation data:     r   "
%08x %s %s FDE cie=%08x pc=%s..%sCIE_pointerinitial_locationaddress_range
%08x ZERO terminatorN)r   re   rr   rD   r  r   r   augmentation_bytesrG  rE   cierF   r   r6   )r   r  cfi_entriesr2  r  s        r`   _dump_frames_infoReadElf._dump_frames_info/  s    	4w||CD E%%%1LL$$U8_d5$Q$$U8_%$P5R  R S <uY?OOP>5Q_K`Aaab#q(NN#@5CX#XYNN#@5CX#XY<uE\?]]^<uE\?]]^<uE^?__`++NN%>u?W?W?[?[\_?`>a#bc E3'',1II,<,<u||,KxQVQZQZ[cQdDLL$$VT%$H$$U=%9Qu$UII$$$$U+=%>UZ$[$$01E/4JJ $U % 4H5  5 6 ++NN%>u?W?W?[?[\_?`>a#bc "%....7%,,FGJJ078M !N 	r_   c                   U R                   R                  5       (       a>  U R                  U R                   R                  U R                   R	                  5       5        U R                  5         U R                   R                  5       (       a?  U R                  U R                   R                  U R                   R                  5       5        gg)zJDump the raw frame info from .debug_frame and .eh_frame sections.
        N)	r  
has_EH_CFIr  eh_frame_secEH_CFI_entriesr   has_CFIdebug_frame_secCFI_entriesr  s    r`   r  ReadElf._dump_debug_framesa  s     ??%%''""OO00OO2246 	??""$$""OO33OO//13 %r_   c                   US:X  a1  U R                   R                  5       nU R                   R                  nO0U R                   R                  5       nU R                   R                  nU(       d  gU R                  SUR                  -  5        U R                  5         UR                  5       n[        U[        R                  " UR                  5       S S95       H  u  nu  pgU R                  SUR                  -  5        U R                  SUR                  -  5        U R                  SUR                  -  5        U R                  S	UR                  -  5        U R                  5         U R                  S
5        U H,  nU R                  SUS   R                   U-
  US   4-  5        M.     M     U R                  5         g)z"
Dump the debug pubnames section.
r  Nro  c                     U S   R                   $ )Nr   )cu_ofs)rw  s    r`   r   -ReadElf._dump_debug_namelut.<locals>.<lambda>  s    QqT[[r_   )keyz)  Length:                              %dz)  Version:                             %dz+  Offset into .debug_info section:     0x%xz)  Size of area in .debug_info section: %dz    Offset  Namez    %x          %sr   r   )r  get_pubnamesdebug_pubnames_secget_pubtypesdebug_pubtypes_secr   re   get_cu_headerszip	itertoolsgroupbyitemsr?  rO  debug_info_offsetdebug_info_lengthdie_ofs)	r   whatnamelutr  
cu_headerscu_hdrr  r  items	            r`   r  ReadElf._dump_debug_nameluto  so    :oo224Goo88Goo224Goo88G 4w||CD++-
 *-Z9J9JMMO#8:: *;%V_f NNF6K]K]]^NNF6>>YZNNH6KcKccdNNF6KcKccdNNNN-.3tAw7OQUVWQX6YYZ *; 	r_   c                   U R                   R                  5       nUc  gUR                  SS9nU(       d"  U R                  5         U R                  S5        gU R                  SU R                   R                  R
                  -  5        U R                  5         SnU GH  nX4R                  :w  a  XBS   :w  a7  U R                  SU R                  SSSS	9< S
U R                  SSSS	9< 35        U R                  SUR                  -  5        U R                  SUR                  -  5        U R                  SUR                  -  5        U R                  SUR                  -  5        U R                  SUR                  -  5        U R                  5         U R                  S5        UR                  S:w  d  UR                  S:w  aK  U R                  SU R                  UR                  SSS	9< S
U R                  UR                  SSS	9< 35        UR                  nGM     U R                  SU R                  SSSS	9< S
U R                  SSSS	9< 35        g)zDump the aranges table
        NT)
need_emptyz/Section '.debug_aranges' has no debugging data.ro  r   r  Fr+  r   z  Length:                   %dz  Version:                  %dz   Offset into .debug_info:  0x%xz  Pointer Size:             %dz  Segment Size:             %dz    Address            Length)r  get_aranges_get_entriesr   debug_aranges_secre   info_offsetr   r?  rO  rG  r  
begin_addrr  )r   aranges_tableunordered_entriesprev_offsetr2  s        r`   r  ReadElf._dump_debug_aranges  s    335 
 *66$6G NNNNLM4t7X7X7]7]]^&E///a00NN((D(G((D(G$I J ?5CTCTUV?5==QRAUEVEVWX?5CUCUVW?5CUCUVW >?1$(9$$U%5%5tE$R$$U\\4$N P Q  ++K# '$ 	  D ?  D ?A 	Br_   c                z   U R                  SUR                  -  5        U GH  n[        U[        5      (       ae  U R                  SUR                  U R                  US   SSS9U R                  US   SSS	9[        US
   5      US   US   US   4-  5        US   nGOn[        U[        5      (       Ga   UR                  R                  UR                  :  a  US   OUR                  S   nU R                  SUR                  U R                  USSS9U R                  US   SSS	9UR                  R                  U R                  US   SSS9U R                  US   US   -   SSS94-  5        UR                  S   n[        UR                  5       R                  5      [        UR                  R                  5       R                  5      :X  a  GM  O8[        U[        5      (       d   eU R                  SUR                  -  5        GM  UR                  5       nUR                  (       d  GM  U R                  S5        U R                  UR                  R                  S:X  a  SOS5        U R                  S5        UR                  5       n[!        UR"                  5      nUR"                  (       a>  U H8  nX:X  a  U R                  S5        M  U R                  S[%        U5      -  5        M:     U R                  5         UR                   H  n	U R                  U R                  U	S   SSS95        U	S   b  ['        U	S   5      n
OSn
U R                  SU
-  5        U H,  nX;   a  [)        X   5      n
OSn
U R                  SU
-  5        M.     U R                  5         M     GM     U R                  5         g)zDump interpreted (decoded) frame information in a section.

`section` is the Section instance that contains the call frame info
while `cfi_entries` must be an iterable that yields the sequence of
CIE or FDE instances.
ro  z&
%08x %s %s CIE "%s" cf=%d df=%d ra=%dr  TFr+  r  r"  r#  r  r  r  r  r  r  r  r  r  z   LOCr  r  z
          z
 CFA      zra      z %-5spccfaNuz %-9s)r   re   rr   rD   r  r   r   rE   r  r  get_decodedtablerF   r   structsrG  sorted	reg_orderr3   r8   r7   )r   r  r  r2  	ra_regnumr  decoded_tabler  regnumr  r   s              r`   _dump_frames_interp_info ReadElf._dump_frames_interp_info  s    	4w||CD E%%%HLL$$U8_d5$Q$$U8_%$PeN34121234L6  6 7 "";<	E3'',1II,<,<u||,KxQVQZQZ[cQdDLL$$VT%$H$$U=%9Qu$UII$$$$U+=%>UZ$[$$U+=%>AW%W $U % 4H5  5 6 "II&?@	 ))+112EII11399:;;
 "%....7%,,FG "--/M && JJx JJu}}99Q>tLQJJ|$ "--/M}667I&&'F*

:. JJw):6)BBC	 (
 NN%++

4++JU , < = ;*-d5k:AA

7Q;''F~6t|DJJw{+ (  ! , !` 	r_   c                   U R                   R                  5       (       a>  U R                  U R                   R                  U R                   R	                  5       5        U R                  5         U R                   R                  5       (       a?  U R                  U R                   R                  U R                   R                  5       5        gg)z[Dump the interpreted (decoded) frame information from .debug_frame
and .eh_frame sections.
N)	r  r  r  r  r  r   r  r  r  r  s    r`   r  !ReadElf._dump_debug_frames_interp  s     ??%%''))OO00OO2246 	??""$$))OO33OO//13 %r_   c                   U R                   nUR                  5       nU(       d  g[        U[        5      (       a7  U R	                  XR
                  5        U R	                  XR                  5        gU R	                  X5        g)HDump the location lists from .debug_loc/.debug_loclists section
        N)r  location_listsrr   rA   _dump_debug_locsection_loc	_loclists)r   diloc_lists_secs      r`   r  ReadElf._dump_debug_locations%  se     __))+m%677'',>,>?'',C,CD'':r_   c                n   UR                   S:  nU(       a  UR                  OUR                  R                  nUR	                  5        VVVs0 s H  nUR                  5         Hr  nUR                  R                  5         HP  n[        R                  " XuS   5      (       d  M#  [        R                  " XuS   5      (       d  MC  UR                  U_MR     Mt     M     nnnnUR                  R                  n	U	S-  n
SX4-  n[        UR                  5       5      nU(       d  U R!                  SU< S35        gU(       a  [        UR	                  5       5      OSnSnSnU R!                  S	U< S
35        U(       d  U R!                  S5        U H  nU(       a  US   R"                  U:  al  US   R"                  U:  aH  X   nU R%                  U5        UR&                  UR(                  -   nUS-  nUS   R"                  U:  a  MH  U R!                  S5        U R+                  UX5        M     gs  snnnf )r  r  rO  r'  z    %%08x %%0%dx %%0%dx %%s%%sz

Section 'z' has no debugging data.Nr   zContents of the z
 section:
z9    Offset   Begin            End              Expressionr   )rO  debug_loclists_secdebug_loc_secre   rZ  r]  rm   r_  r=   attribute_has_location_attribute_has_loc_listrn   configdefault_address_sizelistiter_location_listsr   entry_offset_dump_debug_loclists_CU_headeroffset_after_lengthr?  _dump_loclist)r   r  r  ver5r  rx   rc  rz   cu_map	addr_size
addr_widthline_template	loc_listslcus	lcu_indexnext_lcu_offsetloc_listlcus                     r`   r  ReadElf._dump_debug_locsection3  s    $$)15--2;K;KQQ kkm
#||~--/55dyMJ	 
 66t	]K DJJN 0 % # 	 
 II22	]
8J;SS::<=	NNlTU 26tM**,-4	,HINNVW!H00?Bqk..@/C77<&)&=&=&OONI	 qk..@
 Z[x? "E
s   AH0%H0H0c           	        SnSnS nSnS nU GH}  n	[        U	[        5      (       a:  S=pTU R                  SU	R                  U	R                  U	R
                  4-  5        MS  U(       a  SnU R                  S5        Uc  SnO1Uc.  UR                  U	R                  S5      nU(       d  [        S5      e[        U	[        5      (       Gau  Uc  U	R                  (       d  [        U5      nU	R                  (       a  SOUU	R                  -   n
U	R                  (       a  SOUU	R                  -   n[        U	R                  UR                  UR                   5      nU(       a  X   nU	R                  U	R                  :X  a  UR                  UR
                  :X  a  SOSnU R                  SU	R                  UR                  UR
                  UR                  4-  5        U R                  S	U
UUU4-  5        US
-  nGM  U	R                  U	R                  :X  a  SOSnU R                  UU	R                  U
UUU4-  5        GM/  [        U	["        5      (       d  GMG  U	R$                  nU R                  SU	R                  U	R$                  4-  5        GM     US   nU R                  SUR                  UR&                  -   -  5        g )NFr   Tz)    %08x v%015x v%015x location view pairr   z&Location list can't be tracked to a CU (start == end)z)    %08x v%015x v%015x views at %08x for:z             %016x %016x %s%sr   z    %08x %016x (base address)    %08x <End of list>)rr   r?   r   r  beginendrs  rw   r>   ru   r   rv   
end_offsetr9   loc_exprr  r[  LocBaseAddressEntryrt   entry_length)r   r  r  r  in_views	has_viewsr|   loc_entry_countrx   r2  rv   r  exprviewre  lasts                   r`   r  ReadElf._dump_loclistj  s   	E%!122'++	JeN`N`bgbmbmotoxoxMyyz$HNN2& >GZE$6$6>B()QRRe]33u/@/@".r"2).):):A5K]K]#]L','8'8!gIYIY!YJ.u~~rzz2<<XD '87<7I7IUM]M]7]bfblblptpxpxbx"3  A'R!.. JJ HH --	U/ (/ 0
 'F(& #	I% (% &
 (1,7<7I7IUM]M]7]"3ce}!..(& #8% (% &  ':;;#00GNN#BeFXFXZ_ZlZlEm#mnc j |/43D3DtGXGX3XYZr_   c                d   U R                  SU R                  UR                  SS9-  5        U R                  SU R                  UR                  SS9-  5        U R                  SUR                  -  5        U R                  SUR
                  -  5        U R                  SUR                  -  5        U R                  SUR                  -  5        UR                  (       aO  U R                  S	UR                  -  5        [        UR                  5       H  nU R                  S
U-  5        M     g g )NzTable at Offset %sTr=    Length:          %s  DWARF version:   %d  Address size:    %d  Segment size:    %d  Offset entries:  %d
  Offsets starting at 0x%x:    [%6d] 0x%xr   r   r[  r?  rO  rG  segment_selector_sizeoffset_countoffsetsoffset_table_offsetr  r   rx   i_offsets      r`   r  &ReadElf._dump_debug_loclists_CU_header  s    +d.>.>r||W[.>.\\].1A1A"..\`1A1aab.;<.@A.1I1IIJ02??BC::NN82;Q;QQR%bjj1/(:; 2 r_   c                   U R                   nUR                  5       nU(       d  g [        U[        5      (       a7  U R	                  XR
                  5        U R	                  XR                  5        g U R	                  X5        g r.  )r  rp   rr   rC   _dump_debug_rangesection_ranges	_rnglists)r   r  range_lists_secs      r`   r  ReadElf._dump_debug_ranges  s`    __..*o~66))".E.EF))".G.GH))">r_   c                d   U R                  SU R                  UR                  SS9-  5        U R                  SU R                  UR                  SS9-  5        U R                  SUR                  -  5        U R                  SUR
                  -  5        U R                  SUR                  -  5        U R                  SUR                  -  5        UR                  (       aO  U R                  S	UR                  -  5        [        UR                  5       H  nU R                  S
U-  5        M     g g )Nz Table at Offset: %s:Tr=  r
  r  r  r  r  r  r  r  r  s      r`   _dump_debug_rnglists_CU_header&ReadElf._dump_debug_rnglists_CU_header  s    .1A1A",,Z^1A1__`.1A1A"..\`1A1aab.;<.@A.1I1IIJ02??BC::NN82;Q;QQR%bjj1/(:; 2 r_   c           
        UR                   S:  nU(       a  UR                  OUR                  R                  nUR                  R
                  nUS-  nSXf4-  nSU-  nSXf4-  n	UR                  5        V
Vs0 s HG  n
U
R                  5         H/  nSUR                  ;   d  M  UR                  S   R                  U
_M1     MI     nn
nU(       a  [        UR                  5       5      OS nSnSn[        UR                  5       5      nU(       d  U R                  SU-  5        g U R                  S	U-  5        U(       d  U R                  S
5        U H  nU(       a  US   R                  U:  al  US   R                  U:  aH  X   nU R                  U5        UR                  UR                   -   nUS-  nUS   R                  U:  a  MH  U R                  S
5        U R#                  UXXxX5        M     g s  snn
f )Nr  r'  z    %%08x %%0%dx %%0%dx %%sz    %%08x %%0%dx (base address)z;    %%08x %%0%dx (base address index) %%0%dx (base address)rk   r   z$
Section '%s' has no debugging data.zContents of the %s section:


z    Offset   Begin    Endr   )rO  debug_rnglists_secdebug_ranges_secre   r  r  rZ  r]  rm   rn   r  iter_range_listsr   r  r   r  r?  _dump_rangelist)r   r  r  r  r  r  r  r  base_templatebase_template_indexedrx   rc  r  rcus	rcu_indexnext_rcu_offsetrp   
range_listrcus                      r`   r   ReadElf._dump_debug_rangesection  s   &&!+15--2;N;NTTII22	]
58PP9ZH ]ak`x x
 kkm1#||~/ <#..066;% 7# 	 1
 48tO,,./T	?;;=>NNB\QR:\IJNN67%J
122_D m00?B/C77<&)&=&=&OONI	 !m00?B
 :;  V=Yn  A &'1s   8(G4$"G4c                (  ^ US   n[        X(R                     5      n	S n
U GH  m[        T[        5      (       a  TR                  TR
                  :X  a  SOSnU R                  UU(       a  TR                  OUR                  TR                  (       a  SOU	TR                  -   TR                  (       a  SOU	TR
                  -   U4-  5        M  [        T[        5      (       a  TR                  n	S nU(       a:  U
(       d  UR                  US   R                  5      n
[        U4S jU
 5       5      nU(       aH  UR                  S:X  a8  U R                  UTR                  UR                  TR                  4-  5        GMa  U R                  UU(       a  TR                  OUR                  TR                  4-  5        GM  [        S5      e   US   nU R                  SU(       a  UR                  UR                  -   OUR                  -  5        g )	Nr   r  r   c              3  ^   >#    U  H"  oR                   TR                   :X  d  M  Uv   M$     g 7fr.  )r  )r   rer2  s     r`   r   *ReadElf._dump_rangelist.<locals>.<genexpr>  s%     'o5Er\a\n\nIn5Es   -	-DW_RLE_base_addressxzUnknown object in a range listr  r  )r   r  rr   rB   rv   r  r   ru   rs   rt   get_range_list_at_offset_exr  
entry_typerd   NotImplementedErrorr  )r   r,  r  r  r  r'  r(  r  firstr|   raw_v5_rangelistre  raw_v5_entryr  r2  s                 @r`   r&  ReadElf._dump_rangelist  s    1v&8&89:E%,,/4/A/AUEUEU/U+[]}*.E&&E4F4F++QE<N<NN++QE<L<LL	0   
 E"788,,  $++:+V+VWabcWdWqWq+r(#''o5E'o#oLL$;$;?U$UNN#8**$****<, $, -
 NN=.2**8J8J**4, $, - **JKK7  8 "~/\`43D3DtGXGX3Xfkfxfxyzr_   c           
     H   UR                  5        GH  nU R                  SUR                  S   -  5        UR                  5        H  nUR                  R                  c  SO+SR                  S UR                  R                   5       5      nU R                  U" UR                  R                  US5      5        UR                  5        HK  nU R                  S5        U R                  U" UR                  UR                  UR                  5      5        MM     M     GM     g)z9Display the attributes contained in the section.
        zAttribute Section: %svendor_nameNr   r   c              3  ,   #    U  H
  nS U-  v   M     g7f)z%dNrW   )r   rw  s     r`   r   .ReadElf._display_attributes.<locals>.<genexpr>.  s     CfVeQRD1HVer   r  )
iter_subsectionsr   r   iter_subsubsectionsextrar   rv  iter_attributesr   rn   )r   attr_sec
descriptorr   ssh_valrz   s          r`   _display_attributesReadElf._display_attributes(  s     **,ANN2QXXm5LLM++- iioo5388CfVXV_V_VeVeCf;fz"))--EF..0DJJt$NN:dhh

DJJ#OP 1	 . -r_   c                v    U R                   R                  S5      nU(       a  U R                  U[        5        gg)zJDisplay the ARM architecture-specific info contained in the file.
        z.ARM.attributesN)r   r"  rG  r,   r   rC  s     r`   r  "ReadElf._display_arch_specific_arm5  s2     <<334EF$$X/DE r_   c                v    U R                   R                  S5      nU(       a  U R                  U[        5        gg)zMDisplay the RISC-V architecture-specific info contained in the file.
        z.riscv.attributesN)r   r"  rG  r-   rJ  s     r`   r  $ReadElf._display_arch_specific_riscv<  s2     <<334GH$$X/FG r_   c                L    U R                   R                  [        U5      5        g)z!Emit an object to output
        N)r   r  rr  r   r   s     r`   r   ReadElf._emitC  s     	#a&!r_   c                n    U R                   R                  [        U5      R                  5       S-   5        g)z8Emit an object to output, followed by a newline
        rr  N)r   r  rr  rstriprO  s     r`   r   ReadElf._emitlineH  s%     	#a&--/D01r_   )r   r   )r   z	IO[bytes]r   zIO[str]returnNonerT  rU  )r   r  rT  rr  )T)r  boolrT  rU  )r  	int | strrT  rU  )r  rr  rT  rU  )NFTF)r  r  r   z
int | Noner   rW  r
  rW  r  rW  rT  rr  )Tr   )re   rr  r
  rW  r  r  rT  rU  )rT  rP   )rL  r  rT  zSymbolVersion | None)r#  rX  rT  zSection | None)rT  z(dict[Container, SymbolTableIndexSection])r  rN   rT  rU  )rT  zDWARFInfo | None)r  rr  rT  rU  )r  rM   rT  rU  )r  rr  r  r  rT  rU  )rx   rK   rT  rU  )rx   rL   rT  rU  )r,  r  r  r  r  rW  r  rr  r'  rr  r(  rr  rT  rU  )r   )r   rr  rT  rU  )5rY   rZ   r[   r\   __doc__r   r   r   r  r/  rQ  rx  r  r  r  r  r  r  r  r  r   r  r   rD  rE  r  rH  r'  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r   r  r&  rG  r  r  r   r   r^   rW   r_   r`   r   r   y   s   8tbHWr=1~F#P7JrOTGl!6Fc1J0.`+ZP> !%, ,  ,  	, 
 ,  ,  
, d 
 
 	

 
 

>  2"H:	R 
 
	 X XM^2hB%H0d3 D(BTYv3;5@n<[|<?
<(AX,{,{ ,{ 	,{
 ,{ ,{  #,{ 
,{\QFH"
2 2r_   r   z:Display information about the contents of ELF format filesz!%%(prog)s: based on pyelftools %sc           	     j
   [         R                  " S[        SSS9nUR                  SSS SS9  UR                  S	S
S[        S9  UR                  SSSSSS9  UR                  SSSSSS9  UR                  SSSSSS9  UR                  SSSSSSS9  UR                  S S!S"SS#S$S9  UR                  S%S&SS'S(S9  UR                  S)S*S+SS,S-S9  UR                  S.S/SS0S1S9  UR                  S2S3SS4S5S9  UR                  S6S7SS8S9S9  UR                  S:S;S<S=S>S?S@9  UR                  SASBS<SCS>SDS@9  UR                  SESFSSGSHS9  UR                  SISJSSKSLS9  UR                  SMS<SNSOSPS@9  UR                  SQSSRSSS9  UR                  5       nUR                  (       d  UR                  (       d&  UR                  5         [        R                  " ST5        UR                  (       a  SU=n=pEO$UR                  nUR                  nUR                  nU =(       d    [        R                  n[!        UR                  SV5       n [#        Xv5      nU(       a  UR%                  5         U(       a  UR'                  U(       + SW9  U(       a  UR)                  U(       + SW9  UR*                  (       a  UR-                  5         UR.                  (       a  UR1                  5         UR2                  (       a  UR5                  5         UR6                  (       a  UR9                  5         UR:                  (       a  UR=                  5         UR>                  (       a  URA                  5         URB                  (       a  URE                  5         URF                  (       a  URI                  URF                  5        URJ                  (       a  URM                  URJ                  5        URN                  (       a  URQ                  URN                  5        URS                  5         S S S 5        g ! [T         a  n	[        R                  RS                  5         [        RV                  RY                  SXU	-  5        URZ                  (       a  [\        R^                  " 5         [        R                  " SY5         S n	A	NS n	A	f[`         aq    [b        R                   " [b        Rd                  [b        Rf                  5      n
[b        Rh                  " XRk                  5       5        [        R                  " SY5         GNf = f! , (       d  f       g = f)ZNz$usage: %(prog)s [options] <elf-file>Fz
readelf.py)usager   add_helpprogr   ?zELF file to parse)nargsdefaulthelpz-vz	--versionrO  )actionrO  z-dz	--dynamic
store_trueshow_dynamic_tagszDisplay the dynamic section)rb  destra  z-Hz--helpra  zDisplay this informationz-hz--file-headershow_file_headerzDisplay the ELF file headerz-lz--program-headersz
--segmentsshow_program_headerzDisplay the program headersz-Sz--section-headersz
--sectionsshow_section_headerzDisplay the sections' headersz-ez	--headersshow_all_headerszEquivalent to: -h -l -Sz-sz	--symbolsz--symsshow_symbolszDisplay the symbol tablez-nz--notes
show_notesz#Display the core notes (if present)z-rz--relocsshow_relocsz$Display the relocations (if present)z-auz--arm-unwindshow_arm_unwindz3Display the armeabi unwind information (if present)z-xz
--hex-dumpstoreshow_hex_dumpz<number|name>z3Dump the contents of section <number|name> as bytes)rb  re  metavarra  z-pz--string-dumpshow_string_dumpz5Dump the contents of section <number|name> as stringsz-Vz--version-infoshow_version_infoz)Display the version sections (if present)z-Az--arch-specificshow_arch_specificz:Display the architecture-specific information (if present)z--debug-dumpdebug_dump_whatz<what>zDisplay the contents of DWARF debug sections. <what> can one of {info,decodedline,frames,frames-interp,aranges,pubtypes,pubnames,loc,Ranges}z--tracebackshow_tracebackz>Dump the Python traceback on ELFError exceptions from elftoolsr   Trb)r  zELF error: %s
r   )6argparseArgumentParserSCRIPT_DESCRIPTIONadd_argumentVERSION_STRING
parse_argsra  r   
print_helpr  exitri  rf  rh  rg  stdoutopenr   r   r/  r  rd  rx  rj  rQ  rk  r  rl  r  rm  r  rr  r  rs  r  ro  r  rq  r  rt  r  flushr
   r  r  ru  	traceback	print_excBrokenPipeErrorosdevnullO_WRONLYdup2fileno)stream	argparserr~  do_file_headerdo_section_headerdo_program_headerr   r   readelfexr  s              r`   mainr  R  s   ''8*	I
 6t$  & 4n  64&9.  0 4f+  - 4&8.  0 4!4l&;.  0 4!4l&;0  2 4&8*  , 4hn+  - 4l6  8 4m7  9 5.&7F  H 4/F  H 4!3_H  J 4!1&9<  > 4!2&:M  O >!2Hf  h
 =".5E!<  =
 !Dyy		AEEE*->.. 44 44!szzF	dii	$*	d+G++- //)7%7 0 9 //)7%7 0 9%%,,.  --/%%'++-##**,%%,,.&&--/!!((););<$$++D,A,AB##**4+?+?@LLN? 
	@  	JJJJ.34""##%HHQKK 	 ggbjj"++6GGGG]]_-HHQK	M 
	s?   :T$<GP
T!"A<R#T$#A:T!T$ T!!T$$
T2c                     Sn SS K nUR                  SU 5        SS KnUR                  U 5      nUR	                  S5      R                  S5        g )Nzreadelf.profiler   z!main(open("readelfout.txt", "w"))
cumulative   )cProfilerunpstatsStats
sort_statsprint_stats)PROFFILEr  r  ps       r`   profile_mainr    sE     !HLL4h? XALL**2.r_   __main__)rx   rL   )r   rr  rT  rr  r.  )r  zIO[str] | NonerT  rU  rV  )z
__future__r   rw  r  r  r1  r  r  	functoolsr   typingr   r   r   pathinsertelftoolsr	   elftools.common.exceptionsr
   elftools.common.utilsr   elftools.elf.elffiler   elftools.elf.dynamicr   elftools.elf.enumsr   elftools.elf.segmentsr   elftools.elf.sectionsr   r   r   elftools.elf.gnuversionsr   r   r   elftools.elf.relocationr   elftools.elf.descriptionsr   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   elftools.elf.constantsr/   r0   r1   r2   elftools.dwarf.descriptionsr3   r4   r5   r6   r7   r8   r9   elftools.dwarf.constantsr:   r;   r<   elftools.dwarf.locationlistsr=   r>   r?   r@   r   rA   elftools.dwarf.rangesrB   rs   rC   elftools.dwarf.callframerD   rE   rF   elftools.ehabi.ehabiinforG   rH   rI   elftools.dwarf.enumsrJ    elftools.construct.lib.containerrK   elftools.dwarf.compileunitrL   elftools.dwarf.dwarfinforM   rN   rP   rb   r   compiler   r   r   ry  r{  r  r  rY   rW   r_   r`   <module>r     sX   #  	 
 	   % / / 3  ! / + ( / ) /   6       + 0 + .  
6 6 U  U g g 3 3 a a +:62-i 	 E< ::n- RR2 R2j6 R 4{Bzz
/ zF r_   