实例操作
编辑基本原理
编辑using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Win32;
namespace 设置映象劫持
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;//开始定时器
}
private void dra()//定时器周期时间,主要用来绘制时间,和本文关系不大
{
Graphics gr = this.CreateGraphics();
Brush br1 = new SolidBrush(Color.Green);
Brush br = new SolidBrush(Color.Red);
gr.FillRectangle(br1, 20, 20, 120, 40);
gr.DrawString("映像劫持",new Font ("宋体",12),br,21,21 );
gr.FillRectangle(br1, 150,20, 120, 40);
gr.DrawString(DateTime.Now.ToLongTimeString(), new Font("楷书", 12), br, 151, 20);
}
private void timer1_Tick(object sender, EventArgs e)
{
dra();
}
private void button1_Click(object sender, EventArgs e)//设置映像劫持,本文的核心
{
int s=0;
for (int i = 0; i < comboBox1.Items.Count; i++)
{
string []name=new string [comboBox1.Items.Count ];
name[i]= comboBox1.Items[i].ToString();
if (name[i] == comboBox1.Text)
{
s++;
}
}
if(s==0)
{
comboBox1.Items.Add (comboBox1.Text );
}
else
{
}
try
{
RegistryKey reg;
reg = Registry.LocalMachine;
reg = reg.CreateSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\" + comboBox1.Text);
reg.SetValue("Debugger", comboBox2.Text);
reg.Close();
MessageBox.Show("映像劫持成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
Refresh();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)//解除映像劫持,本文的核心
{
try
{
RegistryKey reg;
reg = Registry.LocalMachine;
reg.DeleteSubKeyTree(@"Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\" + comboBox1.Text,true);
reg.Close();
MessageBox.Show("解救映像成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
Refresh();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
label1.Text = "解救映像名:";
}
}
}
}