
    j%                         d dl Z d dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
mZmZ d dlmZmZ d dlmZ d dlmZ dd	Zd
 Zd Zedk    r e             dS dS )    N)__version__)!extract_file_based_on_header_info(extract_all_files_from_central_directory)print_headers_of_filenameZipEntryshow_and_save_info_of_headers)save_data_to_filepretty_print_header)apk_tampering_check)get_manifest c                     |                                  D ]L\  }}t          |t                    rt          ||            -|r| d| n|}t	          | d|            Md S )N)
parent_keyz->z: )items
isinstancedictprint_nested_dictprint)
dictionaryr   keyvaluefull_keys        [/home/ubuntu/.hermes/hermes-agent/venv/lib/python3.11/site-packages/apkInspectorCLI/main.pyr   r      s     &&(( * *
UeT"" 	*e:@@@@@1;D*-----HX(((())))* *    c                      t           j                                       r gS t           j                                       r  fdt          j                   D             S g S )Nc                     g | ]t}|                     d           t          j                            t          j                            |                    Tt          j                            |          uS )z.apk)endswithospathisfilejoin).0fr   s     r   
<listcomp>z!get_apk_files.<locals>.<listcomp>   sw     N N N!

6""N')w~~bgll46K6K'L'LNT1%% N N Nr   )r   r   r    isdirlistdir)r   s   `r   get_apk_filesr'      s}    	w~~d Nv 
t		 NN N N Nrz$/?/? N N N 	N Ir   c            	      6   t          j        d          } |                     dd           |                     ddd           |                     d	d
dd           |                     dddd           |                     dddd           |                     dddd           |                     dddd           |                     dddd           |                     dddd           |                     d d!d"           |                     d#d$dd%           |                     d&d'dd(           |                                 }|j        r9d)}t          |           t          d*t                      t          d+           d S t          d,t                      t          d+           |j        |j        |                     d-           |j        d u |j        d u k    s|                     d.           |j        rt          |j                  }|st          d/|j                    d S |D ]}t          d0| d1           t          j                            |          d2         }t          |d3          5 }t          j        |          }|j        r|j        r|                    |j                  }|'t          d4|j         d5           	 d d d             d S |                    |j                  }	t+          ||	           t-          ||	|          d2         }
t/          d6|j         |
           n}|j        ro|                    |j                  }|'t          d4|j         d5           	 d d d             d S |                    |j                  }	t+          ||	           n|j        rt          d7t3          |j        j                              t9          ||                                d8         |                                d9         |          st          d:|            n|j        rIt?          |                                d9         |d;|j         d<           t          d=|j                     n1|j!        rIt?          |                                d8         |d>|j         d<           t          d?|j                     n|j"        ryt?          |                                d8         |d;|j         d<           t?          |                                d9         |d;|j         d<           t          d@|j                     na|j#        r|                    dA          }|                    dA          }	tI          j%        t-          ||	|          d2                   }
tM          |
          }t          dBdCdDE          5 }|'                    |           d d d            n# 1 swxY w Y   t          dF           n|j(        rtS          |j*        dG          }|dH         r%t          dI           tW          |dH                    nt          dJ           |dK         r%t          dL           tW          |dK                    n$t          dM           n| ,                                 d d d            n# 1 swxY w Y   d S |j        rt          |j        d3          5 }tM          tI          j%        |-                                                    }t          dBdCdDE          5 }|'                    |           d d d            n# 1 swxY w Y   t          dF           d d d            d S # 1 swxY w Y   d S d S )NNzapkInspector is a tool designed to provide detailed insights into the zip structure of APK files, offering the capability to extract content and decode the AndroidManifest.xml file.)descriptionz-apkzFA single APK to inspect or a directory where multiple APKs may reside.)helpz-fz
--filenamezFilename to provide info forz-llz--list-local
store_truez)List all files by name from local headers)actionr*   z-lcz--list-centralz4List all files by name from central directory headerz-laz
--list-allz<List all files from both central directory and local headersz-ez--exportzDExport to JSON. What you list from the other flags, will be exportedz-xz	--extractz4Attempt to extract the file specified by the -f flagz-xaz--extract-allzEAttempt to extract all files detected in the central directory headerz-mz
--manifestz*Extract and decode the AndroidManifest.xmlz-smz--specify-manifestz6Pass an encoded AndroidManifest.xml file to be decodedz-az	--analyzez3Check an APK for static analysis evasion techniquesz-vz	--versionzRetrieves version informationa  
#                 _     _____                                 _                
#                | |   |_   _|                               | |               
#    __ _  _ __  | | __  | |   _ __   ___  _ __    ___   ___ | |_   ___   _ __ 
#   / _` || '_ \ | |/ /  | |  | '_ \ / __|| '_ \  / _ \ / __|| __| / _ \ | '__|
#  | (_| || |_) ||   <  _| |_ | | | |\__ \| |_) ||  __/| (__ | |_ | (_) || |   
#   \__,_|| .__/ |_|\_\ \___/ |_| |_||___/| .__/  \___| \___| \__| \___/ |_|   
#         | |                             | |                                  
#         |_|                             |_|                                  
zapkInspector Library Version: z,Copyright 2025 erev0s <projects@erev0s.com>
zapkInspector Version: z0APK file or AndroidManifest.xml file is requiredziPlease specify an apk file with flag "-apk" or an AndroidManifest.xml file with flag "-sm", but not both.zNo APK files found at: zResults for :r   rbzIt appears that file: z3 is not among the entries of the central directory!
EXTRACTED_zNumber of entries: central_directorylocal_headerszExtraction successful for: localTz%Local headers list complete. Export: centralz&Central header list complete. Export: z1Central and local headers list complete. Export: zAndroidManifest.xmlzdecoded_AndroidManifest.xmlwzutf-8)encodingz9AndroidManifest was saved as: decoded_AndroidManifest.xmlFzzip tamperingzC
The zip structure was tampered with using the following patterns:
zINo files were detected were a tampering in the zip structure was present.zmanifest tamperingzJ

The AndroidManifest.xml file was tampered using the following patterns:
zGThe AndroidManifest.xml file does not seem to be tampered structurally.).argparseArgumentParseradd_argument
parse_argsversionr   apkspecify_manifesterrorr'   r
   r   r   splitextopenr   parsefilenameextract get_central_directory_entry_dictget_local_header_dictr   r   r	   extract_alllenr0   entriesr   to_dict
list_localr   exportlist_centrallist_allmanifestioBytesIOr   writeanalyzer   zipr   
print_helpread)parserargsmm	apk_filesr;   apk_nameapk_filezipentrycd_h_of_filelocal_header_of_fileextracted_datarM   xml_file
tamperingsenc_manifests                  r   mainrb   $   s
   $ 29 : : :F %mnnn
l1OPPP
~lItuuu
/ L^ _ _ _
|L[  ] ] ]
jc  e e e
k, FL M M M
| Ki j j j
l<I  K K K
3:rsss
k,R  T T T
k,EdeeeD| 	 	b			8w88999>???	
,7
,
,---	
:;;;xD19GHHH!T)tx4/?@@w	y 	y 	yx EO!$(++	 	6DH66777F :	( :	(C 5s 5 5 5666w'',,Q/Hc4 7(H#>(33= 5(T\ 5(#+#L#LT]#[#[L#+yt}yyyzzz7( 7( 7( 7( 7( 7( 7( 7( 7( ,4+I+I$-+X+X(-l<PQQQ%FxQegs%t%tuv%wN%&B4=&B&BNSSSS] ,(#+#L#LT]#[#[L#+yt}yyyzzz7( 7( 7( 7( 7( 7( 7( 7( 7(  ,4+I+I$-+X+X(-l<PQQQQ% %(YH4N4V0W0WYYZZZCHhN^N^N`N`atNuw  xH  xH  xJ  xJ  KZ  x[  ]e  f  f HFHFFGGG_ !(1(2B2B2D2D_2UW_ahjnjuw{|||O$+OOPPPP& (1(2B2B2D2DEX2Y[cenptp{  ~B  C  C  CP4;PPQQQQ] (1(2B2B2D2DEX2Y[celnrny{  A  A  A1(2B2B2D2D_2UW_ahjnjuw{|||[dk[[\\\\] (#+#L#LMb#c#cL+3+I+IJ_+`+`(%'Z9(DXZfgghij&l &lN+N;;H;S7SSS 1W_ x0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1UVVVV\ (!4X\5!I!IJ!/2 ldf f f)*_*EFFFFjkkk!"67 jnooo)*5I*JKKKKhiiii%%'''o7( 7( 7( 7( 7( 7( 7( 7( 7( 7( 7( 7( 7( 7( 7(:	( :	(v 
	 O$'.. 	O,#BJ|/@/@/B/B$C$CDDH3S7KKK )xx((() ) ) ) ) ) ) ) ) ) ) ) ) ) )MNNN		O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	OO Os}   A[.B[I[ X6[X[	X
B<[[	[	=A^]%^%])	)^,])	-^^^__main__)r   )r6   rN   r   apkInspectorr   r:   apkInspector.extractr   r   apkInspector.headersr   r   r   apkInspector.helpersr	   r
   apkInspector.indicatorsr   apkInspector.axmlr   r   r'   rb   __name__ r   r   <module>rl      s    				 				 / / / / / / l l l l l l l l c c c c c c c c c c G G G G G G G G 7 7 7 7 7 7 * * * * * ** * * *  uO uO uOp zDFFFFF r   