/volatility/volatility/plugins/gui/windows.py

https://github.com/Cisco-Talos/pyrebox · Python · 105 lines · 70 code · 12 blank · 23 comment · 18 complexity · e9e547192db7e8b30f60f6c4dcd8658f MD5 · raw file

  1. # Volatility
  2. # Copyright (C) 2007-2013 Volatility Foundation
  3. # Copyright (C) 2010,2011,2012 Michael Hale Ligh <michael.ligh@mnin.org>
  4. #
  5. # This file is part of Volatility.
  6. #
  7. # Volatility is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # Volatility is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with Volatility. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. import volatility.plugins.common as common
  21. import volatility.plugins.gui.messagehooks as messagehooks
  22. class WinTree(messagehooks.MessageHooks):
  23. """Print Z-Order Desktop Windows Tree"""
  24. def render_text(self, outfd, data):
  25. for winsta, atom_tables in data:
  26. for desktop in winsta.desktops():
  27. outfd.write("*" * 50 + "\n")
  28. outfd.write("Window context: {0}\\{1}\\{2}\n\n".format(
  29. winsta.dwSessionId, winsta.Name, desktop.Name))
  30. for wnd, level in desktop.windows(desktop.DeskInfo.spwnd):
  31. outfd.write("{0}{1} {2} {3}:{4} {5}\n".format(
  32. "." * level,
  33. str(wnd.strName or '') or "#{0:x}".format(wnd.head.h),
  34. "(visible)" if wnd.Visible else "",
  35. wnd.Process.ImageFileName,
  36. wnd.Process.UniqueProcessId,
  37. self.translate_atom(winsta, atom_tables, wnd.ClassAtom),
  38. ))
  39. class Windows(messagehooks.MessageHooks):
  40. """Print Desktop Windows (verbose details)"""
  41. def __init__(self, config, *args, **kwargs):
  42. common.AbstractWindowsCommand.__init__(self, config, *args, **kwargs)
  43. # Filter specific processes
  44. config.add_option('PID', short_option='p', default=None,
  45. help='Operate on these Process IDs (comma-separated)',
  46. action='store', type='str')
  47. def render_text(self, outfd, data):
  48. if self._config.PID:
  49. wanted_pids = [int(pid) for pid in self._config.PID.split(',')]
  50. else:
  51. wanted_pids = None
  52. for winsta, atom_tables in data:
  53. for desktop in winsta.desktops():
  54. outfd.write("*" * 50 + "\n")
  55. outfd.write("Window context: {0}\\{1}\\{2}\n\n".format(
  56. winsta.dwSessionId, winsta.Name, desktop.Name))
  57. for wnd, _level in desktop.windows(desktop.DeskInfo.spwnd):
  58. # Is this a process we want?
  59. if wanted_pids and not wnd.Process.UniqueProcessId in wanted_pids:
  60. continue
  61. outfd.write("Window Handle: #{0:x} at {1:#x}, Name: {2}\n".format(
  62. wnd.head.h, wnd.obj_offset, str(wnd.strName or '')
  63. ))
  64. outfd.write("ClassAtom: {0:#x}, Class: {1}\n".format(
  65. wnd.ClassAtom,
  66. self.translate_atom(winsta, atom_tables, wnd.ClassAtom),
  67. ))
  68. outfd.write("SuperClassAtom: {0:#x}, SuperClass: {1}\n".format(
  69. wnd.SuperClassAtom,
  70. self.translate_atom(winsta, atom_tables, wnd.SuperClassAtom),
  71. ))
  72. outfd.write("pti: {0:#x}, Tid: {1} at {2:#x}\n".format(
  73. wnd.head.pti.v(),
  74. wnd.Thread.Cid.UniqueThread,
  75. wnd.Thread.obj_offset,
  76. ))
  77. outfd.write("ppi: {0:#x}, Process: {1}, Pid: {2}\n".format(
  78. wnd.head.pti.ppi.v(),
  79. wnd.Process.ImageFileName,
  80. wnd.Process.UniqueProcessId,
  81. ))
  82. outfd.write("Visible: {0}\n".format("Yes" if wnd.Visible else "No"))
  83. outfd.write("Left: {0}, Top: {1}, Bottom: {2}, Right: {3}\n".format(
  84. wnd.rcClient.left,
  85. wnd.rcClient.top,
  86. wnd.rcClient.right, wnd.rcClient.bottom
  87. ))
  88. outfd.write("Style Flags: {0}\n".format(wnd.style))
  89. outfd.write("ExStyle Flags: {0}\n".format(wnd.ExStyle))
  90. outfd.write("Window procedure: {0:#x}\n".format(
  91. wnd.lpfnWndProc,
  92. ))
  93. outfd.write("\n")