
    u%j)v                         d dl 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 d dlmZ d dlmZ d dlmZ d dlmZ  e j,                  d      Z G d	 d
e      Z G d de      Zy)    N)bytecode)unpack)
ARSCHeaderARSCResTablePackageARSCResTypeSpecARSCResTypeARSCResTableEntryARSCResTableConfig)StringBlock)complexToFloat)escapezpyaxmlparser.arscparserc                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd#dZd#dZd#dZd Zd#dZd#dZd#dZd#dZd#dZd#dZ G d de      Zd$dZd Zd%dZd#dZd Zd Z d$d Z!e"d!        Z#d$d"Z$y)&
ARSCParserz(
    Parser for resource.arsc files
    c           	         d| _         d | _        t        j                  |      | _        t        | j                        | _        t        d| j                  j                  d            d   | _	        i | _
        i | _        t        j                  t        j                        | _        t        j                  d       | _        t        j                  d       | _        d | _        | j                  j%                  | j                  j&                  | j                  j(                  z          | j                  j&                  | j                  j*                  z   }| j                  j-                         |t
        j.                  z
  k  rt        | j                        }|j&                  |j*                  z   |kD  ry |j0                  t2        j4                  k(  r)| j"                  st7        | j                  |      | _        n|j0                  t2        j8                  k(  rt;        | j                        | j                  k  sJ d       t=        | j                  |      }|j?                         }|j&                  |j*                  z   }g | j                  |<   | j                  j%                  |j                  j&                  |j@                  z          t        | j                        }|j0                  t2        j4                  k(  sJ d|j0                  z         t7        | j                  |      }| j                  j%                  |j                  j&                  |jB                  z          t        | j                        }	|	j0                  t2        j4                  k(  sJ d|	j0                  z         t7        | j                  |	      }
| j                  |   jE                  |       | j                  |   jE                  |       | j                  |   jE                  |
       tG        || j"                  ||
      }| j                  j%                  |j&                  |j(                  z   |j*                  z   |	j*                  z          | j                  j-                         |t
        j.                  z
  k  r4t        | j                        }tH        jK                  d	jM                  |             |j&                  |j*                  z   |kD  rn| j                  |   jE                  |       |j0                  t2        jN                  k(  r4| j                  |   jE                  tQ        | j                  |             n|j0                  t2        jR                  k(  rtU        | j                  |      }| j                  |   jE                  |       | j                  |   |   jW                  |jX                         tH        jK                  d
jM                  |jX                               g }t[        d|j\                        D ]\  }|j^                  dz  |z  |_/        |jE                  t        d| j                  j                  d            d   |j^                  f       ^ | j                  |   jE                  |       |D ]  \  }}| j                  ja                         r n|dk7  s(tc        | j                  ||      }| j                  |   jE                  |       |je                         sn| j                  j%                  |j&                          n4|j0                  t2        jf                  k(  rtH        ji                  d       n	 | j                  j%                  |j&                  |j*                  z          | j                  j-                         |t
        j.                  z
  k  r4| j                  j%                  |j&                  |j*                  z          | j                  j-                         |t
        j.                  z
  k  ry y )NFz<I   r   c                  4    t        j                  t              S N)collectionsdefaultdictset     e/home/ubuntu/.local/share/pipx/venvs/gplaycli/lib/python3.12/site-packages/pyaxmlparser/arscparser.py<lambda>z%ARSCParser.__init__.<locals>.<lambda>0   s    @W@WX[@\ r   c                  H    t        j                  t         j                        S r   )r   r   r   r   r   r   z%ARSCParser.__init__.<locals>.<lambda>2   s    K++K,C,CD r   zGot more packages than expectedz#Expected String Pool header, got %xzFound a header: {}z
Config: {}l      z<iz-RES_TABLE_LIBRARY_TYPE chunk is not supported)5analyzed_resolved_stringsr   
BuffHandlebuffr   headerr   readpackageCountpackagesvaluesr   r   resource_valuesresource_configsresource_keysstringpool_mainset_idxstartheader_sizesizeget_idxSIZEtypeconstRES_STRING_POOL_TYPEr   RES_TABLE_PACKAGE_TYPElenr   get_nametypeStrings
keyStringsappendPackageContextlogdebugformatRES_TABLE_TYPE_SPEC_TYPEr   RES_TABLE_TYPE_TYPEr   addconfigrange
entryCountmResIdendr	   is_weakRES_TABLE_LIBRARY_TYPEwarning)selfraw_buffdata_end
res_headercurrent_packagepackage_namepackage_data_endtype_sp_headermTableStringskey_sp_headermKeyStringspcpkg_chunk_header
a_res_typeentriesientryres_idates                      r   __init__zARSCParser.__init__$   sY   !%''1	 +"4):;A>*66{7N7NO + 7 78\ ](44DF# 			$++++dkk.E.EEF ;;$$t{{'7'77ii!X
%??#DII.J*//1H<%"<"<<TEYEY'2499j'I$E$@$@@4==)D,=,==`?``="5dii"L.779#-#3#3joo#E .0l+ 		!!/"8"8">">A\A\"\]!+DII!6%**e.H.HH P9N<O<OOPH +DII~ F 		!!/"8"8">">A[A["[\ *499 5$))U-G-GG O9M<N<NNOG)$))]C l+22?Cl+22=Al+22;?#OT5I5I$1;@ 		!!*"2"2Z5K5K"KnNaNa"adqdvdv"vw ii'')-=
-OO'1$))'<$II299:JKL'--0@0E0EEHXXMM,/667GH',,0N0NNl3::?499VX;YZ)..%2K2KK%0B%?
l3:::F--l;JGKKJL]L]^		,"5"5j6G6G"HI"$!&q**?*?!@ iA5D5K5Kj5X[\5\O2#NNF49J,KA,NP_PfPf+ghi l3::7C-4 AME6#yy}} %${&7		62&N $l ; B B3 G#&;;= %)II$5$5cii$@A  *..%2N2NN$ST  II%%&6&<&<?O?T?T&TUc ii'')-=
-OOh IIj..@AI ii!X
%??r   c                 6   | j                   ry d| _         | j                  D ]u  }i | j                  |<   d}|t        | j                  |         k  s1| j                  |   |   }t	        |t
              r |j                  t        j                  k(  r| j                  |   |dz      }|j                  j                         }| j                  |   j                  |dg i      }| j                  |   |dz      }d}|D ]j  \  }	}
|	dk7  s| j                  |   |dz   |z      }|| j                  |j                     |j                  <   |j                  | j                  |   |j                            |j!                         <   |j#                         dk7  r=|d   j%                  |j                         |j!                         |j                  f       |j                         |vrg ||j                         <   |j                         dk(  r%|d   j%                  | j'                  |             n3|j                         d	k(  r5|j)                         s|d	   j%                  | j+                  |             n|j                         d
k(  r4|j)                         s|d
   j%                  | j-                  |             n|j                         dk(  r$|d   j%                  | j/                  |             nm|j                         dk(  r$|d   j%                  | j1                  |             n6|j                         dk(  r#|d   j%                  | j3                  |             |dz  }m |d|z   dz
  z  }|dz  }|t        | j                  |         k  rEx y )NT      public   r   r   stringidboolintegercolordimen)r   r$   r%   r4   
isinstancer   r0   r1   r>   r@   get_language_and_region
setdefaultr&   rC   r(   get_type	get_value	get_indexr8   get_resource_string
is_complexget_resource_idget_resource_boolget_resource_integerget_resource_colorget_resource_dimen)rH   rM   nbr!   rU   localec_valuerV   nb_irX   rY   rZ   s               r   _analysezARSCParser._analyse   se   == MM ;	L(*DKK%Bs4==677|4R8fj1{{e&?&??%)]]<%@a%H
!+!2!2!J!J!L"&++l";"F"FvPXZ\~"^"&--"=b1f"E -4 )*ME6${&*mmL&A"q&4-&PVY 4 4SZZ @ARAR Sknkuku 2 2< @ATATAV WX[XeXeXg h#&==?b#8$+H$5$<$<)3)<)<)>),)5%6 $.#6#6#8#GEGGJ,?,?,A$B#-#6#6#8H#D$+H$5$<$<(,(@(@(E%G &0%8%8%:d%B+.>>+;(/(<(<,0,@,@,E)G &0%8%8%:f%D+.>>+;(/(>(>,0,B,B3,G)I &0%8%8%:i%G$+I$6$=$=(,(A(A#(F%H &0%8%8%:g%E$+G$4$;$;(,(?(?(D%F &0%8%8%:g%E$+G$4$;$;(,(?(?(D%F !%	S)*T a$hl*ao s4==677	;	r   c                 B    |j                         |j                         gS r   )rk   get_key_datarH   rZ   s     r   rm   zARSCParser.get_resource_string   s    !1!1!344r   c                     |j                         g}|j                  j                         dk(  r|j                  d       |S |j                  j                         dk(  r|j                  d       |S )Nr   falser^   truerk   keyget_datar8   rH   rZ   xs      r   ro   zARSCParser.get_resource_id   s`    ]]_77"HHW  WW1$HHVr   c                     |j                         g}|j                  j                         dk(  r|j                  d       |S |j                  j                         dk(  r|j                  d       |S )Nr   r}   r   r~   r   r   s      r   rp   zARSCParser.get_resource_bool   s`    ]]_77"HHW  WW2%HHVr   c                 V    |j                         |j                  j                         gS r   )rk   r   r   r{   s     r   rq   zARSCParser.get_resource_integer   s     !1!1!344r   c                     |j                   j                         }|j                         d|dz	  dz  |dz	  dz  |dz	  dz  |dz  fz  gS )Nz#%02x%02x%02x%02x            )r   r   rk   )rH   rZ   
entry_datas      r   rr   zARSCParser.get_resource_color   sb    WW%%'
MMO"d*"d*/T)d"	#% %
 	
r   c                 "   	 |j                         t        |j                  j                               t        j
                  |j                  j                         t        j                  z     gS # t        $ r t        j                  dt        |j                  j                               d|j                  j                         t        j                  z         |j                         |j                  j                         gcY S w xY w)Nz&Out of range dimension unit index for z: )
rk   r   r   r   r1   DIMENSION_UNITSCOMPLEX_UNIT_MASK
IndexErrorr:   r;   r{   s     r   rs   zARSCParser.get_resource_dimen  s    
	9"377#3#3#56))#''*:*:*<u?V?V*VW"Y 
  	9IIsww//12  "U%<%<<> ? MMOSWW%5%5%788		9s   A0A3 3BDDc                 
    ddgS )N r   r{   s     r   get_resource_stylezARSCParser.get_resource_style  s    Bxr   c                 H    t        | j                  j                               S )zp
        Retrieve a list of all package names, which are available
        in the given resources.arsc.
        )listr$   keysrH   s    r   get_packages_nameszARSCParser.get_packages_names  s    
 DMM&&())r   c                 n    | j                          t        | j                  |   j                               S )z
        Retrieve a list of all available locales in a given packagename.

        :param package_name: the package name to get locales of
        rx   r   r%   r   rH   rM   s     r   get_localeszARSCParser.get_locales  s*     	DKK-22455r   c                 t    | j                          t        | j                  |   |   j                               S )z
        Retrieve a list of all types which are available in the given
        package and locale.

        :param package_name: the package name to get types of
        :param locale: the locale to get types of (default: '  ')
        r   )rH   rM   ru   s      r   	get_typeszARSCParser.get_types&  s/     	DKK-f5::<==r   c                     | j                          d}|dz  }	 | j                  |   |   d   D ]  }|d|d   |d   |d   fz  z  } 	 |dz  }|j                  d	      S # t        $ r Y !w xY w)
a#  
        Get the XML (as string) of all resources of type 'public'.

        The public resources table contains the IDs for each item.

        :param package_name: the package name to get the resources for
        :param locale: the locale to get the resources for (default: '  ')
        '<?xml version="1.0" encoding="utf-8"?>
<resources>
r_   z+<public type="%s" name="%s" id="0x%08x" />
r   r^   r`   </resources>
utf-8rx   r%   KeyErrorencoderH   rM   ru   r    rW   s        r   get_public_resourceszARSCParser.get_public_resources1  s     	9	[[.v6x@ &FaD!A$!J& & && 	  {{7##  		s   .A 	A*)A*c                 0   | j                          d}|dz  }	 | j                  |   |   d   D ]A  }t        t        |d   j                  d            r	d|d   z  }n|d   }|d|d   d	|d
z  }C 	 |dz  }|j                  d      S # t
        $ r Y !w xY w)a\  
        Get the XML (as string) of all resources of type 'string'.

        Read more about string resources:
        https://developer.android.com/guide/topics/resources/string-resource.html

        :param package_name: the package name to get the resources for
        :param locale: the locale to get the resources for (default: '  ')
        r   r   ra   r^   z<&>z<![CDATA[%s]]><string name="r   ">
</string>
r   r   )rx   r%   anymap__contains__r   r   )rH   rM   ru   r    rW   values         r   get_string_resourceszARSCParser.get_string_resourcesK  s     	9	[[.v6x@ Js1Q4,,e45,qt3EaDEQqT5IIJ 	  {{7##  		s   AB	 		BBc                    | j                          d}|dz  }| j                         D ]|  }|d|z  z  }| j                  |      D ]Y  }|dt        |      z  z  }|dz  }	 | j                  |   |   d   D ]  }|d|d   d	t        |d
         dz  } 	 |dz  }|dz  }[ |dz  }~ |dz  }|j                  d      S # t        $ r Y 4w xY w)z
        Get the XML (as string) of all resources of type 'string'.
        This is a combined variant, which has all locales and all package names
        stored.
        r   z<packages>
z<package name="%s">
z<locale value=%s>
r   ra   r   r   r   r^   r   r   z
</locale>
z</package>
z</packages>
r   )rx   r   r   reprr%   r   r   r   )rH   r    rM   ru   rW   s        r   get_strings_resourcesz ARSCParser.get_strings_resourcesh  s    	9 335 	#L-<<D**<8 &-V<<'![[6v>xH YQqT6RSTURV< XXY
 ((%& N"D!	#$ 	{{7##   s   5B==	C	C	c           	         | j                          d}|dz  }	 | j                  |   |   d   D ]7  }t        |      dk(  r|d|d   z  z  }|d|d   dt        |d         d	z  }9 	 |d
z  }|j                  d      S # t        $ r Y !w xY w)aV  
        Get the XML (as string) of all resources of type 'id'.

        Read more about ID resources:
        https://developer.android.com/guide/topics/resources/more-resources.html#Id

        :param package_name: the package name to get the resources for
        :param locale: the locale to get the resources for (default: '  ')
        r   r   rb   r^   z<item type="id" name="%s"/>
r   z<item type="id" name="r   z</item>
r   r   )rx   r%   r4   r   r   r   r   s        r   get_id_resourceszARSCParser.get_id_resources  s     	9	[[.v6t< Uq6Q;;qtDDDqtGMaPQd|U UD	U 	  {{7##  		s   AA? ?	B
Bc                     | j                          d}|dz  }	 | j                  |   |   d   D ]  }|d|d   d|d   dz  } 	 |d	z  }|j                  d
      S # t        $ r Y !w xY w)a\  
        Get the XML (as string) of all resources of type 'bool'.

        Read more about bool resources:
        https://developer.android.com/guide/topics/resources/more-resources.html#Bool

        :param package_name: the package name to get the resources for
        :param locale: the locale to get the resources for (default: '  ')
        r   r   rc   z<bool name="r   r   r^   z</bool>
r   r   r   r   s        r   get_bool_resourceszARSCParser.get_bool_resources  s     	9	[[.v6v> E1qtDDE
 	  {{7##  		   ,A 	A('A(c                     | j                          d}|dz  }	 | j                  |   |   d   D ]  }|d|d   d|d   dz  } 	 |d	z  }|j                  d
      S # t        $ r Y !w xY w)ae  
        Get the XML (as string) of all resources of type 'integer'.

        Read more about integer resources:
        https://developer.android.com/guide/topics/resources/more-resources.html#Integer

        :param package_name: the package name to get the resources for
        :param locale: the locale to get the resources for (default: '  ')
        r   r   rd   z<integer name="r   r   r^   z</integer>
r   r   r   r   s        r   get_integer_resourcesz ARSCParser.get_integer_resources  s     	9	[[.v6yA KqtQqTJJK
 	  {{7##  		r   c                     | j                          d}|dz  }	 | j                  |   |   d   D ]  }|d|d   d|d   dz  } 	 |d	z  }|j                  d
      S # t        $ r Y !w xY w)a_  
        Get the XML (as string) of all resources of type 'color'.

        Read more about color resources:
        https://developer.android.com/guide/topics/resources/more-resources.html#Color

        :param package_name: the package name to get the resources for
        :param locale: the locale to get the resources for (default: '  ')
        r   r   re   z<color name="r   r   r^   z	</color>
r   r   r   r   s        r   get_color_resourceszARSCParser.get_color_resources       	9	[[.v6w? G1Q41FFG
 	  {{7##  		r   c                     | j                          d}|dz  }	 | j                  |   |   d   D ]  }|d|d   d|d   dz  } 	 |d	z  }|j                  d
      S # t        $ r Y !w xY w)ag  
        Get the XML (as string) of all resources of type 'dimen'.

        Read more about Dimension resources:
        https://developer.android.com/guide/topics/resources/more-resources.html#Dimension

        :param package_name: the package name to get the resources for
        :param locale: the locale to get the resources for (default: '  ')
        r   r   rf   z<dimen name="r   r   r^   z	</dimen>
r   r   r   r   s        r   get_dimen_resourceszARSCParser.get_dimen_resources  r   r   c                     | j                          	 | j                  |   |   d   D ]  }|d   |k(  s|c S  	 y# t        $ r Y yw xY w)a7  
        Returns the tuple (resource_type, resource_name, resource_id)
        for the given resource_id.

        :param package_name: package name to query
        :param rid: the resource_id
        :param locale: specific locale
        :return: tuple of (resource_type, resource_name, resource_id)
        r_   r`   )NNNrx   r%   r   )rH   rM   ridru   rW   s        r   get_idzARSCParser.get_id
  s`     		[[.v6x@ Q43;H
    		s    : : : 	AAc                   0    e Zd ZdZddZd Zd Zd Zd Zy)	ARSCParser.ResourceResolverz*
        Resolves resources by ID
        Nc                      || _         || _        y r   )	resourceswanted_config)rH   android_resourcesr@   s      r   r[   z$ARSCParser.ResourceResolver.__init__"  s    .DN!'Dr   c                 D    g }| j                  ||| j                         |S r   )_resolve_into_resultr   )rH   rY   results      r   resolvez#ARSCParser.ResourceResolver.resolve&  s$    F%%ffd6H6HIMr   c                 |    | j                   j                  ||      }|r|D ]  \  }}| j                  |||        y y r   )r   get_res_configsput_ate_value)rH   r   rY   r@   configsrZ   s         r   r   z0ARSCParser.ResourceResolver._resolve_into_result+  sE    nn44VVDG#* <KFC&&vsF;< r   c                     |j                         rIg }|j                  ||f       |j                  j                  D ]  \  }}| j	                  |||d        y | j	                  ||j
                  |d       y )NT)complex_F)rn   r8   itemitemsput_item_valuer   )rH   r   rZ   r@   complex_array_r   s          r   r   z)ARSCParser.ResourceResolver.put_ate_value1  ss    ~~ "v}56"xx~~ TGAt''tVd'ST ##FCGGVe#Lr   c                 (   |j                         r?|j                         }|r,| j                  ||j                         | j                         y y |r |j	                  |j                                y |j	                  ||j                         f       y r   )is_referencer   r   r   r8   format_value)rH   r   r   r@   r   rY   s         r   r   z*ARSCParser.ResourceResolver.put_item_value:  sx      "--**,  MM$"3"3"56MM64+<+<+>"?@r   r   )	__name__
__module____qualname____doc__r[   r   r   r   r   r   r   r   ResourceResolverr     s"    		(	
	<	M	Ar   r   Nc                 P    t         j                  | |      }|j                  |      S r   )r   r   r   )rH   r   r@   resolvers       r   get_resolved_res_configsz#ARSCParser.get_resolved_res_configsH  s%    ..tV<$$r   c                    | j                          | j                  r| j                  S i }| j                         D ]  }i ||<   i }| j                  |   D ]  }|}|dk(  rd}i ||   |<   	 | j                  |   |   d   D ]$  }|d   dk(  sd ||   |   |d   <   |d   ||d   <   & 	 	 | j                  |   |   d   D ]  }|d   |v s|d   ||   |   ||d      <       || _        |S # t        $ r Y Ow xY w# t        $ r Y w xY w)N  DEFAULTr_   r   ra   r`   r^   )rx   r   r   r%   r   )rH   rrM   kru   v_localerW   s          r   get_resolved_stringszARSCParser.get_resolved_stringsL  sg   !!))) 335 	L AlOA++l3 !z)(H,.,)![[6v>xH +Q48+>BAlOH5ad;&'dAadG+![[6v>xH FQ419AB1AlOH5a!g>F!		4 "#      s0   ) C*
C*'C9C9*	C65C69	DDc                    | j                          |st        d      t        |t              st        d      || j                  vrt
        j                  d       g S | j                  |   }t        |      dkD  rh|rf||v r|||   fgS |rV|t        j                         k(  r?t
        j                  d       t        | j                  |   j                               d   gS g S t        |j                               S )a_  
        Return the resources found with the ID `rid` and select
        the right one based on the configuration, or return all if no configuration was set.

        But we try to be generous here and at least try to resolve something:
        This method uses a fallback to return at least one resource (the first one in the list)
        if more than one items are found and the default config is used and no default entry could be found.

        This is usually a bad sign (i.e. the developer did not follow the android documentation:
        https://developer.android.com/guide/topics/resources/localization.html#failing2)
        In practise an app might just be designed to run on a single locale and thus only has those locales set.

        You can disable this fallback behaviour, to just return exactly the given result.

        :param rid: resource id as int
        :param config: a config to resolve from, or None to get all results
        :param fallback: Enable the fallback for resolving default configuration (default: True)
        :return: a list of ARSCResTableConfig: ARSCResTableEntry
        z'rid' should be setz'rid' must be an intz6The requested rid could not be found in the resources.r^   zLNo default resource config could be found for the given rid, using fallback!r   )rx   
ValueErrorrg   intr&   r:   infor4   r
   default_configrG   r   r   )rH   r   r@   fallbackres_optionss        r   r   zARSCParser.get_res_configso  s    ( 	233#s#344d***HHMNI**3/{aF$V!4566f(:(I(I(KKjkT11#6<<>?BCC	))+,,r   c                     | j                          	 | j                  |   |   d   D ]  }|d   |k(  s|c S  y # t        $ r Y y w xY w)Nra   r   r   )rH   rM   nameru   rW   s        r   
get_stringzARSCParser.get_string  sV    	[[.v6x@ Q44<H  		s    9 9 9 	AAc                 L    	 | j                   |   |   |   S # t        $ r Y y w xY wr   )r(   r   )rH   rM   resource_typer   s       r   get_res_id_by_keyzARSCParser.get_res_id_by_key  s4    	%%l3MB3GG 		s    	##c                 @    | j                          | j                  |   S r   )rx   r$   r   s     r   	get_itemszARSCParser.get_items  s    }}\**r   c                 V   || j                         d   }t        j                  t              }t        | j                  |   j                               D ]Q  \  }}|j                         |k(  s||j                         |k(  s0||j                            j                  |       S |S )Nr   )	r   r   r   r   r'   r   get_package_namerj   extend)rH   rM   	type_namer   res_typer   s         r   get_type_configszARSCParser.get_type_configs  s    224Q7L((.!%d&;&;L&I&O&O&Q!R 	<Hg((*l:%-1B1B1D	1Qx((*+227;	<
 r   c                 Z   | j                  d      st        dj                  |             | dd } d}d| v r| j                  dd      \  }}n| }t	        |      dk7  rt        dj                  |            	 t        |d      |fS # t        $ r t        d	j                  |            w xY w)
a  
        Resolves an id from a binary XML file in the form "@[package:]DEADBEEF"
        and returns a tuple of package name and resource id.
        If no package name was given, i.e. the ID has the form "@DEADBEEF",
        the package name is set to None.

        Raises a ValueError if the id is malformed.

        :param name: the string of the resource, as in the binary XML file
        :return: a tuple of (resource_id, package_name).
        @z0Not a valid resource ID, must start with @: '{}'r^   N:r   z+Numerical ID is not 8 characters long: '{}'r   zID is not a hex ID: '{}')
startswithr   r<   splitr4   r   )r   packagerY   s      r   parse_idzARSCParser.parse_id  s     s#OVVW[\]] ABx$;"jja0OGVFv;!JQQRXYZZ	Hvr?G++ 	H7>>vFGG	Hs   8B $B*c                     |r+| j                  ||      \  }}}|sydj                  ||      S | j                         D ]"  }| j                  ||      \  }}}|s|}|}|} n |sydj                  |      S )a  
        Returns the XML name for a resource, including the package name if package is None.
        A full name might look like `@com.example:string/foobar`
        Otherwise the name is only looked up in the specified package and is returned without
        the package name.
        The same example from about without the package name will read as `@string/foobar`.

        If the ID could not be found, `None` is returned.

        A description of the XML name can be found here:
        https://developer.android.com/guide/topics/resources/providing-resources#ResourcesFromXml

        :param r_id: numerical ID if the resource
        :param package: package name
        :return: XML name identifier
        Nz@{}/{}z	@{}:{}/{})r   r<   r   )	rH   r_idr  resourcer   i_idpr   ns	            r   get_resource_xml_namez ARSCParser.get_resource_xml_name  s    " #';;w#= HdD??8T22,,. ![[D1
1dG HD "))'8TBBr   )r   r   )NT)%r   r   r   r   r[   rx   rm   ro   rp   rq   rr   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   objectr   r   r   r   r   r   r   r   staticmethodr  r  r   r   r   r   r       s    {BzAF55	
9*6	>$4$:$B$:$2$2$2$2 ((A6 (AT%!F)-V+
 H HB"Cr   r   c                   $    e Zd Zd Zd Zd Zd Zy)r9   c                 <    || _         || _        || _        || _        y r   )r)   rP   rR   rL   )rH   rL   r)   rP   rR   s        r   r[   zPackageContext.__init__  s"    .*&.r   c                 .    | j                   j                  S r   rL   rC   r   s    r   
get_mResIdzPackageContext.get_mResId	  s    ##***r   c                 &    || j                   _        y r   r  )rH   rC   s     r   
set_mResIdzPackageContext.set_mResId  s    &,#r   c                 6    | j                   j                         S r   )rL   r5   r   s    r   r   zPackageContext.get_package_name  s    ##,,..r   N)r   r   r   r[   r  r  r   r   r   r   r9   r9     s    /+-/r   r9   )loggingpyaxmlparserr   r   structr   pyaxmlparser.arscutilr   r   r   r   r	   r
   pyaxmlparser.stringblockr   pyaxmlparser.constants	constantsr1   pyaxmlparser.utilsr   xml.sax.saxutilsr   	getLoggerr:   r  r   r9   r   r   r   <module>r"     s[   $  !  H H 0 & - #g12^C ^CB/V /r   