基于C#實現(xiàn)文件偽裝技術(shù)
1.目的
將一般文件夾偽裝成計算機(jī),控制面板,打印機(jī)等,當(dāng)雙擊該文件夾時打開相應(yīng)的偽裝組件(計算機(jī),控制面板,打印機(jī)等)而不是文件夾從而達(dá)到隱藏的目的。
2.原理
在需要進(jìn)行偽裝的文件夾下,建立desktop.ini 文本,并在其中寫入需要偽裝的系統(tǒng)標(biāo)識符。如下:
系統(tǒng)標(biāo)識符格式:
[.ShellClassInfo]
CLSID={21EC2020-3AEA-1069-A2DD-08002B30309D}
注解:
.ShellClassInfo:根節(jié)點 ;
CLSID:類標(biāo)識符;
{21EC2020-3AEA-1069-A2DD-08002B30309D}:系統(tǒng)標(biāo)識符
常用系統(tǒng)標(biāo)識符目錄:
我的電腦 :{20D04FE0-3AEA-1069-A2D8-08002B30309D}
我的文檔 :{450D8FBA-AD25-11D0-98A8-0800361B1103}
撥號網(wǎng)絡(luò) :{992CFFA0-F557-101A-88EC-00DD010CCC48}
控制面板 :{21EC2020-3AEA-1069-A2DD-08002B30309D}
計劃任務(wù) :{D6277990-4C6A-11CF-8D87-00AA0060F5BF}
打 印 機(jī) :{2227A280-3AEA-1069-A2DE-08002B30309D}
網(wǎng)上鄰居 :{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"文件夾打開呈現(xiàn)效果:
3>還原之后的效果(還原后等候30秒后效果方能呈現(xiàn))
4.實現(xiàn)代碼
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數(shù)據(jù) 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是否已經(jīng)存在 bool hascLsid = cLSID.Any(a => a.Value == txtContent); if (hascLsid) { MessageBox.Show("該CLSID已存在請勿重復(fù)登錄!","提示", 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 文件標(biāo)識符的文本 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文件設(shè)置特性 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文件進(jìn)行讀寫 /// </summary> class INIHelper { /// <summary> /// 從INI文件中讀取數(shù)據(jù) /// </summary> /// <param name="filePath">INI文件的全路徑</param> /// <param name="rootValue">根節(jié)點值,例如根節(jié)點[ConnectString]的值為:ConnectString</param> /// <param name="key">根節(jié)點下的鍵</param> /// <param name="defValue">當(dāng)標(biāo)記值未設(shè)定或不存在時的默認(rèn)值</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文件進(jìn)行讀取操作 /// </summary> /// <param name="IpAppName">表示INI文件內(nèi)部根節(jié)點的值</param> /// <param name="IpKeyName">表示根節(jié)點下子標(biāo)記的值</param> /// <param name="IpDefault">表示當(dāng)標(biāo)記值未設(shè)定或不存在時的默認(rèn)值</param> /// <param name="IpReturnString">返回讀取節(jié)點的值</param> /// <param name="nSize">讀取的節(jié)點內(nèi)容的最大容量</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文件進(jìn)行寫入操作 /// </summary> /// <param name="mpAppName">INI文件內(nèi)部根節(jié)點的值</param> /// <param name="mpKeyName">將要修改的標(biāo)記名稱</param> /// <param name="mpDefault">想要修改的內(nèi)容</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); }
對INI文件的詳細(xì)操作指南請參考:C#對INI文件的讀寫操作
到此這篇關(guān)于基于C#實現(xiàn)文件偽裝技術(shù)的文章就介紹到這了,更多相關(guān)C#文件偽裝內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
基于C#動手實現(xiàn)網(wǎng)絡(luò)服務(wù)器Web Server
這篇文章主要為大家詳細(xì)介紹了基于C#動手實現(xiàn)網(wǎng)絡(luò)服務(wù)器Web Server,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-10-10C#實現(xiàn)XML文件與DataTable、Dataset互轉(zhuǎn)
這篇文章介紹了C#實現(xiàn)XML文件與DataTable、Dataset互轉(zhuǎn)的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-04-04C#微信公眾號開發(fā)之用戶上下文WeixinContext和MessageContext
這篇文章介紹了C#微信公眾號開發(fā)之用戶上下文WeixinContext和MessageContext,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-06-06