o
    �õ±jø  ã                   @   sT   d dl Z d dlT d dlmZ dd„ ZG dd„ de jƒZdd	„ Zed
kr(eƒ  dS dS )é    N)Ú*)Úhexdumpc                 C   s|   t | tƒr| S t | tƒr6| d d…  ¡ dkrt| dd … dƒS | d d…  ¡ dkr2t| dd … dƒS t| ƒS tdt| ƒ ƒ‚)Né   Ú0xé   Ú0bzUnknown integer format! %s)Ú
isinstanceÚintÚstrÚlowerÚ	ExceptionÚtype)Úx© r   ú‰/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/minidump/minidumpshell.pyÚargs2int   s   

r   c                   @   sÈ   e Zd ZdZdZdZdZdZdd„ Zdd„ Z	d	d
„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ ZdS )/ÚMinidumpShellzBWelcome to the minidump shell.   Type help or ? to list commands.
z[minidump] Nr   c                 C   s    t  |¡| _| j ¡  ¡ | _dS )zOpens minidump fileN)ÚMinidumpFileÚparseÚminiÚ
get_readerÚget_buffered_readerÚreader)ÚselfÚfilenamer   r   r   Údo_open   s   zMinidumpShell.do_openc                 C   ó$   | j jdurtt| j jƒƒ dS dS )z$Shows PEB information (if available)N)r   ÚpebÚprintr
   ©r   Úargsr   r   r   Údo_peb    ó   ÿzMinidumpShell.do_pebc                 C   ó\   | j jdurtt| j jƒƒ | j jdurtt| j jƒƒ | j jdur,tt| j jƒƒ dS dS )z+Lists all thread information (if available)N)r   Úthreadsr   r
   Ú
threads_exÚthread_infor   r   r   r   Ú
do_threads%   ó   ÿzMinidumpShell.do_threadsc                 C   r#   )zLists all memory segmentsN)r   Úmemory_segmentsr   r
   Úmemory_segments_64Úmemory_infor   r   r   r   Ú	do_memory.   r(   zMinidumpShell.do_memoryc                 C   ó@   | j jdurtt| j jƒƒ | j jdurtt| j jƒƒ dS dS )z?Lists all loaded and unloaded module information (if available)N)r   Úmodulesr   r
   Úunloaded_modulesr   r   r   r   Ú
do_modules7   ó
   ÿzMinidumpShell.do_modulesc                 C   r   )zShows sysinfo (if available)N)r   Úsysinfor   r
   r   r   r   r   Ú
do_sysinfo>   r"   zMinidumpShell.do_sysinfoc                 C   r   )z*Shows exception information (if available)N)r   Ú	exceptionr   r
   r   r   r   r   Údo_exceptionC   r"   zMinidumpShell.do_exceptionc                 C   r-   )zLists all comments (if any)N)r   Ú	comment_ar   r
   Ú	comment_wr   r   r   r   Údo_commentsH   r1   zMinidumpShell.do_commentsc                 C   r   )z Lists all handles (if available)N)r   Úhandlesr   r
   r   r   r   r   Ú
do_handlesO   r"   zMinidumpShell.do_handlesc                 C   r   )z+Lists all miscellaneous info (if available)N)r   Ú	misc_infor   r
   r   r   r   r   Údo_miscT   r"   zMinidumpShell.do_miscc                 C   s   dS )ÚQuitTr   r   r   r   r   Údo_quitZ   s   zMinidumpShell.do_quitc                 C   ó
   |   d¡S ©r=   N©r>   r   r   r   r   Údo_exit]   ó   
zMinidumpShell.do_exitc                 C   r?   r@   rA   r   r   r   r   Údo_q`   rC   zMinidumpShell.do_qc                 C   s   t |ƒ| _dS )zIChanges the hexdump print size to the given bytes/line size (default: 16)N)r   Úhexdump_size)r   Ú	printsizer   r   r   Údo_printsizee   s   zMinidumpShell.do_printsizec                 C   s<   | j  ¡ }| j jj}|| }dt|ƒt|ƒt|ƒf | _d S )Nz[%s %s+%s] )r   ÚtellÚcurrent_segmentÚstart_addressÚhexÚprompt)r   r    ÚposÚcurrent_segment_startÚsegment_relative_positionr   r   r   Úupdate_prompti   s   

 zMinidumpShell.update_promptc                 C   s*   | j  ¡ }|du rtdƒ tt|ƒƒ dS )zIShows/refreshes the current position in the process' virtual memory spaceNzRReader not yet positioned! Issue a "move" command with the desired memory address!)r   rH   r   rK   )r   r    r   r   r   r   Údo_tello   s   
zMinidumpShell.do_tellc                 C   s"   t |ƒ}| j |¡ |  d¡ dS )z>Sets the current position in the process' virtual memory spaceN)r   r   ÚmoverP   )r   ÚpositionrM   r   r   r   Údo_movev   s   zMinidumpShell.do_movec                 C   óB   t |ƒ}| j ¡ }| j |¡}tt|| jd|d�ƒ |  d¡ dS )zePerforms a read of 'count' bytes from the current position and updates the cursor with the bytes readÚ.©ÚlengthÚsepÚstartN)r   r   rH   Úreadr   r   rE   rP   ©r   ÚcountÚ
pos_beforeÚdatar   r   r   Údo_read|   ó
   
zMinidumpShell.do_readc                 C   ó4   | j  ¡ }td| ƒ tdt|ƒ ƒ |  d¡ dS )zÊReads a signed integer starting the current position and updates the cursor with the bytes read. The integer size is determined automatically by the processor architecture information from the dump fileúD: %súH: %sN)r   Úread_intr   rK   rP   ©r   r    r_   r   r   r   Údo_readi„   ó   
zMinidumpShell.do_readic                 C   rb   )zÍReads an unsigned integer starting the current position and updates the cursor with the bytes read. The integer size is determined automatically by the processor architecture information from the dump filerc   rd   N)r   Ú	read_uintr   rK   rP   rf   r   r   r   Ú	do_readui‹   rh   zMinidumpShell.do_readuic                 C   rU   )zYPerforms a read of 'count' bytes from the current position but doesn't update the cursor.rV   rW   N)r   r   rH   Úpeekr   r   rE   rP   r\   r   r   r   Údo_peek’   ra   zMinidumpShell.do_peek)Ú__name__Ú
__module__Ú__qualname__ÚintrorL   r   r   rE   r   r!   r'   r,   r0   r3   r5   r8   r:   r<   r>   rB   rD   rG   rP   rQ   rT   r`   rg   rj   rl   r   r   r   r   r      s6    		r   c                  C   sP   dd l } | jdd�}|jdddd� | ¡ }tƒ }|jr"| |j¡ | ¡  d S )Nr   zA parser for minidumnp files)Údescriptionz-fz--minidumpfilez&path to the minidump file of lsass.exe)Úhelp)ÚargparseÚArgumentParserÚadd_argumentÚ
parse_argsr   Úminidumpfiler   Úcmdloop)rs   Úparserr    Úshellr   r   r   Úmain›   s   r{   Ú__main__)	ÚcmdÚminidump.minidumpfileÚminidump.common_structsr   r   ÚCmdr   r{   rm   r   r   r   r   Ú<module>   s    
ÿ