-
Notifications
You must be signed in to change notification settings - Fork 20
/
profiles.py
59 lines (43 loc) · 1.61 KB
/
profiles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
"""Windows user profiles collector."""
from winregrc import interface
class UserProfile(object):
"""User profile.
Attributes:
profile_path (str): path of the users profile.
security_identifier (str): security identifier of the user.
"""
def __init__(self, security_identifier, profile_path):
"""Initializes an user profile.
Args:
security_identifier (str): security identifier of the user.
profile_path (str): path of the users profile.
"""
super(UserProfile, self).__init__()
self.profile_path = profile_path
self.security_identifier = security_identifier
class UserProfilesCollector(interface.WindowsRegistryKeyCollector):
"""Windows user profiles collector."""
_PROFILE_LIST_KEY_PATH = (
'HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\'
'ProfileList')
def _CollectUserProfiles(self, profile_list_key):
"""Collects user profiles.
Args:
profile_list_key (dfwinreg.WinRegistryKey): profile list Windows Registry.
Yields:
UserProfile: an user profile.
"""
for subkey in profile_list_key.GetSubkeys():
profile_image_path = self._GetValueFromKey(subkey, 'ProfileImagePath')
yield UserProfile(subkey.name, profile_image_path)
def Collect(self, registry):
"""Collects user profiles.
Args:
registry (dfwinreg.WinRegistry): Windows Registry.
Yields:
UserProfile: an user profile.
"""
profile_list_key = registry.GetKeyByPath(self._PROFILE_LIST_KEY_PATH)
if profile_list_key:
yield from self._CollectUserProfiles(profile_list_key)