| Trees | Indices | Help | 
 | 
|---|
|  | 
  1  # Rekall Memory Forensics 
  2  # Copyright (C) 2007,2008 Volatile Systems 
  3  # Copyright (C) 2004,2005,2006 4tphi Research 
  4  # Copyright 2013 Google Inc. All Rights Reserved. 
  5  # 
  6  # Authors: 
  7  # {npetroni,awalters}@4tphi.net (Nick Petroni and AAron Walters) 
  8  # Michael Cohen <scudette@users.sourceforge.net> 
  9  # Mike Auty <mike.auty@gmail.com> 
 10  # 
 11  # This program is free software; you can redistribute it and/or modify 
 12  # it under the terms of the GNU General Public License as published by 
 13  # the Free Software Foundation; either version 2 of the License, or (at 
 14  # your option) any later version. 
 15  # 
 16  # This program is distributed in the hope that it will be useful, but 
 17  # WITHOUT ANY WARRANTY; without even the implied warranty of 
 18  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
 19  # General Public License for more details. 
 20  # 
 21  # You should have received a copy of the GNU General Public License 
 22  # along with this program; if not, write to the Free Software 
 23  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
 24  # 
 25   
 26  """ These are standard address spaces supported by Rekall Memory Forensics """ 
 27  import StringIO 
 28  import struct 
 29  import os 
 30  import weakref 
 31   
 32  from rekall import addrspace 
 33  from rekall import config 
 34   
 35   
 36  config.DeclareOption( 
 37      "-o", "--file_offset", 
 38      type="IntParser", help="A Relative offset for image file.") 
 39   
 40   
 42      """An address space which operated on a file like object.""" 
 43   
 44      __name = "filelike" 
 45   
 46      # We should be first. 
 47      order = 0 
 48   
 50          self.as_assert(base == None, "Base passed to FDAddressSpace.") 
 51          self.as_assert(fhandle is not None, 'file handle must be provided') 
 52   
 53          self.fhandle = fhandle 
 54          try: 
 55              self.fhandle.seek(0, 2) 
 56              self.fsize = self.fhandle.tell() 
 57          except IOError: 
 58              # We failed to seek to the end - this is usual with devices so we 
 59              # assume they are volatile to be safe. 
 60              self.fsize = 0 
 61              self.volatile = True 
 62              self.session.logging.warn( 
 63                  "Unable to determine file size, assuming file is volatile.") 
 64   
 65          self.offset = 0 
 66   
 67          super(FDAddressSpace, self).__init__(**kwargs) 
 68   
 70          length = int(length) 
 71          addr = int(addr) 
 72          try: 
 73              self.fhandle.seek(addr) 
 74              data = self.fhandle.read(length) 
 75   
 76              return data + addrspace.ZEROER.GetZeros(length - len(data)) 
 77          except IOError: 
 78              return addrspace.ZEROER.GetZeros(length) 
 79   
 84   
 89   
 94   
 96          self.fhandle.close() 
 97   
101   
102   
104      """ This is a direct file AS. 
105   
106      For this AS to be instantiated, we need 
107   
108      1) A valid config.filename 
109   
110      2) no one else has picked the AS before us 
111   
112      3) base == None (we dont operate on anyone else so we need to be 
113      right at the bottom of the AS stack.) 
114      """ 
115   
116      __name = "file" 
117   
118      # We should be the AS of last resort 
119      order = 100 
120   
121      # This address space handles images. 
122      __image = True 
123   
125          self.as_assert(base == None, 'Must be first Address Space') 
126   
127          self.session = session 
128          path = filename or (session and session.GetParameter("filename")) 
129          self.as_assert(path, "Filename must be specified in session (e.g. " 
130                         "session.SetParameter('filename', 'MyFile.raw').") 
131   
132          self.name = os.path.basename(path) 
133          self.fname = os.path.abspath(path) 
134          self.mode = 'rb' 
135   
136          if path.startswith(r"\\\\.\\"): 
137              raise RuntimeError( 
138                  "Unable to open a device without the win32file package " 
139                  "installed.") 
140   
141          try: 
142              fhandle = open(self.fname, self.mode) 
143          except (IOError, OSError) as e: 
144              raise addrspace.ASAssertionError("%s" % e) 
145   
146          self._closer = weakref.ref(self, lambda x: fhandle.close()) 
147   
148          super(FileAddressSpace, self).__init__( 
149              fhandle=fhandle, session=session, **kwargs) 
150   
151   
153      """An address space to add a constant offset.""" 
154   
155      __image = True 
156   
157      # Must come after all other address space. 
158      order = 120 
159   
161          super(GlobalOffsetAddressSpace, self).__init__(**kwargs) 
162          self.file_offset = self.session.GetParameter("file_offset") 
163   
164          self.as_assert(self.file_offset, "File offset not specified.") 
165          self.as_assert(self.base.__class__ is not GlobalOffsetAddressSpace, 
166                         "Can not stack on GlobalOffsetAddressSpace") 
167   
168          self.add_run(0, self.file_offset, self.base.end()) 
169   
170   
172      """This address space can be used to create new files. 
173   
174      NOTE: This does not participate in voting or gets automatically 
175      selected. It can only be instantiated directly. 
176      """ 
177   
179          self.fhandle.seek(addr) 
180          self.fhandle.write(data) 
181          self.fhandle.flush() 
182   
183          return len(data) 
184   
188   
192   
202   
203   
205   
207          self.as_assert(filename, "Filename must be specified.") 
208          self.name = os.path.abspath(filename) 
209          self.fname = self.name 
210          self.mode = mode 
211   
212          fhandle = open(self.fname, self.mode) 
213          self._closer = weakref.ref(self, lambda x: fhandle.close()) 
214   
215          super(WritableAddressSpace, self).__init__(fhandle=fhandle, **kwargs) 
216   
217   
219      """An address space which can be initialized from a file handle. 
220   
221      Note that file handle must be writable. 
222      """ 
223   
224   
237   
| Trees | Indices | Help | 
 | 
|---|
| Generated by Epydoc 3.0.1 on Mon Oct 9 03:29:36 2017 | http://epydoc.sourceforge.net |