1,目的:
将一般文件夹伪装成计算机,控制面板,打印机等,当双击该文件夹时打开相应的伪装组件(计算机,控制面板,打印机等)而不是文件夹从而达到隐藏的目的。
2,原理:
在需要进行伪装的文件夹下,建立desktop.ini 文本,并在其中写入需要伪装的系统标识符。如下:
系统标识符格式:
[.ShellClassInfo]
CLSID={21EC2020-3AEA-1069-A2DD-08002B30309D}
注解:
.ShellClassInfo:根节点 ;
CLSID:类标识符;
{21EC2020-3AEA-1069-A2DD-08002B30309D}:系统标识符
常用系统标识符目录:
我的电脑 :{20D04FE0-3AEA-1069-A2D8-08002B30309D}
我的文档 :{450D8FBA-AD25-11D0-98A8-0800361B1103}
拨号网络 :{992CFFA0-F557-101A-88EC-00DD010CCC48}
控制面板 :{21EC2020-3AEA-1069-A2DD-08002B30309D}
计划任务 :{D6277990-4C6A-11CF-8D87-00AA0060F5BF}
打 印 机 :{2227A280-3AEA-1069-A2DE-08002B30309D}
网上邻居 :{208D2C60-3AEA-1069-A2D7-08002B30309D}
回 收 站 :{645FF040-5081-101B-9F08-00AA002F954E}
公 文 包 :{85BBD920-42A0-1069-A2E4-08002B30309D}
字 体 :{D20EA4E1-3957-11D2-A40B-0C5020524152}
Web文件夹 :{BDEADF00-C265-11D0-BCED-00A0C90AB50F}
写字板文档:{73FDDC80-AEA9-101A-98A7-00AA00374959}
3,效果:
1>软件效果
2>伪装操作文件夹后效果:
双击"伪装测试2"文件夹打开呈现效果:
3>还原之后的效果(还原后等候30秒后效果方能呈现)
4,代码如下:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
List<Clsid> cLSID;
private void btnDirc_Click(object sender, EventArgs e)
{
using(FolderBrowserDialog fbd=new FolderBrowserDialog())
{
if (fbd.ShowDialog() == DialogResult.OK)
{
label3.Text = fbd.SelectedPath;
}
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
//保存Json数据
using (TextWriter writer=new StreamWriter("../../Data.json"))
{
string jsonStr = JsonConvert.SerializeObject(cLSID, Formatting.Indented);
writer.Write(jsonStr);
}
}
private void Form1_Load(object sender, EventArgs e)
{
if (File.Exists("../../Data.json"))
{
string objstr = File.ReadAllText("../../Data.json", Encoding.UTF8);
cLSID = JsonConvert.DeserializeObject<List<Clsid>>(objstr);
}
else
{
cLSID = new List<Clsid>();
}
if (cLSID.Count > 0)
{
cLSID.ForEach(a =>
{
comboBox1.Items.Add(a);
});
comboBox1.DisplayMember = "Key";
comboBox1.ValueMember = "Value";
comboBox1.SelectedIndex = 0;
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedItem != null)
{
Clsid csid = comboBox1.SelectedItem as Clsid;
textBox1.Text = csid.Value;
}
}
private void btnLogin_Click(object sender, EventArgs e)
{
string txtContent = textBox1.Text.Trim().ToUpper();
if (System.Text.RegularExpressions.Regex.IsMatch(txtContent, @"^\{\w{8}-\w{4}-\w{4}-\w{4}-\w{12}\}$"))
{
//判断Clsid是否已经存在
bool hascLsid = cLSID.Any(a => a.Value == txtContent);
if (hascLsid)
{
MessageBox.Show("该CLSID已存在请勿重复登录!","提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
LoginFrm win = new LoginFrm(txtContent);
win.StartPosition = FormStartPosition.CenterParent;
win.LoginCompleted += Win_LoginCompleted;
if(win.ShowDialog() == DialogResult.OK)
{
MessageBox.Show("添加成功!","提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
else
{
MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void Win_LoginCompleted(string obj)
{
Clsid cs = new Clsid
{
Key = obj,
Value = textBox1.Text.Trim().ToUpper()
};
cLSID.Add(cs);
comboBox1.Items.Add(cs);
}
private void btnDisguise_Click(object sender, EventArgs e)
{
if (Directory.Exists(label3.Text))
{
//用于保存windows 文件标识符的文本
string desktopFile = Path.Combine(label3.Text, "desktop.ini");
if (!File.Exists(desktopFile))
{
FileStream fs= File.Create(desktopFile);
fs.Dispose();
}
Clsid csid = comboBox1.SelectedItem as Clsid;
string cmdStr = csid.Value;
INIHelper.WriteToINI(desktopFile, ".ShellClassInfo", "CLSID", cmdStr);
//给ini文件设置特性
File.SetAttributes(desktopFile, FileAttributes.Hidden);
File.SetAttributes(label3.Text, FileAttributes.System);
MessageBox.Show("伪装成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("该文件夹不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
private void btnRestore_Click(object sender, EventArgs e)
{
//所谓还原就是删除ini文件
string desktopFile = Path.Combine(label3.Text, "desktop.ini");
if (File.Exists(desktopFile))
{
try
{
File.Delete(desktopFile);
MessageBox.Show("还原成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show("还原失败,原因:"+ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("该文件不需要还原", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
class Clsid
{
public string Key { get; set; }
public string Value { get; set; }
}
/// <summary>
/// 对INI文件进行读写
/// </summary>
class INIHelper
{
/// <summary>
/// 从INI文件中读取数据
/// </summary>
/// <param name="filePath">INI文件的全路径</param>
/// <param name="rootValue">根节点值,例如根节点[ConnectString]的值为:ConnectString</param>
/// <param name="key">根节点下的键</param>
/// <param name="defValue">当标记值未设定或不存在时的默认值</param>
/// <returns></returns>
public static string ReadFromINI(string filePath, string rootValue, string key, string defValue = "")
{
StringBuilder sb = new StringBuilder(1024);
GetPrivateProfileString(rootValue, key, defValue, sb, 1024, filePath);
return sb.ToString();
}
public static void WriteToINI(string filePath, string rootValue, string key, string newVal)
{
WritePrivateProfileString(rootValue, key, newVal, filePath);
}
/// <summary>
/// 对INI文件进行读取操作
/// </summary>
/// <param name="IpAppName">表示INI文件内部根节点的值</param>
/// <param name="IpKeyName">表示根节点下子标记的值</param>
/// <param name="IpDefault">表示当标记值未设定或不存在时的默认值</param>
/// <param name="IpReturnString">返回读取节点的值</param>
/// <param name="nSize">读取的节点内容的最大容量</param>
/// <param name="IpFileName">文件的全路径</param>
/// <returns></returns>
[System.Runtime.InteropServices.DllImport("kernel32")]
static extern int GetPrivateProfileString(string IpAppName, string IpKeyName, string IpDefault, StringBuilder IpReturnString, int nSize, string IpFileName);
/// <summary>
/// 对INI文件进行写入操作
/// </summary>
/// <param name="mpAppName">INI文件内部根节点的值</param>
/// <param name="mpKeyName">将要修改的标记名称</param>
/// <param name="mpDefault">想要修改的内容</param>
/// <param name="mpFileName">INI文件的全路径</param>
/// <returns></returns>
[System.Runtime.InteropServices.DllImport("kernel32")]
static extern long WritePrivateProfileString(string mpAppName, string mpKeyName, string mpDefault, string mpFileName);
}