/我手敲的代码(中文注释)/chapter11/volatility-2.3/build/lib/volatility/plugins/hibinfo.py

https://github.com/giantbranch/python-hacker-code · Python · 83 lines · 43 code · 14 blank · 26 comment · 5 complexity · 3a68eb8a47f71da95746c551d93e3c5b MD5 · raw file

  1. # Volatility
  2. #
  3. # Authors:
  4. # Mike Auty <mike.auty@gmail.com>
  5. #
  6. # This file is part of Volatility.
  7. #
  8. # Volatility is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License Version 2 as
  10. # published by the Free Software Foundation. You may not use, modify or
  11. # distribute this program under any other version of the GNU General
  12. # Public License.
  13. #
  14. # Volatility is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with Volatility. If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. import volatility.utils as utils
  23. import volatility.obj as obj
  24. import volatility.plugins.common as common
  25. import volatility.debug as debug
  26. import volatility.cache as cache
  27. import volatility.win32.tasks as tasks
  28. class HibInfo(common.AbstractWindowsCommand):
  29. """Dump hibernation file information"""
  30. @cache.CacheDecorator("tests/hibinfo")
  31. def calculate(self):
  32. """Determines the address space"""
  33. addr_space = utils.load_as(self._config)
  34. result = None
  35. adrs = addr_space
  36. while adrs:
  37. if adrs.__class__.__name__ == 'WindowsHiberFileSpace32':
  38. sr = adrs.ProcState.SpecialRegisters
  39. peb = obj.NoneObject("Cannot locate a valid PEB")
  40. # Find the PEB by cycling through processes. This method works
  41. # on all versions of Windows x86 and x64.
  42. for task in tasks.pslist(addr_space):
  43. if task.Peb:
  44. peb = task.Peb
  45. break
  46. result = {'header': adrs.get_header(),
  47. 'sr': sr,
  48. 'peb': peb,
  49. 'adrs': adrs }
  50. adrs = adrs.base
  51. if result == None:
  52. debug.error("Memory Image could not be identified or did not contain hiberation information")
  53. return result
  54. def render_text(self, outfd, data):
  55. """Renders the hiberfil header as text"""
  56. hdr = data['header']
  57. sr = data['sr']
  58. peb = data['peb']
  59. outfd.write("PO_MEMORY_IMAGE:\n")
  60. outfd.write(" Signature: {0}\n".format(hdr.Signature))
  61. outfd.write(" SystemTime: {0}\n".format(hdr.SystemTime))
  62. outfd.write("\nControl registers flags\n")
  63. outfd.write(" CR0: {0:08x}\n".format(sr.Cr0))
  64. outfd.write(" CR0[PAGING]: {0}\n".format((sr.Cr0 >> 31) & 1))
  65. outfd.write(" CR3: {0:08x}\n".format(sr.Cr3))
  66. outfd.write(" CR4: {0:08x}\n".format(sr.Cr4))
  67. outfd.write(" CR4[PSE]: {0}\n".format((sr.Cr4 >> 4) & 1))
  68. outfd.write(" CR4[PAE]: {0}\n".format((sr.Cr4 >> 5) & 1))
  69. outfd.write("\nWindows Version is {0}.{1} ({2})\n\n".format(peb.OSMajorVersion, peb.OSMinorVersion, peb.OSBuildNumber))