C#实现伪装文件夹功能

.NET
252
0
0
2023-07-11
标签   C#
目录
  • 实践过程
  • 效果
  • 代码

实践过程

效果

代码

public partial class Form : Form
{
    public Form()
    {
        InitializeComponent();
    }
    private string GetFolType()
    {
        int Tid = comboBox.SelectedIndex;
        switch (Tid)
        {
            case: return @"{20D04FE0-3AEA-1069-A2D8-08002B30309D}";
            case: return @"{450D8FBA-AD25-11D0-98A8-0800361B1103}";
            case: return @"{992CFFA0-F557-101A-88EC-00DD010CCC48}";
            case: return @"{21EC2020-3AEA-1069-A2DD-08002B30309D}";
            case: return @"{D6277990-4C6A-11CF-8D87-00AA0060F5BF}";
            case: return @"{2227A280-3AEA-1069-A2DE-08002B30309D}";
            case: return @"{208D2C60-3AEA-1069-A2D7-08002B30309D}";
            case: return @"{645FF040-5081-101B-9F08-00AA002F954E}";
            case: return @"{85BBD920-42A0-1069-A2E4-08002B30309D}";
            case: return @"{BD84B380-8CA2-1069-AB1D-08000948F534}";
            case: return @"{BDEADF00-C265-11d0-BCED-00A0C90AB50F}";
        }
        return @"{D04FE0-3AEA-1069-A2D8-08002B30309D}";
    }
    private void button_Click(object sender, EventArgs e)
    {
        if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
        {
            if (folderBrowserDialog.SelectedPath.Length >= 4)
            {
                txtFolPath.Text = folderBrowserDialog.SelectedPath;
            }
            else
            {
                MessageBox.Show("不能对盘符进行伪装", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }

    private void Form_Load(object sender, EventArgs e)
    {
        comboBox.SelectedIndex = 0;
    }

    private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (comboBox.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 button_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();
                    if (!str.StartsWith("{")||str.Trim().Length!=)
                    {
                        MessageBox.Show("自定义类型错误!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        Camouflage(str);
                    }
                }
                else
                {
                    Camouflage(GetFolType());
                }
            }
            catch
            {
                MessageBox.Show ("不要进行多次伪装!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }
        }
    }

    private void button_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();
                    File.Delete(txtFolPath.Text + @"\desktop.ini");
                    File.SetAttributes(txtFolPath.Text.Trim(), FileAttributes.System);
                    MessageBox.Show("还原成功", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch
            {
                MessageBox.Show("不要多次还原!");
            }
        }
    }
}
partial class Form
{
    /// <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.groupBox = new System.Windows.Forms.GroupBox();
        this.txtFolPath = new System.Windows.Forms.TextBox();
        this.button = new System.Windows.Forms.Button();
        this.label = new System.Windows.Forms.Label();
        this.groupBox = new System.Windows.Forms.GroupBox();
        this.txtID = new System.Windows.Forms.TextBox();
        this.label = new System.Windows.Forms.Label();
        this.comboBox = new System.Windows.Forms.ComboBox();
        this.label = new System.Windows.Forms.Label();
        this.groupBox = new System.Windows.Forms.GroupBox();
        this.button = new System.Windows.Forms.Button();
        this.button = new System.Windows.Forms.Button();
        this.folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
        this.groupBox.SuspendLayout();
        this.groupBox.SuspendLayout();
        this.groupBox.SuspendLayout();
        this.SuspendLayout();
        // 
        // groupBox
        // 
        this.groupBox.Controls.Add(this.txtFolPath);
        this.groupBox.Controls.Add(this.button1);
        this.groupBox.Controls.Add(this.label1);
        this.groupBox.ForeColor = System.Drawing.Color.Black;
        this.groupBox.Location = new System.Drawing.Point(12, 8);
        this.groupBox.Name = "groupBox1";
        this.groupBox.Size = new System.Drawing.Size(431, 55);
        this.groupBox.TabIndex = 1;
        this.groupBox.TabStop = false;
        this.groupBox.Text = "第一步:选择文件夹";
        // 
        // txtFolPath
        // 
        this.txtFolPath.Location = new System.Drawing.Point(, 22);
        this.txtFolPath.Name = "txtFolPath";
        this.txtFolPath.Size = new System.Drawing.Size(, 21);
        this.txtFolPath.TabIndex =;
        // 
        // button
        // 
        this.button.Location = new System.Drawing.Point(380, 21);
        this.button.Name = "button1";
        this.button.Size = new System.Drawing.Size(43, 23);
        this.button.TabIndex = 2;
        this.button.Text = "选择";
        this.button.UseVisualStyleBackColor = true;
        this.button.Click += new System.EventHandler(this.button1_Click);
        // 
        // label
        // 
        this.label.AutoSize = true;
        this.label.Location = new System.Drawing.Point(6, 25);
        this.label.Name = "label1";
        this.label.Size = new System.Drawing.Size(77, 12);
        this.label.TabIndex = 1;
        this.label.Text = "文件夹路径:";
        // 
        // groupBox
        // 
        this.groupBox.Controls.Add(this.txtID);
        this.groupBox.Controls.Add(this.label3);
        this.groupBox.Controls.Add(this.comboBox1);
        this.groupBox.Controls.Add(this.label2);
        this.groupBox.ForeColor = System.Drawing.Color.Black;
        this.groupBox.Location = new System.Drawing.Point(12, 69);
        this.groupBox.Name = "groupBox2";
        this.groupBox.Size = new System.Drawing.Size(431, 99);
        this.groupBox.TabIndex = 2;
        this.groupBox.TabStop = false;
        this.groupBox.Text = "第二部:选择伪装的类型";
        // 
        // txtID
        // 
        this.txtID.Location = new System.Drawing.Point(, 57);
        this.txtID.Name = "txtID";
        this.txtID.ReadOnly = true;
        this.txtID.Size = new System.Drawing.Size(, 21);
        this.txtID.TabIndex =;
        // 
        // label
        // 
        this.label.AutoSize = true;
        this.label.Location = new System.Drawing.Point(20, 60);
        this.label.Name = "label3";
        this.label.Size = new System.Drawing.Size(77, 12);
        this.label.TabIndex = 2;
        this.label.Text = "自定义类型:";
        // 
        // comboBox
        // 
        this.comboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
        this.comboBox.FormattingEnabled = true;
        this.comboBox.Items.AddRange(new object[] {
        "我的电脑",
        "我的文档",
        "拨号网络",
        "控制面板",
        "计划任务",
        "打印机",
        "网络邻居",
        "回收站",
        "公文包",
        "字体",
        "Web 文件夹",
        "自定义ID"});
        this.comboBox.Location = new System.Drawing.Point(101, 26);
        this.comboBox.Name = "comboBox1";
        this.comboBox.Size = new System.Drawing.Size(322, 20);
        this.comboBox.TabIndex = 1;
        this.comboBox.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
        // 
        // label
        // 
        this.label.AutoSize = true;
        this.label.Location = new System.Drawing.Point(8, 30);
        this.label.Name = "label2";
        this.label.Size = new System.Drawing.Size(89, 12);
        this.label.TabIndex = 0;
        this.label.Text = "选择伪装类型:";
        // 
        // groupBox
        // 
        this.groupBox.Controls.Add(this.button3);
        this.groupBox.Controls.Add(this.button2);
        this.groupBox.ForeColor = System.Drawing.Color.Black;
        this.groupBox.Location = new System.Drawing.Point(12, 174);
        this.groupBox.Name = "groupBox3";
        this.groupBox.Size = new System.Drawing.Size(431, 53);
        this.groupBox.TabIndex = 3;
        this.groupBox.TabStop = false;
        this.groupBox.Text = "第三部:操作";
        // 
        // button
        // 
        this.button.Location = new System.Drawing.Point(230, 20);
        this.button.Name = "button3";
        this.button.Size = new System.Drawing.Size(75, 23);
        this.button.TabIndex = 1;
        this.button.Text = "还原";
        this.button.UseVisualStyleBackColor = true;
        this.button.Click += new System.EventHandler(this.button3_Click);
        // 
        // button
        // 
        this.button.Location = new System.Drawing.Point(127, 20);
        this.button.Name = "button2";
        this.button.Size = new System.Drawing.Size(75, 23);
        this.button.TabIndex = 0;
        this.button.Text = "伪装";
        this.button.UseVisualStyleBackColor = true;
        this.button.Click += new System.EventHandler(this.button2_Click);
        // 
        // Form
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(F, 12F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(, 233);
        this.Controls.Add(this.groupBox);
        this.Controls.Add(this.groupBox);
        this.Controls.Add(this.groupBox);
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
        this.MaximizeBox = false;
        this.Name = "Form";
        this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        this.Text = "伪装文件夹";
        this.Load += new System.EventHandler(this.Form_Load);
        this.groupBox.ResumeLayout(false);
        this.groupBox.PerformLayout();
        this.groupBox.ResumeLayout(false);
        this.groupBox.PerformLayout();
        this.groupBox.ResumeLayout(false);
        this.ResumeLayout(false);

    }

    #endregion

    private System.Windows.Forms.GroupBox groupBox;
    private System.Windows.Forms.TextBox txtFolPath;
    private System.Windows.Forms.Button button;
    private System.Windows.Forms.Label label;
    private System.Windows.Forms.GroupBox groupBox;
    private System.Windows.Forms.GroupBox groupBox;
    private System.Windows.Forms.Button button;
    private System.Windows.Forms.Button button;
    private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog;
    private System.Windows.Forms.ComboBox comboBox;
    private System.Windows.Forms.Label label;
    private System.Windows.Forms.TextBox txtID;
    private System.Windows.Forms.Label label;
}