我们最近感染了 thumbs.db2 病毒,它创建了我们网络驱动器上所有 Word 和 Excel 文档的快捷方式并隐藏了真实文件。我已经能够编写代码来遍历所有文件夹并找到快捷方式并删除,但我需要能够取消隐藏我无法实现的隐藏文件。
我的代码在下面,写得很快,所以请善待:)
public static IEnumerable<string> GetFiles(string root, string searchPattern)
{
Stack<string> pending = new Stack<string>();
pending.Push(root);
while (pending.Count != 0)
{
var path = pending.Pop();
string[] next = null;
try
{
next = Directory.GetFiles(path, searchPattern);
}
catch { }
if (next != null && next.Length != 0)
foreach (var file in next) yield return file;
try
{
next = Directory.GetDirectories(path);
foreach (var subdir in next) pending.Push(subdir);
}
catch { }
}
}
static void Main()
{
string lines = "";
string startFolder = @"S:\";
// Take a snapshot of the file system.
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(startFolder);
dir.GetDirectories("*.*");
// This method assumes that the application has discovery permissions
// for all folders under the specified path.
IEnumerable<String> fileList = GetFiles(startFolder,"*.lnk");
int I = 0;
List<LinkFileLocation> Lik = new List<LinkFileLocation>();
DtataDataContext D = new DtataDataContext();
//Execute the query. This might write out a lot of files!
foreach (string fi in fileList)
{
LinkFileLocation L = new LinkFileLocation();
// Console.WriteLine(fi.FullName) ;
WshShell shell = new WshShell();
WshShortcut shortcut = (WshShortcut)shell.CreateShortcut(fi);
FileInfo F = new FileInfo(fi);
var fs = F.GetAccessControl();
var sid = fs.GetOwner(typeof(SecurityIdentifier));
Console.WriteLine(sid); // SID
try
{
var ntAccount = sid.Translate(typeof(NTAccount));
Console.WriteLine(ntAccount); // DOMAIN\username
L.UserCreated = ntAccount.Value.ToString();
}
catch {
L.UserCreated = "Not Known";
}
L.CreationTime = F.CreationTime;
if (shortcut.Arguments.Contains("thumbs.db2 start") && shortcut.TargetPath.Contains("cmd.exe"))
{
L.Arguments = shortcut.Arguments;
L.Description = shortcut.Description;
L.FullName = shortcut.FullName;
L.HotKey = shortcut.Hotkey;
L.IconLocation = shortcut.IconLocation;
Console.Write("Infected Shortcut --" + I.ToString() + "-- :-" + shortcut.FullName.ToString() + Environment.NewLine);
lines += "Infected Shortcut :-" + shortcut.FullName.ToString() + Environment.NewLine;
I++;
}
D.LinkFileLocations.InsertOnSubmit(L);
D.SubmitChanges();
}
// Compose a string that consists of three lines.
// Write the string to a file.
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt");
file.WriteLine(lines);
file.Flush();
file.Close();
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
如何在c#中取消隐藏文件
任何帮助将不胜感激。
最诚挚的问候