C#实现伪装文件夹功能
作者:芝麻粒儿 发布时间:2023-04-28 14:21:38
标签:C#,伪装,文件夹
实践过程
效果
代码
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string GetFolType()
{
int Tid = comboBox1.SelectedIndex;
switch (Tid)
{
case 0: return @"{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
case 1: return @"{450D8FBA-AD25-11D0-98A8-0800361B1103}";
case 2: return @"{992CFFA0-F557-101A-88EC-00DD010CCC48}";
case 3: return @"{21EC2020-3AEA-1069-A2DD-08002B30309D}";
case 4: return @"{D6277990-4C6A-11CF-8D87-00AA0060F5BF}";
case 5: return @"{2227A280-3AEA-1069-A2DE-08002B30309D}";
case 6: return @"{208D2C60-3AEA-1069-A2D7-08002B30309D}";
case 7: return @"{645FF040-5081-101B-9F08-00AA002F954E}";
case 8: return @"{85BBD920-42A0-1069-A2E4-08002B30309D}";
case 9: return @"{BD84B380-8CA2-1069-AB1D-08000948F534}";
case 10: return @"{BDEADF00-C265-11d0-BCED-00A0C90AB50F}";
}
return @"{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
}
private void button1_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
if (folderBrowserDialog1.SelectedPath.Length >= 4)
{
txtFolPath.Text = folderBrowserDialog1.SelectedPath;
}
else
{
MessageBox.Show("不能对盘符进行伪装", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.SelectedIndex = 0;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == 11)
{
txtID.ReadOnly = false;
txtID.Text = "";
}
else
{
txtID.ReadOnly = true;
txtID.Text = GetFolType();
}
}
private void Camouflage(string str)
{
StreamWriter sw = File.CreateText(txtFolPath.Text.Trim() + @"\desktop.ini");
sw.WriteLine(@"[.ShellClassInfo]");
sw.WriteLine("CLSID=" + str);
sw.Close();
File.SetAttributes(txtFolPath.Text.Trim() + @"\desktop.ini", FileAttributes.Hidden);
File.SetAttributes(txtFolPath.Text.Trim(), FileAttributes.System);
MessageBox.Show("伪装成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void button2_Click(object sender, EventArgs e)
{
if (this.txtFolPath.Text == "")
{
MessageBox.Show("请选择文件夹路径!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
try
{
if (txtID.ReadOnly == false)
{
string str = txtID.Text.Trim();
if (str.StartsWith("."))
str = str.Substring(1);
if (!str.StartsWith("{")||str.Trim().Length!=38)
{
MessageBox.Show("自定义类型错误!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
Camouflage(str);
}
}
else
{
Camouflage(GetFolType());
}
}
catch
{
MessageBox.Show ("不要进行多次伪装!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
private void button3_Click(object sender, EventArgs e)
{
if (txtFolPath.Text == "")
{
MessageBox.Show("请选择加密过的文件夹!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
else
{
try
{
FileInfo fi = new FileInfo(txtFolPath.Text.Trim() + @"\desktop.ini");
if (!fi.Exists)
{
MessageBox.Show("该文件夹没有被伪装!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
System.Threading.Thread.Sleep(1000);
File.Delete(txtFolPath.Text + @"\desktop.ini");
File.SetAttributes(txtFolPath.Text.Trim(), FileAttributes.System);
MessageBox.Show("还原成功", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch
{
MessageBox.Show("不要多次还原!");
}
}
}
}
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.txtFolPath = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.txtID = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.button3 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.txtFolPath);
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.ForeColor = System.Drawing.Color.Black;
this.groupBox1.Location = new System.Drawing.Point(12, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(431, 55);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "第一步:选择文件夹";
//
// txtFolPath
//
this.txtFolPath.Location = new System.Drawing.Point(78, 22);
this.txtFolPath.Name = "txtFolPath";
this.txtFolPath.Size = new System.Drawing.Size(296, 21);
this.txtFolPath.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(380, 21);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(43, 23);
this.button1.TabIndex = 2;
this.button1.Text = "选择";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(6, 25);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(77, 12);
this.label1.TabIndex = 1;
this.label1.Text = "文件夹路径:";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.txtID);
this.groupBox2.Controls.Add(this.label3);
this.groupBox2.Controls.Add(this.comboBox1);
this.groupBox2.Controls.Add(this.label2);
this.groupBox2.ForeColor = System.Drawing.Color.Black;
this.groupBox2.Location = new System.Drawing.Point(12, 69);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(431, 99);
this.groupBox2.TabIndex = 2;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "第二部:选择伪装的类型";
//
// txtID
//
this.txtID.Location = new System.Drawing.Point(103, 57);
this.txtID.Name = "txtID";
this.txtID.ReadOnly = true;
this.txtID.Size = new System.Drawing.Size(320, 21);
this.txtID.TabIndex = 3;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(20, 60);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(77, 12);
this.label3.TabIndex = 2;
this.label3.Text = "自定义类型:";
//
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Items.AddRange(new object[] {
"我的电脑",
"我的文档",
"拨号网络",
"控制面板",
"计划任务",
"打印机",
"网络邻居",
"回收站",
"公文包",
"字体",
"Web 文件夹",
"自定义ID"});
this.comboBox1.Location = new System.Drawing.Point(101, 26);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(322, 20);
this.comboBox1.TabIndex = 1;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(8, 30);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(89, 12);
this.label2.TabIndex = 0;
this.label2.Text = "选择伪装类型:";
//
// groupBox3
//
this.groupBox3.Controls.Add(this.button3);
this.groupBox3.Controls.Add(this.button2);
this.groupBox3.ForeColor = System.Drawing.Color.Black;
this.groupBox3.Location = new System.Drawing.Point(12, 174);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(431, 53);
this.groupBox3.TabIndex = 3;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "第三部:操作";
//
// button3
//
this.button3.Location = new System.Drawing.Point(230, 20);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 1;
this.button3.Text = "还原";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(127, 20);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 0;
this.button2.Text = "伪装";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(452, 233);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "伪装文件夹";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox txtFolPath;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtID;
private System.Windows.Forms.Label label3;
}
来源:https://blog.csdn.net/qq_27489007/article/details/128363693


猜你喜欢
- 一、DMI动态方法调用的其中一种改变form表单中action属性的方式已经讲过了。还有两种,一种是改变struts.xml配置文件中act
- 其实说实话,没有多大的可比较性,它们是完全不同的两个东西,它们的抽象不在同一个层级上。但是为了让大家更好的理解,还是做一个比较吧,毕竟它们都
- 在多线程处理问题时,无法通过@Autowired注入bean,报空指针异常,在线程中为了线程安全,是防注入的,如果要用到这个类,只能从bea
- 使用IDEA编辑Web项目已经逐渐超过了使用eclipse的人数,但是IDEA对于pom.xml的执行也就是Maven方式导包支持并不是很完
- 一、简介约瑟夫问题(有时也称为约瑟夫斯置换,是一个出现在计算机科学和数学中的问题。在计算机编程的算法中,类似问题又称为约瑟夫环。又称“丢手绢
- 小编为面试Java程序员的朋友们整理了2017非常热门的面试中的笔试试题,如果你是一个正在准备面试Java程序员的读者,赶快学习一下吧。1,
- 记录web项目部署到阿里云服务器步骤(使用 web项目、阿里云服务器、Xftp、Xshell),敬请参考和指正1.将要部署的项目打包成WAR
- 一、什么是代理?指为一个目标对象提供一个代理对象, 并由代理对象控制对目标对象的引用. 使用代理对象, 是为了在不修改目标对象的基础上,增强
- 1.问题分析我们在开发中经常遇到多个实体类有共同的属性字段,例如在用户注册时需要设置创建时间、创建人、修改时间、修改人等字段,在用户编辑信息
- Java基础编写猜数游戏,供大家参考,具体内容如下设计内容及要求产生一个100以内的随机数,游戏者进行猜数,猜中即胜,猜不中,提示是大了还是
- 在有些情况下,有很多列表不能一次性显示完整,需要对其进行分页处理博主自己也写了一个分页系统,在这里记录下来,方便以后直接拿来使用这篇文章De
- 先通过一个页面看下事情的来龙去脉,页面如下所示: 这个页面刚好一屏幕大小,所以没有滚动条,因为“保存”键上面那个项目备注是需要用户
- swing自带的窗体是不能够满足我们的应用需求的,所以需要制作任意图片和形状的JFrame框体,比如下图:并且可以设置窗体背景图片的透明度下
- Flutter有个悠久的传统,便是运行flutter create并删除所有内容,然后在所有标准样板文件(boilerplate)当中尽力复
- Android的WebView做不到ios的WebView那样可以很方便的直接预览pdf文件。要实现利用WebView预览pdf我们可以使用
- 本文实例为大家分享了Java操作MongoDB模糊查询和分页查询,供大家参考,具体内容如下模糊查询条件:1、完全匹配Pattern patt
- 前言我们都知道浮点型变量在进行计算的时候会出现丢失精度的问题。如下一段代码:System.out.println(0.05 + 0.01);
- 什么是通用Mapper通用Mapper就是为了解决单表增删改查,基于Mybatis的插件。开发人员不需要编写SQL,不需要在DAO中增加方法
- 谜题在C#中,用virtual关键字修饰的方法(属性、事件)称为虚方法(属性、事件),表示该方法可以由派生类重写(override)。虚方法
- 在Monkeyrunner做自动化测试时,可以使用模拟器,当然也可以选择用真机。不过,要想通过电脑来安装软件,操作手机,则必须先安装手机驱动