-
Notifications
You must be signed in to change notification settings - Fork 23
/
UserAssist.cs
134 lines (111 loc) · 4.94 KB
/
UserAssist.cs
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text.RegularExpressions;
using ExtensionBlocks;
using Registry.Abstractions;
using RegistryPluginBase.Classes;
using RegistryPluginBase.Interfaces;
namespace RegistryPlugin.UserAssist
{
public class UserAssist : IRegistryPluginGrid
{
private readonly BindingList<ValuesOut> _values;
public UserAssist()
{
_values = new BindingList<ValuesOut>();
Errors = new List<string>();
}
public string InternalGuid => "5222820b-efea-4f5d-b2bd-4ef3dcd3007b";
public List<string> KeyPaths => new List<string>(new[]
{
@"Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist",
@"Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\*\Count"
});
public string ValueName => null;
public string AlertMessage { get; private set; }
public RegistryPluginType.PluginType PluginType => RegistryPluginType.PluginType.Grid;
public string Author => "Eric Zimmerman";
public string Email => "saericzimmerman@gmail.com";
public string Phone => "501-313-3778";
public string PluginName => "UserAssist";
public string ShortDescription => "Un ROT-13s UserAssist key values and extracts execution count, last run, etc.";
public string LongDescription
=>
"UserAssist is a method used to populate a user’s start menu with frequently used applications. This is achieved by maintaining a count of application use in each users NTUSER.DAT registry file. This key is suppose to contain information about programs and shortcuts accessed by the Windows GUI, including execution count, date of last execution, count of focuses, and total seconds focused";
public double Version => 0.5;
public List<string> Errors { get; }
public void ProcessValues(RegistryKey key)
{
_values.Clear();
Errors.Clear();
if (key.KeyName == "UserAssist")
{
// block of code to be executed if the condition is True
foreach (var registryKey in key.SubKeys)
{
foreach (var subregistryKey in registryKey.SubKeys)
{
ProcessKeys(subregistryKey);
}
}
}
else
{
ProcessKeys(key);
}
}
public void ProcessKeys(RegistryKey key)
{
foreach (var keyValue in key.Values)
{
try
{
var unrot = Helpers.Rot13Transform(keyValue.ValueName);
var run = 0;
string guid = null;
try
{
guid =
Regex.Match(unrot, @"\b[A-F0-9]{8}(?:-[A-F0-9]{4}){3}-[A-F0-9]{12}\b",
RegexOptions.IgnoreCase).Value;
var foldername = Utils.GetFolderNameFromGuid(guid);
unrot = unrot.Replace(guid, foldername);
}
catch (ArgumentException)
{
// Syntax error in the regular expression
}
DateTimeOffset? lastRun = null;
int? focusCount = null;
TimeSpan focusTime = new TimeSpan();
if (keyValue.ValueDataRaw.Length >= 16)
{
run = BitConverter.ToInt32(keyValue.ValueDataRaw, 4);
lastRun = DateTimeOffset.FromFileTime(BitConverter.ToInt64(keyValue.ValueDataRaw, 8));
// Windows 7 and up, new format
if (keyValue.ValueDataRaw.Length >= 68)
{
focusCount = BitConverter.ToInt32(keyValue.ValueDataRaw, 8);
focusTime = TimeSpan.FromMilliseconds(BitConverter.ToInt32(keyValue.ValueDataRaw, 12));
lastRun = DateTimeOffset.FromFileTime(BitConverter.ToInt64(keyValue.ValueDataRaw, 60));
}
}
if (lastRun?.Year < 1970)
{
lastRun = null;
}
var vo = new ValuesOut(keyValue.ValueName, unrot, run, lastRun, focusCount, focusTime.ToString(@"d'd, 'h'h, 'mm'm, 'ss's'"));
vo.BatchKeyPath = key.KeyPath;
vo.BatchValueName = keyValue.ValueName;
_values.Add(vo);
}
catch (Exception ex)
{
Errors.Add($"Value name: {keyValue.ValueName}, message: {ex.Message}");
}
}
}
public IBindingList Values => _values;
}
}