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

https://github.com/giantbranch/python-hacker-code · Python · 89 lines · 49 code · 16 blank · 24 comment · 9 complexity · efd295316189c3ea334276e6722379f9 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. #pylint: disable-msg=C0111
  23. import volatility.plugins.common as common
  24. import volatility.cache as cache
  25. import volatility.win32 as win32
  26. import volatility.utils as utils
  27. class Modules(common.AbstractWindowsCommand):
  28. """Print list of loaded modules"""
  29. def __init__(self, config, *args, **kwargs):
  30. common.AbstractWindowsCommand.__init__(self, config, *args, **kwargs)
  31. config.add_option("PHYSICAL-OFFSET", short_option = 'P', default = False,
  32. cache_invalidator = False, help = "Physical Offset", action = "store_true")
  33. def render_text(self, outfd, data):
  34. offsettype = "(V)" if not self._config.PHYSICAL_OFFSET else "(P)"
  35. self.table_header(outfd,
  36. [("Offset{0}".format(offsettype), "[addrpad]"),
  37. ("Name", "20"),
  38. ('Base', "[addrpad]"),
  39. ('Size', "[addr]"),
  40. ('File', "")
  41. ])
  42. for module in data:
  43. if not self._config.PHYSICAL_OFFSET:
  44. offset = module.obj_offset
  45. else:
  46. offset = module.obj_vm.vtop(module.obj_offset)
  47. self.table_row(outfd,
  48. offset,
  49. str(module.BaseDllName or ''),
  50. module.DllBase,
  51. module.SizeOfImage,
  52. str(module.FullDllName or ''))
  53. @cache.CacheDecorator("tests/lsmod")
  54. def calculate(self):
  55. addr_space = utils.load_as(self._config)
  56. result = win32.modules.lsmod(addr_space)
  57. return result
  58. class UnloadedModules(common.AbstractWindowsCommand):
  59. """Print list of unloaded modules"""
  60. def render_text(self, outfd, data):
  61. self.table_header(outfd, [
  62. ("Name", "20"),
  63. ('StartAddress', "[addrpad]"),
  64. ('EndAddress', "[addrpad]"),
  65. ('Time', "")])
  66. for drv in data:
  67. self.table_row(outfd, drv.Name, drv.StartAddress,
  68. drv.EndAddress, drv.CurrentTime)
  69. def calculate(self):
  70. addr_space = utils.load_as(self._config)
  71. kdbg = win32.tasks.get_kdbg(addr_space)
  72. for drv in kdbg.MmUnloadedDrivers.dereference().dereference():
  73. yield drv