-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SneakAndPeek method
- Loading branch information
Showing
2 changed files
with
42 additions
and
72 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
Harden-Windows-Security Module/Main files/C#/SneakAndPeek.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.IO.Compression; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace HardeningModule | ||
{ | ||
public static class SneakAndPeek | ||
{ | ||
/// <summary> | ||
/// Takes a peek into a zip file and returns bool based on whether a file based on the query is found or not | ||
/// </summary> | ||
/// <param name="query"></param> | ||
/// <param name="zipFile"></param> | ||
/// <returns></returns> | ||
public static bool Search(string query, string zipFile) | ||
{ | ||
// Convert the query to a regular expression | ||
string regexPattern = "^" + Regex.Escape(query).Replace("\\*", ".*") + "$"; | ||
Regex regex = new Regex(regexPattern, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); | ||
|
||
// Open the zip file in read mode | ||
using (ZipArchive zipArchive = ZipFile.OpenRead(zipFile)) | ||
{ | ||
// Make sure the selected zip has the required file | ||
var content = zipArchive.Entries.Where(entry => regex.IsMatch(entry.FullName)).ToList(); | ||
|
||
// Return true if the number of files found is greater than 0 | ||
return content.Count > 0; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters