
    u%j                        d dl mZ d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	Z	 e	j                  d      Zd Z G d	 d
e      Z G d de      Zd Z G d de      Z G d de      Z G d de      ZeZd Zd Zd Zd Z G d de      Zy)    )print_function)absolute_import)str)object)unpackpackNzpyaxmlparser.bytecodec                 H    t         j                  d| z          t        d      )NzError : oops)logwarning	Exception)msgs    c/home/ubuntu/.local/share/pipx/venvs/gplaycli/lib/python3.12/site-packages/pyaxmlparser/bytecode.pyExitr      s    KK
S !
F
    c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	SVc                 N    || _         t        | j                   |      d   | _        y Nr   )	_SV__sizer   
_SV__valueselfsizebuffs      r   __init__zSV.__init__   s     dkk403r   c                 B    t        | j                  | j                        S N)r   r   r   r   s    r   _getzSV._get   s    DKK..r   c                      d| j                   z  S )Nz0x%xr   r   s    r   __str__z
SV.__str__   s    $$r   c                     | j                   S r   r"   r   s    r   __int__z
SV.__int__       ||r   c                 "    | j                         S r   r    r   s    r   get_value_buffzSV.get_value_buff"       yy{r   c                     | j                   S r   r"   r   s    r   	get_valuezSV.get_value%   r&   r   c                     || _         y r   r"   r   attrs     r   	set_valuezSV.set_value(   s	    r   N)
__name__
__module____qualname__r   r    r#   r%   r)   r,   r0    r   r   r   r      s%    4/%r   r   c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	SVsc                 f    || _         |j                  t        | j                   |            | _        y r   )
_SVs__size_maker   _SVs__value)r   r   ntupler   s       r   r   zSVs.__init__.   s$    ||F4;;$=>r   c                     g }| j                   j                  D ]'  }|j                  t        | j                   |             ) t	        | j
                  g| S r   )r:   _fieldsappendgetattrr   r8   )r   lis      r   r    zSVs._get3   sK    %% 	/AHHWT\\1-.	/DKK$!$$r   c                 T    | j                   j                  D cg c]  }| c}S c c}w r   )r:   r=   )r   xs     r   _exportzSVs._export9   s     <<//0a000s   	%c                 "    | j                         S r   r(   r   s    r   r)   zSVs.get_value_buff<   r*   r   c                     | j                   S r   )r:   r   s    r   r,   zSVs.get_value?   r&   r   c                 F     | j                   j                  di || _         y )Nr4   )r:   _replacer.   s     r   r0   zSVs.set_valueB   s    ,t||,,4t4r   c                 6    | j                   j                         S r   )r:   r#   r   s    r   r#   zSVs.__str__E   s    ||##%%r   N)
r1   r2   r3   r   r    rD   r)   r,   r0   r#   r4   r   r   r6   r6   ,   s%    ?
%15&r   r6   c                    t        | t              rt        | d      S t        | t              r
t               S t        | t              rt        d|       S | 
t               S t        | t              r| S | j                         S )zj
    Convert a object to a bytearray or call get_raw() of the object
    if no useful type was found.
    zUTF-8z<L)
isinstancer   	bytearrayboolintr   get_raw)objs    r   object_to_bytesrQ   I   sk    
 #sg&&	C	{	C	D#	{	C	#
{{}r   c                       e Zd Zd Zy)MethodBCc                 ,     t        | d|z                 y )Nshow_)r?   )r   values     r   showzMethodBC.show^   s    &go&(r   N)r1   r2   r3   rW   r4   r   r   rS   rS   \   s    )r   rS   c                       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 Zd Zd Zd Zd Zd Zd Zd Zy)
BuffHandlez|
    BuffHandle is a wrapper around bytes.
    It gives the ability to jump in the byte stream, just like with BytesIO.
    c                 2    t        |      | _        d| _        y r   )rL   _BuffHandle__buff_BuffHandle__idxr   r   s     r   r   zBuffHandle.__init__h   s    o
r   c                      | j                   |   S )z
        Get the byte at the position `item`

        :param int item: offset in the buffer
        :returns: byte at the position
        :rtype: int
        r[   )r   items     r   __getitem__zBuffHandle.__getitem__l   s     {{4  r   c                 "    | j                         S r   r   r   s    r   __len__zBuffHandle.__len__v   r*   r   c                 ,    t        | j                        S )zG
        Get the total size of the buffer

        :rtype: int
        )lenr[   r   s    r   r   zBuffHandle.sizey   s     4;;r   c                 "    | j                         S )z(
        Alias for :meth:`size`
        rc   r   s    r   length_buffzBuffHandle.length_buff   s     yy{r   c                     || _         y)z]
        Set the current offset in the buffer

        :param int idx: offset to set
        Nr\   r   idxs     r   set_idxzBuffHandle.set_idx   s     
r   c                     | j                   S )zK
        Get the current offset in the buffer

        :rtype: int
        rj   r   s    r   get_idxzBuffHandle.get_idx        zzr   c                 .    | xj                   |z  c_         y)zi
        Advance the current offset by `idx`

        :param int idx: number of bytes to advance
        Nrj   rk   s     r   add_idxzBuffHandle.add_idx   s     	

c
r   c                     | j                   S )zA
        Alias for :meth:`get_idx`.

        :rtype: int
        rj   r   s    r   tellzBuffHandle.tell   rp   r   c                 (    | j                  |      }|S )z
        Read a String with length `size` at the current offset

        :param int size: length of the string
        :rtype: bytearray
        )read)r   r   datas      r   readNullStringzBuffHandle.readNullString   s     yyr   c                 N    | j                   | j                  | j                  |z    S )z
        Read bytes with length `size` without incrementing the current offset

        :param int size: length to read in bytes
        :rtype: bytearray
        )r[   r\   r   r   s     r   read_bzBuffHandle.read_b   s"     {{4::djj4&788r   c                 $    | j                  |      S )z*
        Alias for :meth:`read_b`
        )r{   rz   s     r   peekzBuffHandle.peek   s     {{4  r   c                 &    | j                   |||z    S )z
        Read bytes from the given offset with length `size` without incrementing
        the current offset

        :param int offset: offset to start reading
        :param int size: length of bytes to read
        :rtype: bytearray
        r_   )r   offsetr   s      r   read_atzBuffHandle.read_at   s     {{6&4-00r   c                 X    t        |t              r|j                  }| j                  |d S )z
        Read all bytes from the start of `off` until the end of the buffer

        :param int off: starting offset
        :rtype: bytearray
        N)rK   r   rV   r[   )r   offs     r   readatzBuffHandle.readat   s(     c2))C{{34  r   c                     t        |t              r|j                  }| j                  | j                  | j                  |z    }| xj                  |z  c_        |S )z
        Read from the current offset a total number of `size` bytes
        and increment the offset by `size`

        :param int size: length of bytes to read
        :rtype: bytearray
        )rK   r   rV   r[   r\   r   s      r   rv   zBuffHandle.read   sG     dB::D{{4::djj4&78

d
r   c                 F    | j                   t        | j                        k\  S )zl
        Test if the current offset is at the end or over the buffer boundary

        :rtype: bool
        )r\   rf   r[   r   s    r   endzBuffHandle.end   s     zzS---r   c                     | j                   S )zD
        Return the whole buffer

        :rtype: bytearray
        r_   r   s    r   get_buffzBuffHandle.get_buff   s     {{r   c                     || _         y)zx
        Overwrite the current buffer with the content of `buff`

        :param bytearray buff: the new buffer
        Nr_   r]   s     r   set_buffzBuffHandle.set_buff   s     r   c                 |    t        |d      5 }|j                  | j                         ddd       y# 1 sw Y   yxY w)z
        Save the current buffer to `filename`

        Exisiting files with the same name will be overwritten.

        :param str filename: the name of the file to save to
        wbN)openwriter[   )r   filenamefds      r   savezBuffHandle.save   s5     (D! 	"RHHT[[!	" 	" 	"s   2;N)r1   r2   r3   __doc__r   ra   rd   r   rh   rm   ro   rr   rt   rx   r{   r}   r   r   rv   r   r   r   r   r4   r   r   rY   rY   b   sf    
! 9!	1
! .	"r   rY   c                       e Zd Zd Zy)Buffc                 @    || _         || _        t        |      | _        y r   )r   r   rf   r   )r   r   r   s      r   r   zBuff.__init__  s    	I	r   Nr1   r2   r3   r   r4   r   r   r   r     s    r   r   c                 2    d| j                  dd      z   dz   S )z
    Transform a java class name into the typed variant found in DEX files.

    example::

        >>> FormatClassToJava('java.lang.Object')
        'Ljava/lang/Object;'

    :param i: the input class name
    :rtype: str
    L./;replacerA   s    r   FormatClassToJavar     s     3$$s**r   c                 X    | dd } | j                  dd      } | j                  dd      } | S )a  
    Transform a typed class name into a form which can be used as a python
    attribute

    example::

        >>> FormatClassToPython('Lfoo/bar/foo/Barfoo$InnerClass;')
        'Lfoo_bar_foo_Barfoo_InnerClass'

    :param i: classname to transform
    :rtype: str
    Nr   _$r   r   s    r   FormatClassToPythonr   &  s4     	
#2A			#sA			#sAHr   c                 r    | j                  dd      } | j                  dd      } | j                  dd      } | S )z
    Transform a (method) name into a form which can be used as a python
    attribute

    example::

        >>> FormatNameToPython('<clinit>')
        'clinit'

    :param i: name to transform
    :rtype: str
    < >r   r   r   r   s    r   FormatNameToPythonr   :  s9     	
		#rA			#rA			#sAHr   c                    | j                  dd      } | j                  dd      } | j                  dd      } | j                  dd      } | j                  dd      } | j                  dd      } | j                  d	d      } | S )
a  
    Format a descriptor into a form which can be used as a python attribute

    example::

        >>> FormatDescriptorToPython('(Ljava/lang/Long; Ljava/lang/Long; Z Z)V')
        'Ljava_lang_LongLjava_lang_LongZZV

    :param i: name to transform
    :rtype: str
    r   r   r   r   [() r   r   r   s    r   FormatDescriptorToPythonr   O  sy     	
		#sA			#rA			#rA			#rA			#rA			#rA			#rAHr   c                       e Zd Zd Zy)Nodec                 .    || _         || _        g | _        y r   )idtitlechildren)r   nss      r   r   zNode.__init__h  s    
r   Nr   r4   r   r   r   r   g  s    r   r   )
__future__r   r   builtinsr   r   structr   r   logging	getLoggerr   r   r   r6   rQ   rS   rY   r   	_Bytecoder   r   r   r   r   r4   r   r   <module>r      s    % &    g/0
 2&& &:&)v )f" f"R6  	+(*06 r   