
    Xf`                          d dl Z d dlZd dlmZmZmZmZmZmZ d dl	m
Z
mZmZmZ d dlmZ d dlmZmZmZ d dlmZ d dlmZ  e j        e          Z G d d	e
j        j                  ZdS )
    N)Dict	GeneratorListSetTupleOptional)
interfaces	renderers
exceptions	constants)requirements)intel	resourceslinear)format_hints)pslistc                   R   e Zd ZdZdZdZ ej        d          Ze	de
ej        j                 fd            Zd Zdeeddf         fd	Zd
edeeef         fdZe		 	 ddej        j        dededej        dee
e                  deeeeeef                  f         fd            ZdS )Stringsz]Reads output from the strings command and indicates which process(es) each string belongs to.)      r   r   r   r   s%   ^(?:\W*)([0-9]+)(?:\W*)(\w[\w\W]+)\n?returnc                     t          j        ddddg          t          j        dt          j        d          t          j        d	t          d
d          t          j        dd          gS )NkernelzWindows kernelIntel32Intel64)namedescriptionarchitecturesr   r   )r   pluginversionpidz8Process ID to include (all other processes are excluded)T)r   element_typer   optionalstrings_filezStrings file)r   r   )r   ModuleRequirementPluginRequirementr   PsListListRequirementintURIRequirement)clss    _/home/panchajanya/Development/work/volatility3/volatility3/framework/plugins/windows/strings.pyget_requirementszStrings.get_requirements   s     *,()4  
 *fmY   ( V	   '#  
 	
    c                     t          j        dt          fdt          j        fdt          fg|                                           S )NStringzPhysical AddressResult)r
   TreeGridstrr   Hex
_generator)selfs    r-   runzStrings.run0   s@    !_1<3CDxQToVOO
 
 	
r/   Nc              #     K   g }t          j                    }|                    | j        d         d          }|                                }d}|ry|dz  }	 |                     |          \  }}|                    ||f           n-# t          $ r  t          	                    d|            Y nw xY w|                                }|y| j
        j        | j        d                  }|                     | j
        |j        |j        | j        | j        d                   }	d}
d}t!          |          }|D ]\  }}|dz  }	 d	 |	|d
z	           D             }n# t"          t$          f$ r dg}Y nw xY wdt'          |d          t)          j        |          d                    |          ffV  ||z  dz  }t/          |d          |
k    r&t/          |d          }
|                     |d           dS )z&Generates results from a strings file.r%   rbr   r   z"Line in unrecognized format: line r   r"   )progress_callbackpid_listc                 >    g | ]\  }}|d z   t          |          z   S ):)hex).0r   offsets      r-   
<listcomp>z&Strings._generator.<locals>.<listcomp>W   s8       1?$D3JV,  r/      zFREE MEMORYzlatin-1z, d   zMatching strings in memoryN)r   ResourceAccessoropenconfigreadline_parse_lineappend
ValueErrorvollogerrorcontextmodulesgenerate_mapping
layer_namesymbol_table_name_progress_callbacklen
IndexErrorKeyErrorr4   r   r5   joinround)r7   string_listaccessor
strings_fplinecountrA   stringr   revmap	last_prog
line_countnum_stringsrevmap_listprogs                  r-   r6   zStrings._generator6   ss     /1 -//]]4;~#>EE
""$$ 	)QJEK!%!1!1$!7!7""FF#34444 K K KI%IIJJJJJK&&((D  	) %dk(&;<&&L$"5[' ' 
 
 	
+&&) 	L 	LNFF!OJ. CI&TV,CW   ) . . .,o. 	** $V,,IIk**    +c1DT1~~	))!$NN	''.JKKK'	L 	Ls$   /B 'B10B1 EE-,E-r\   c                     | j                             |          }|st          d          |                    dd          \  }}t	          |          |fS )zParses a single line from a strings file.

        Args:
            line: bytes of the line of a strings file (an offset and a string)

        Returns:
            Tuple of the offset and the string found at that offset
        z*Strings file contains invalid strings liner   r   )strings_patternsearchrK   groupr*   )r7   r\   matchrA   r^   s        r-   rI   zStrings._parse_linei   sZ     $++D11 	KIJJJQ**6{{F""r/   rN   rQ   symbol_tabler;   r<   c           	         t           j                            |          }|j        |         }t	                      }t          |t          j                  r|                    d|j	        d          D ]~}	|	\  }
}}}}t          |||z   d          D ]F}|                    |dz	  t                                }|                    d|
f           |||dz	  <   G|r ||
dz  |j	        z  d           t           j                            |||          D ]V} ||          sGd	}	 |j        }|                                }nU# t"          j        $ rC}t&                              d
                    ||j        |j                             Y d}~{d}~ww xY w|j        |         }t          |t0          j                  r|                    d|j	        d          D ]}	|	\  }}}
}}t          |||z   d          D ]N}|                    |dz	  t                                }|                    d|j         |
f           |||dz	  <   O|r ||
dz  |j	        z  d|j                    X|S )a4  Creates a reverse mapping between virtual addresses and physical
        addresses.

        Args:
            context: the context for the method to run against
            layer_name: the layer to map against the string lines
            symbol_table: the name of the symbol table for the provided layer
            progress_callback: an optional callable to display progress
            pid_list: a lit of process IDs to consider when generating the reverse map

        Returns:
            A mapping of virtual offsets to strings and physical offsets
        r   T)ignore_errorsi   rC   r   rD   zCreating reverse kernel mapUnknownz*Process {}: invalid address {} in layer {}NzProcess zCreating mapping for task )r   r(   create_pid_filterlayersdict
isinstancer   Intelmappingmaximum_addressrangegetsetaddlist_processesUniqueProcessIdadd_process_layerr   InvalidAddressExceptionrL   debugformatinvalid_addressrQ   r   LinearlyMappedLayer)r,   rN   rQ   rj   r;   r<   filterlayerreverse_mapmapvalrA   _mapped_offsetmapped_sizemaplayervalcur_setprocessproc_idproc_layer_nameexcp
proc_layers                         r-   rP   zStrings.generate_mappingy   s   , 00::z*7;vveU[)) 3	"--U-BRV-WW 
 
BH?=+x 0KVTT 5 5C)oocRi??GKK6 2333-4Kr	**$ %%#)>>5   "=77\  #" #" vg  "'G	!")"9*1*C*C*E*E%= ! ! !HOO ')=t   
 !! ")!@J!*f.HII "&0&8&8!;4 '9 ' ' " "F OUKM1fk8', -}{/JF( ( K K +6//-2:Msuu*U*U '%I0G%I%I6$R!" !" !" DKMR,? @ @0 " 1 1%+c\U5J$J$ZAX$Z$Z!" !" !"
 s   %EF9FF)NN)__name__
__module____qualname____doc___version_required_framework_versionrecompilerf   classmethodr   r	   configurationRequirementInterfacer.   r8   r   r   r6   bytesr*   rI   rN   ContextInterfacer4   r   ProgressCallbackr   r   r   rP    r/   r-   r   r      sk       ggH"+ bj!JKKO
j&>&S!T 
 
 
 [
,
 
 
1LIeT4&78 1L 1L 1L 1Lf# #%U
*; # # # #   9=(,N N#4N N 	N
 %5N 49%N 
c3uS#X''	(N N N [N N Nr/   r   )loggingr   typingr   r   r   r   r   r   volatility3.frameworkr	   r
   r   r   #volatility3.framework.configurationr   volatility3.framework.layersr   r   r   volatility3.framework.renderersr   volatility3.plugins.windowsr   	getLoggerr   rL   pluginsPluginInterfacer   r   r/   r-   <module>r      s  
  				 > > > > > > > > > > > > > > > > N N N N N N N N N N N N < < < < < < A A A A A A A A A A 8 8 8 8 8 8 . . . . . .		8	$	$v v v v vj 0 v v v v vr/   