Skip to content

Commit 3c91c1d

Browse files
authored
Adds include filtering support. (#60)
1 parent a7ec3ab commit 3c91c1d

File tree

5 files changed

+42
-30
lines changed

5 files changed

+42
-30
lines changed

Lib/Collectors/FileSystem/FileSystemMonitor.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public void WriteRename(RenamedEventArgs obj)
207207

208208
private void OnChanged(object source, FileSystemEventArgs e)
209209
{
210-
if (Filter.IsFiltered(Filter.RuntimeString(), "Monitor", "File", "Path", "Exclude", e.FullPath))
210+
if (Filter.IsFiltered(Filter.RuntimeString(), "Monitor", "File", "Path", e.FullPath))
211211
{
212212
return;
213213
}
@@ -238,7 +238,7 @@ private void OnChanged(object source, FileSystemEventArgs e)
238238

239239
private void OnRenamed(object source, RenamedEventArgs e)
240240
{
241-
if (Filter.IsFiltered(Filter.RuntimeString(), "Monitor", "File", "Path", "Exclude", e.FullPath))
241+
if (Filter.IsFiltered(Filter.RuntimeString(), "Monitor", "File", "Path", e.FullPath))
242242
{
243243
return;
244244
}

Lib/Collectors/Registry/RegistryCollector.cs

+28-25
Original file line numberDiff line numberDiff line change
@@ -128,37 +128,40 @@ public override void Execute()
128128
(hive =>
129129
{
130130
Logger.Instance.Debug("Starting " + hive.ToString());
131-
if (Filter.IsFiltered(Filter.RuntimeString(), "Scan", "Registry", "Hive", "Exclude", hive.ToString(), out Regex Capturer))
131+
if (Filter.IsFiltered(Filter.RuntimeString(), "Scan", "Registry", "Hive", "Include", hive.ToString()))
132+
{
133+
}
134+
else if (Filter.IsFiltered(Filter.RuntimeString(), "Scan", "Registry", "Hive", "Exclude", hive.ToString(), out Regex Capturer))
132135
{
133-
Logger.Instance.Info("Hi mom");
134136
Logger.Instance.Info("Excluding hive '{0}' due to filter '{1}'.", hive.ToString(), Capturer.ToString());
137+
138+
return;
135139
}
136-
else
140+
141+
var registryInfoEnumerable = RegistryWalker.WalkHive(hive);
142+
try
137143
{
138-
var registryInfoEnumerable = RegistryWalker.WalkHive(hive);
139-
try
140-
{
141-
Parallel.ForEach(registryInfoEnumerable,
142-
(registryObject =>
144+
Parallel.ForEach(registryInfoEnumerable,
145+
(registryObject =>
146+
{
147+
try
143148
{
144-
try
145-
{
146-
Write(registryObject);
147-
}
148-
// Some registry keys don't get along
149-
catch (InvalidOperationException e)
150-
{
151-
Logger.Instance.Debug(registryObject.Key + " " + e.GetType());
152-
}
153-
}));
154-
}
155-
catch (Exception e)
156-
{
157-
Logger.Instance.Debug(e.GetType());
158-
Logger.Instance.Debug(e.Message);
159-
Logger.Instance.Debug(e.StackTrace);
160-
}
149+
Write(registryObject);
150+
}
151+
// Some registry keys don't get along
152+
catch (InvalidOperationException e)
153+
{
154+
Logger.Instance.Debug(registryObject.Key + " " + e.GetType());
155+
}
156+
}));
161157
}
158+
catch (Exception e)
159+
{
160+
Logger.Instance.Debug(e.GetType());
161+
Logger.Instance.Debug(e.Message);
162+
Logger.Instance.Debug(e.StackTrace);
163+
}
164+
162165
}));
163166

164167
DatabaseManager.Commit();

Lib/Utils/DirectoryWalker.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static IEnumerable<FileSystemInfo> WalkDirectory(string root)
2424
{
2525
string currentDir = dirs.Pop();
2626

27-
if (Filter.IsFiltered(Filter.RuntimeString(), "Scan", "File", "Path", "Exclude", currentDir))
27+
if (Filter.IsFiltered(Filter.RuntimeString(), "Scan", "File", "Path", currentDir))
2828
{
2929
continue;
3030
}
@@ -100,7 +100,7 @@ public static IEnumerable<FileSystemInfo> WalkDirectory(string root)
100100
continue;
101101
}
102102
string FullPath = String.Format("{0}{1}{2}", currentDir, Path.PathSeparator, file);
103-
if (Filter.IsFiltered(Filter.RuntimeString(), "Scan", "File", "Path", "Exclude", FullPath))
103+
if (Filter.IsFiltered(Filter.RuntimeString(), "Scan", "File", "Path", FullPath))
104104
{
105105
continue;
106106
}

Lib/Utils/Filter.cs

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ public static string RuntimeString()
2929
return "Unknown";
3030
}
3131

32+
public static bool IsFiltered(string Platform, string ScanType, string ItemType, string Property, string Target)
33+
{
34+
if (IsFiltered(Platform, ScanType, ItemType, Property, "include", Target))
35+
{
36+
return false;
37+
}
38+
return IsFiltered(Platform, ScanType, ItemType, Property, "exclude", Target);
39+
}
40+
3241
public static bool IsFiltered(string Platform, string ScanType, string ItemType, string Property, string FilterType, string Target) => IsFiltered(Platform, ScanType, ItemType, Property, FilterType, Target, out Regex dummy);
3342

3443
public static bool IsFiltered(string Platform, string ScanType, string ItemType, string Property, string FilterType, string Target, out Regex regex)

Lib/Utils/RegistryWalker.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static IEnumerable<RegistryObject> WalkHive(RegistryHive Hive)
3333
{
3434
continue;
3535
}
36-
if (Filter.IsFiltered(Filter.RuntimeString(), "Scan", "Registry", "Key", "Exclude", currentKey.Name))
36+
if (Filter.IsFiltered(Filter.RuntimeString(), "Scan", "Registry", "Key", currentKey.Name))
3737
{
3838
continue;
3939
}

0 commit comments

Comments
 (0)