
    j|D                        d Z ddlZddlZddlZddlZddlmZ ddlm	Z	 ddl
ZddlmZ ddlmZmZmZmZmZmZmZmZ  ej        e            ej        ej                   ej        d	d
ddd          d                                     Ze                                 ej        ddd ej        ddd          d           ej        ddd           ej        ddd           ej        dd ej        ddd                    d                                                              Ze                                 ej        ddd ej        d!          d"           ej        dd#           ej        ddd$           ej        d%d&d'           ej        d(d)d*           ej        d+d,d-d.           ej        d/d0d1           ej        d2ddd34           ej        d5ddd34           ej        d6ddd74          d8                                                                                                                                     Ze                                 ej        ddd ej        ddd9          d:           ej        d ej        ddd9          d;           ej        dddd<=           ej        d>d?d@dA ej         g dB          C           ej        dDdEdddF4           ej        dGd)dH           ej        dIdJdK          dL                                                                                                 Z!e                                 ej        dMdN ej         g dO          dPddQR           ej        dSdTdUddddVW           ej        dXdYddddZW           ej        d[d\ ej        ddd9          ]          d^                                                             Z"e                                 ej        d_d\ ej        ddd          ]          d_e#e$         fd`                        Z%e                                 ej        dadb ej        d!          C           ej        d[dd ej        ddd9          c          dde$d[e$fde                                    Z&e                                 ej        ddfde'dgh           ej        dYdide'djh           ej        dk ej        ddd9          l          dm                                                 Z(e                                 ej        d[dd ej        ddd9          c           ej        dndodg dpq           ej        drddds4          dt                                                 Z)e                                 ej        duddv           ej        dndodg dpq          dw                                     Z*e                                 ej        duddv           ej        dndoddxgdpq          dy                                     Z+dz Z,d{ Z-d| Z. e/e,ej0        ej1        ej2        }          Z3e                                 ej        d ej        ddd9          d;           ej        ddd~d           ej        d ej          e#e34                                          d          dd           ej        dXdYddd           ej        ddd           ej        ddd           ej        ddd           ej        ddd           ej        dddd          d                                                                                                                         Z5e6dk    r e             dS dS )zAAndroguard is a full Python tool to reverse Android Applications.    N)logger)Session)util)androarsc_mainandroaxml_mainandrodis_mainandrodump_mainandrolyze_mainandrosign_mainandrotrace_mainexport_apps_to_format)help)versionz	--verbosez--debug	verbosityverbosez
Print more)
flag_valuer   c                     | t          j        d           nt          j        d           t          j        dd           d S )NERRORINFOzandroguard.logz10 days)	retention)r   set_logr   add)r   s    Y/home/ubuntu/.hermes/hermes-agent/venv/lib/python3.11/site-packages/androguard/cli/cli.pyentry_pointr      sI     WV
J9555555    z--inputz-iinput_TF)exists	file_okaydir_okayz3AndroidManifest.xml or APK to parse (legacy option))typer   z--outputz-ozCfilename to save the decoded AndroidManifest.xml to, default stdoutz
--resourcez-rzUResource (any binary XML file) inside the APK to parse instead of AndroidManifest.xmlfile_)requiredr    c                     |%| #t          d           t          j        d           |%| #t          d           t          j        d           |t          |||           dS | t          | ||           dS dS )a5  
    Parse the AndroidManifest.xml.

    Parsing is either direct or from a given APK and prints in XML format or
    saves to file.

    This tool can also be used to process any AXML encoded file, for example
    from the layout directory.

    Example:

        >>> androguard axml AndroidManifest.xml
    NJCan not give --input and positional argument! Please use only one of them!   Give one file to decode!)printsysexitr   )r   outputr!   resources       r   axmlr,   ,   s    J V/+	
 	
 	
 	}()))ufh/////		vvx00000 
	r   )r   z.resources.arsc or APK to parse (legacy option))r"   z)filename to save the decoded resources toz	--packagez-pzVShow only resources for the given package name (default: the first package name found)z--localez-lz>Show only resources for the given locale (default: '\x00\x00')z--typez-ttype_z7Show only resources of the given type (default: public)z--idid_zJResolve the given ID for the given locale and package. Provide the hex ID!z--list-packageszList all package names and exit)is_flagdefaultr   z--list-localesz--list-typeszList all types and exitc
                 N	   ddl m}
m}m} |r*| r(t	          j        d           t          j        d           | s*|s(t	          j        d           t          j        d           | r| }n|}|
                    |          }|dk    rT|	                    |          }|
                                }|s(t	          j        d           t          j        d           n|dk    rzt          |d	          5 }|                    |                                          }|s(t	          j        d
           t          j        d           ddd           n# 1 swxY w Y   n(t	          j        d           t          j        d           |rS|d         dk    r
|dd         }	 t          |d          }nF# t           $ r9 t#          d                    |                     t          j        d           Y nw xY w|                    |          }|s#t#          d           t          j        d           t#          d                    ||                     t#                       |                    |          D ]P\  }}t#          d                    |                                s|                                nd|                     Qt          j        d           |rHt#          d                    |                                                     t          j        d           |r|                                D ]c}t#          d|           t#          d                    t3          d t5          |                    |                                                   dt          j        d           |	r|                                D ]}t#          d|           t5          |                    |                    D ]}t#          d                    |dk    rdn|                     t#          d                    t3          dj        t5          |                    ||                                                   t          j        d           t;          |||||           dS )z
    Decode resources.arsc either directly from a given file or from an APK.

    Example:

        >>> androguard arsc app.apk
    r   )	androconfapkr,   r$   r%   r&   APKz*The APK does not contain a resources file!ARSCrbz'The resources file seems to be invalid!NzUnknown file type!@   zBID '{}' could not be parsed! have you supplied the correct hex ID?z!Specified resource was not found!z@{:08x} resolves to '{}'z	{} = '{}'z	<default>
zIn Package:c                 <    | dk    rdnd                     |           S )N  z
  \x00\x00z  {})format)xs    r   <lambda>zarsc.<locals>.<lambda>  s&     J +N!'q!1!1 r   z  In Locale: {}r;   z\x00\x00z    {})outppackagetyplocale)androguard.corer2   r3   r,   r   infor(   r)   
is_androidr4   get_android_resourceserroropen
ARSCParserreadint
ValueErrorr'   r<   get_resource_xml_nameget_resolved_res_configs
is_defaultget_qualifierjoinget_packages_namesmapsortedget_locales	get_typesr   )r   r!   r*   r@   rB   r-   r.   list_packageslist_locales
list_typesr2   r3   r,   fnameret_typeaarscobjfpi_idnameconfigentryps                          r   arscrd   b   s=   \ 5444444444  X	
 	
 	
 	 % ./// ##E**H5GGENN))++ 	LEFFFHQKKK	V		% 	"oobggii00G FGGG		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	)***
 $q6S==abb'C	sB<<DD 	 	 	T[[   
 HQKKKKK	 ,,T22 	5666HQKKK(//d;;<<< %==dCC 
	 
	MFE""  &0022),,...( 	 	 	 	 	 dii224455666 ++-- 	 	A-###		 
 w2215566 	 	    	 ++-- 	 	A-### !4!4Q!7!788  %,,(.*(<(<&   
 II$O"7#4#4Q#?#?@@      	fg5     s&   /AEEEF, ,A G/.G/)r   r   r   zAPK to parse (legacy option))r    r"   zNoutput directory. If the output folder already exsist, it will be overwritten!)r"   r   z--formatz-fformat_zzAdditionally write control flow graphs for each method, specify the format for example png, jpg, raw (write dot file), ...)pngjpgraw)r   r    z--jarz-jz Use DEX2JAR to create a JAR filez--limitz6Limit to certain methods only by regex (default: '.*')z--decompilerz-dz)Use a different decompiler (default: DAD)c           	         ddl m} |r1| r/t          dt          j                   t          j        d           | s1|s/t          dt          j                   t          j        d           | r| }n|}|                                }	t          |d          5 }
|	                    ||
	                                           ddd           n# 1 swxY w Y   t          ||	|||||           dS )	zo
    Decompile an APK and create Control Flow Graphs.

    Example:

        >>> androguard resources.arsc
    r   )sessionr$   )filer%   r&   r6   N)
androguardrj   r'   r(   stderrr)   r   rH   r   rJ   r   )r   r!   r*   re   jarlimit
decompilerrj   rZ   sfds              r   	decompilers   %  sI   j #"""""  +	
 	
 	
 	

 	 % (sz:::: A	eT		  b	eRWWYY                             %FE3
GLLLLLs   )CCCz--hashhash_)md5sha1sha256sha512rv   zFingerprint Hash algorithm)r    r0   show_defaultr   z--allz-aprint_all_hasheszPrint all supported hashes)r/   r0   ry   r   z--showz-szLAdditionally of printing the fingerprints, show more certificate informationr3   )nargsr    c                 *    t          || ||           dS )z<Return the fingerprint(s) of all certificates inside an APK.N)r   )rt   rz   showr3   s       r   signr   s  s     D 3/66666r   apksc                     ddl m} t          j        d           t	                      }| D ]} ||          ||<   t          t          j        |d                     dS )zpPrints the packageName/versionCode/versionName per APK as JSON.
    
    :param apks: list of apk filepaths
    r   )	get_apkidAPKID   )indentN)androguard.core.apkr   r   debugdictr'   jsondumps)r   r   resultsr3   s       r   apkidr     st     .-----
LffG & & y~~	$*WQ
'
'
'(((((r   z	--sessionz2Previously saved session to load instead of a file)r0   r"   r    rj   c                 &    t          | |           dS )zOpen a IPython Shell and start reverse engineering.
    
    :param session: session file to restore
    :param apk: apk filename to analyze, if session not set
    N)r
   )rj   r3   s     r   analyzer     s    $ 7C     r   z--offsetz,Offset to start dissassembly inside the file)r0   r    r   z--sizez<Number of bytes from offset to disassemble, 0 for whole fileDEX)r    c                 (    t          | ||           dS )zH
    Disassemble Dalvik Code with size SIZE starting from an offset
    N)r   )offsetsizedexs      r   disassembler     s    . &$$$$$$r   z-mz	--modulesz"A list of modules to load in frida)multipler0   r   z--enable-uiz	Enable UIc                 *    t          | |d|           dS )a"  
    Push an APK on the phone and start to trace all interesting methods from the modules list

    Example:

        >>> androguard trace test.APK -m "ipc/*"  -m "webviews/*" -m "modules/**"
        >>> androguard trace test.APK -m "ipc/*"  -m "webviews/*" -m "modules/**" --enable-ui
    FNr   )r3   modules	enable_uis      r   tracer     s    : C%33333r   package_name)r0   r"   c                 (    t          | |d           dS )z
    Start dynamically an installed APK on the phone and start to trace all interesting methods from the modules list

    Example:

        >>> androguard dtrace package_name -m "ipc/*"  -m "webviews/*" -m "modules/**"
    TNr   r   r   s     r   dtracer     s    * L'400000r   z2androguard/pentest/modules/helpers/dump/dexdump.jsc                 &    t          | |           dS )zz
    Start and dump dynamically an installed APK on the phone

    Example:

        >>> androguard dump package_name
    N)r	   r   s     r   dumpr     s    * <)))))r   c                 :    t          j        | |t                    S )zWrapper around nx.write_gml)
stringizer)nx	write_gmlstr)Gpaths     r   
_write_gmlr   -  s    <4C0000r   c                     ddl }t          |d          5 }|                    | ||j                   ddd           dS # 1 swxY w Y   dS )zWrapper around pickle dumpr   Nwb)picklerH   r   HIGHEST_PROTOCOL)r   r   r   fs       r   _write_gpickler   2  s    MMM	dD		 3QAq&12223 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3s   ?AAc                     ddl }t          |d          5 }|                    | |           ddd           dS # 1 swxY w Y   dS )zWrapper around yaml dumpr   Nw)yamlrH   r   )r   r   r   r   s       r   _write_yamlr   :  s    KKK	dC A		!Q                 s   9= =)gmlgexfgraphmlnetzcallgraph.gmlz!Filename of the output graph file)r0   r   z--output-type)case_sensitiver   zType of the graph to output )r    r0   r   z;instead of saving the graph file, render it with matplotlib)r0   r/   r   z--classnamez.*zRegex to filter by classnamez--methodnamezRegex to filter by methodnamez--descriptorzRegex to filter by descriptorz--accessflagzRegex to filter by accessflagz--no-isolatedz'Do not store methods which has no xrefsc	                 j   ddl m}	 ddlm}
 ddlm}  ||           \  }}}t          |
|                                |                                z   |	                                z   |
                                z             }t          |          }|                    ||||||          }|r*	 ddl}ddlm} n-# t           $ r  t#          d           t%                       Y nw xY wt'          j        |          }g }g }|D ]=}t+          ||	          r|                    |           (|                    |           >t'          j        ||d|           t'          j        ||d	|           t'          j        ||d
d           t'          j        ||dd |j        D                        |                                 |                                 dS |                                }|t<          vr't#          d| d           t?          j        d           t=          |         ||           dS )z^
    Create a call graph based on the data of Analysis and export it into a graph format.
    r   )ExternalMethod)FormatClassToJava)
AnalyzeAPKNzoPyQt5 or matplotlib is not installed. In most OS you can install it by running 'pip install PyQt5 matplotlib'.
r)pos
node_colornodelistbg      ?T)widtharrows   c                 \    i | ])}||                                  d |j         d |j         *S ) )get_class_namer`   
descriptor).0ns     r   
<dictcomp>zcg.<locals>.<dictcomp>  sP        a&&((BB16BBALBB  r   )r   	font_sizelabelsz+Could not find a method to export files to !r%   ) !androguard.core.analysis.analysisr   androguard.core.bytecoder   androguard.miscr   rS   get_activitiesget_providersget_servicesget_receiverslistget_call_graphPyQt5matplotlib.pyplotpyplotImportErrorr'   r)   r   spring_layout
isinstanceappenddraw_networkx_nodesdraw_networkx_edgesdraw_networkx_labelsnodesdrawr~   lowerwrite_methodsr(   )r!   r*   output_typer~   	classname
methodnamer   
accessflagno_isolatedr   r   r   r\   ddxentry_points	callgraphr   pltr   internalexternalr   output_type_lowers                           r   cgr   M  s   B A@@@@@::::::******z%  HAq"	
//

	
..

	 //

	 L %%L!! I  3<	LLL+++++++ 	 	 	 C   FFFFF		
 y)) 	# 	#A!^,, #""""""""
33	
 	
 	
 	
 	33	
 	
 	
 	
 	y#SFFFF
 "  		
 	
 	
 	
 	







 (--//M11R>ORRR   HQKKK'(F;;;;;s   0
B; ;'C%$C%__main__)7__doc__r   r(   clicknetworkxr   logurur   androguard.sessionr   r   rl   r   androguard.cli.mainr   r   r   r	   r
   r   r   r   groupversion_option__version__optionr   commandPathargumentr,   rd   Choicers   r   r   r   r   r   rK   r   r   r   r   r   r   r   r   
write_gexfwrite_graphmlwrite_pajekr   keysr   __name__ r   r   <module>r     s9   H G  



            & & & & & &          	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 'j4555	  6 6  65 6 	44%	@	@	@	>   	N  
 	`  
 	44%	@	@	@  
1 1     .1> 	4	 	 	 	9      	4	   
.   	M  
 	B	   
		U  
 	*	   	*	   	"	  F F        	   tFR 	4%4	@	@	@	'   	4%4	@	@	@  
 
	   
A	+++	,	,   	+   	C  
 	4  
M M        ZMB 	999	:	:	%   	%   
   	
	4%4	@	@	@  
7 7     @7
 

	44%	@	@	@  
)S	 ) ) )  ) 	=	4	 	 	   
 		4%4	@	@	@	  !S !s ! ! !   ! 		7   		G   		4%4	@	@	@  % %	    &% 		4%4	@	@	@	   	-   		  	4 	4    (	4   
 	-  1 1   1   
 AB	-  * *   *1 1 1
3 3 3   	
   	4%4	@	@	@  
 	,	   	dd=--//00	G	G	G	'	   	F   	'  
 	(  
 	(  
 	(  
 	2	  Y< Y<          fY<x zKMMMMM r   