-
Notifications
You must be signed in to change notification settings - Fork 20
/
application_identifiers.py
65 lines (48 loc) · 1.86 KB
/
application_identifiers.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
60
61
62
63
64
65
# -*- coding: utf-8 -*-
"""Windows application identifiers (AppID) collector."""
from winregrc import interface
class ApplicationIdentifier(object):
"""Application identifier.
Attributes:
description (str): description.
guid (str): identifier.
"""
def __init__(self, guid, description):
"""Initializes an application identifier.
Args:
guid (str): identifier.
description (str): description.
"""
super(ApplicationIdentifier, self).__init__()
self.description = description
self.guid = guid
class ApplicationIdentifiersCollector(interface.WindowsRegistryKeyCollector):
"""Windows application identifiers collector."""
_APPLICATION_IDENTIFIERS_KEY_PATH = (
'HKEY_LOCAL_MACHINE\\Software\\Classes\\AppID')
def _CollectApplicationIdentifiers(self, application_identifiers_key):
"""Collects Windows application identifiers (AppID).
Args:
application_identifiers_key (dfwinreg.WinRegistryKey): application
identifiers Windows Registry key.
Yields:
ApplicationIdentifier: an application identifier.
"""
for subkey in application_identifiers_key.GetSubkeys():
name = subkey.name.lower()
# Ignore subkeys that are not formatted as {%GUID%}
if len(name) == 38 and name[0] == '{' and name[37] == '}':
description = self._GetValueFromKey(subkey, '')
yield ApplicationIdentifier(name, description)
def Collect(self, registry):
"""Collects Windows application identifiers (AppID).
Args:
registry (dfwinreg.WinRegistry): Windows Registry.
Yields:
ApplicationIdentifier: an application identifier.
"""
application_identifiers_key = registry.GetKeyByPath(
self._APPLICATION_IDENTIFIERS_KEY_PATH)
if application_identifiers_key:
yield from self._CollectApplicationIdentifiers(
application_identifiers_key)