
    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 j0                  e      Z G d d	e
j6                  j8                        Zy)
    N)Dict	GeneratorListSetTupleOptional)
interfaces	renderers
exceptions	constants)requirements)intel	resourceslinear)format_hints)pslistc                   J   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j4                  dee
e      deeeeeef      f   fd       Zy)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   sv     **,()4
 **fmmY (( V	 ''#
 	
    c                     t        j                  dt        fdt        j                  fdt        fg| j                               S )NStringzPhysical AddressResult)r
   TreeGridstrr   Hex
_generator)selfs    r-   runzStrings.run0   s>    !!_1<3C3CDxQToVOO
 	
r/   Nc           	   #     K   g }t        j                         }|j                  | j                  d   d      }|j	                         }d}|r@|dz  }	 | j                  |      \  }}|j                  ||f       |j	                         }|r@| j                  j                  | j                  d      }| j                  | j                  |j                  |j                  | j                  | j                  d         }	d}
d}t!        |      }|D ]  \  }}|dz  }	 |	|d	z	     D cg c]  \  }}|d
z   t#        |      z    }}}dt)        |d      t+        j,                        dj/                  |      ff ||z  dz  }t1        |d      |
kD  st1        |d      }
| j                  |d        y# t        $ r t        j                  d|        Y \w xY wc c}}w # t$        t&        f$ r dg}Y w xY ww)z&Generates results from a strings file.r%   rbr   r   z"Line in unrecognized format: line r   r"   )progress_callbackpid_list   :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hex
IndexErrorKeyErrorr4   r   r5   joinround)r7   string_listaccessor
strings_fplinecountoffsetstringr   revmap	last_prog
line_countnum_stringsr   revmap_listprogs                   r-   r6   zStrings._generator6   s    /1 --/]]4;;~#>E
""$QJEK!%!1!1$!7""FF#34 &&(D  %%dkk(&;<&&LL$$"55[[' ' 
 	
+&) 	LNFF!OJ.CI&TV,CW1?$D3JV,  	* $$V,IIk*  +c1DT1~	)!$N	''.JK'	L!  KA%IJK& ) .,o.sn   AG7'F1 9G7BG7G%G GAG7!G71!GG7GG7GG41G73G44G7rX   c                     | j                   j                  |      }|st        d      |j                  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searchrF   groupr*   )r7   rX   matchrZ   r[   s        r-   rD   zStrings._parse_linei   sL     $$++D1IJJQ*6{F""r/   rI   rL   symbol_tabler;   r<   c           	         t         j                  j                  |      }|j                  |   }t	               }t        |t        j                        r|j                  d|j                  d      D ]s  }	|	\  }
}}}}t        |||z   d      D ]:  }|j                  |dz	  t                     }|j                  d|
f       |||dz	  <   < |s[ ||
dz  |j                  z  d       u t         j                  j                  |||      D ]  } ||      rd	}	 |j                  }|j!                         }|j                  |   }t        |t0        j2                        sV|j                  d|j                  d      D ]  }	|	\  }}}
}}t        |||z   d      D ]G  }|j                  |dz	  t                     }|j                  d|j                   |
f       |||dz	  <   I |sh ||
dz  |j                  z  d|j                            |S # t"        j$                  $ rE}t&        j)                  d
j+                  ||j,                  |j.                               Y d}~\d}~ww xY w)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   r=   r   r?   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   InvalidAddressExceptionrG   debugformatinvalid_addressrL   r   LinearlyMappedLayer)r,   rI   rL   rg   r;   r<   filterlayerreverse_mapmapvalrZ   _mapped_offsetmapped_sizemaplayervalcur_setprocessproc_idproc_layer_nameexcp
proc_layers                         r-   rK   zStrings.generate_mappingy   s   , 00:z*7;veU[[)--U-B-BRV-W 
BH?=+x 0KVT 5C)oocRi?GKK6 23-4Kr	*5 %%#)>)>>5
 "==77\ #" g'G	!")"9"9*1*C*C*E ")!@J!*f.H.HI&0&8&8!;!;4 '9 ' "F OUKM1fk8', -}{/JF( K +6//-2:Msu*U ''/0G0G/H%I6$R!" DKMR,? @K  1 1%+c\U5J5J$J&@AXAX@Y$Z!""%#"J ; &== !HOO ')=)=t
 !!s   HI*%:I%%I*)NN)__name__
__module____qualname____doc___version_required_framework_versionrecompilerc   classmethodr   r	   configurationRequirementInterfacer.   r8   r   r   r6   bytesr*   rD   rI   ContextInterfacer4   r   ProgressCallbackr   r   r   rK    r/   r-   r   r      s   gH"+ bjj!JKO
j&>&>&S&S!T 
 
,
1LIeT4&78 1Lf# #%U
*; #   9=(,N##44N N 	N
 %55N 49%N 
c3uS#X''	(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   rG   pluginsPluginInterfacer   r   r/   r-   <module>r      sT   
  	 > > N N < A A 8 .			8	$vj  00 vr/   