分享
 
 
 

实战Registry和RegistryKey类,一个简单的可疑文件扫描程序

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

private void Search()

{

try

{

this.listBox1.Items.Add("");

this.listBox1.Items.Add("扫描指定的目录文件");

RegistryKey scan = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Honeydogchen\\.Dog\\Scan",true);

string strdir = scan.GetValue("FolderSelect").ToString();

if(this.checkBox2.Checked==true)

{

RegistryKey microsoft = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft",true);

RegistryKey currentversion1 = microsoft.OpenSubKey("Windows NT\\CurrentVersion",true);

RegistryKey currentversion2 = microsoft.OpenSubKey("Windows\\CurrentVersion",true);

try

{

string system32dir = currentversion1.GetValue("SystemRoot").ToString();

GetSystemFiles(system32dir+"\SYSTEM32");

}

catch(Exception)

{

}

try

{

string systemdir = currentversion2.GetValue("SystemRoot").ToString();

GetSystemFiles(systemdir+"\SYSTEM");

}

catch(Exception)

{

}

}

GetCommonFiles(strdir);

this.textBox1.Text = strdir;

this.label1.Enabled = true;

this.label4.Enabled = true;

this.Cursor = System.Windows.Forms.Cursors.Default;

if(a==0)

{

this.listBox1.Items.Add(" 恭喜恭喜,没有发现可疑文件");

}

else

{

this.listBox1.Items.Add(" 共发现"+a+"个可疑文件,请用专业反病毒软件查杀");

}

this.listBox1.Items.Add("");

this.listBox1.Items.Add("扫描结束,"+"共扫描了"+d+"个进程,"+b+"个文件");

this.listBox1.Items.Add("");

this.listBox1.Items.Add("反病毒技术支持");

this.listBox1.Items.Add(" Email:honeydogchen@sohu.com");

}

catch(Exception)

{

}

}

private void GetCommonFiles(string strDir)

{

string path = Application.StartupPath;

Share.Ini ini = new Share.Ini(path+"\Virus.dat");

DirectoryInfo dir = new DirectoryInfo(strDir);

int number = Convert.ToInt16(ini.IniReadValue("VirusList","Number"));

FileInfo[] exefiles = dir.GetFiles("*.exe");

foreach(FileInfo f in exefiles)

{

this.textBox1.Text = f.FullName.ToString();

this.textBox1.Refresh();

for(int i=0;i<number;i++)

{

string name = Convert.ToString(ini.IniReadValue("VirusList","Name"+i));

if(f.Name.ToLower().EndsWith(name))

{

this.listBox1.Items.Add(" 名称:"+f.Name.ToString());

this.listBox1.Items.Add(" 路径:"+strDir+"\"+f.Name.ToString());

a++;

}

}

b++;

}

if(this.checkBox3.Checked==true)

{

DirectoryInfo[] dir1List = dir.GetDirectories();

for(int i = 0;i<dir1List.Length;i++)

{

GetCommonFiles(strDir+"\"+dir1List[i].Name);

}

}

}

private void GetSystemFiles(string strDir)

{

string path = Application.StartupPath;

Share.Ini ini = new Share.Ini(path+"\Virus.dat");

DirectoryInfo dir = new DirectoryInfo(strDir);

int number = Convert.ToInt16(ini.IniReadValue("VirusList","Number"));

FileInfo[] exefiles = dir.GetFiles("*.exe");

foreach(FileInfo f in exefiles)

{

this.textBox1.Text = f.FullName.ToString();

this.textBox1.Refresh();

for(int i=0;i<number;i++)

{

string name = Convert.ToString(ini.IniReadValue("VirusList","Name"+i));

if(f.Name.ToLower().EndsWith(name))

{

this.listBox1.Items.Add(" 名称:"+f.Name.ToString());

this.listBox1.Items.Add(" 路径:"+strDir+"\"+f.Name.ToString());

a++;

}

}

b++;

}

}

private void CheckRegistry()

{

int h = 0;

int i = 0;

int j = 0;

int k = 0;

int l = 0;

int n = 0;

this.listBox1.Visible = true;

try

{

this.listBox1.Items.Clear();

this.listBox1.Items.Add("扫描注册表的启动项");

RegistryKey hklm = Registry.LocalMachine;

RegistryKey hkcu = Registry.CurrentUser;

RegistryKey hkcr = Registry.ClassesRoot;

RegistryKey run1 = hklm.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");

foreach(string sValName1 in run1.GetValueNames())

{

this.listBox1.Items.Add(" "+sValName1+":"+run1.GetValue(sValName1));

}

RegistryKey run2 = hkcu.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run");

foreach(string sValName2 in run2.GetValueNames())

{

this.listBox1.Items.Add(" "+sValName2+":"+run2.GetValue(sValName2));

}

this.listBox1.Items.Add("");

this.listBox1.Items.Add("扫描文件的关联状况");

RegistryKey currentversion1 = hklm.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",true);

RegistryKey winlogon = currentversion1.OpenSubKey("Winlogon",true);

RegistryKey windowstoo = currentversion1.OpenSubKey("Windows",true);

try

{

RegistryKey currentversion2 = hklm.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion",true);

string systemdir = currentversion2.GetValue("SystemRoot").ToString();

if(systemdir!="")

{

Share.Ini ini = new Share.Ini(systemdir+"\System.ini");

string explorer = Convert.ToString(ini.IniReadValue("boot","shell"));

if(explorer!="explorer.exe"&&explorer!="Explorer.exe")

{

n++;

this.listBox1.Items.Add(" Shell="+explorer+" 异常");

}

ini = new Share.Ini(systemdir+"\Win.ini");

string run = Convert.ToString(ini.IniReadValue("windows","run"));

if(run!="")

{

n++;

this.listBox1.Items.Add(" run="+run+" 异常");

}

string load = Convert.ToString(ini.IniReadValue("windows","load"));

if(load!="")

{

n++;

this.listBox1.Items.Add(" load="+load+" 异常");

}

}

}

catch(Exception)

{

}

try

{

string explorer = winlogon.GetValue("Shell").ToString();

if(explorer!="explorer.exe"&&explorer!="Explorer.exe")

{

n++;

this.listBox1.Items.Add(" Shell="+explorer+" 异常");

}

string runtoo = windowstoo.GetValue("run").ToString();

if(runtoo!="")

{

n++;

this.listBox1.Items.Add(" run="+runtoo+" 异常");

}

string loadtoo = windowstoo.GetValue("load").ToString();

if(loadtoo!="")

{

n++;

this.listBox1.Items.Add(" load="+loadtoo+" 异常");

}

}

catch(Exception)

{

}

RegistryKey command1 = hkcr.OpenSubKey("txtfile\\shell\\open\\command",true);

foreach(string txt in command1.GetValueNames())

{

string txt1 = command1.GetValue(txt).ToString();

if(txt1!="NOTEPAD.EXE %1"&&txt1!="notepad.exe %1")

{

h++;

this.listBox1.Items.Add(" txt文件关联:"+txt1.ToString()+" 异常");

}

}

RegistryKey command2 = hkcr.OpenSubKey("exefile\\shell\\open\\command",true);

foreach(string exe in command2.GetValueNames())

{

string exe1 = command2.GetValue(exe).ToString();

string exe10 = "\""+"%1"+"\""+" %*";

if(exe1!=exe10)

{

i++;

this.listBox1.Items.Add(" exe文件关联:"+exe1+" 异常");

}

}

RegistryKey command3 = hkcr.OpenSubKey("regfile\\shell\\open\\command",true);

foreach(string reg in command3.GetValueNames())

{

string reg1 = command3.GetValue(reg).ToString();

string reg10 = "regedit.exe "+"\""+"%1"+"\"";

if(reg1!=reg10)

{

j++;

this.listBox1.Items.Add(" reg文件关联:"+reg1+" 异常");

}

}

RegistryKey command4 = hkcr.OpenSubKey("comfile\\shell\\open\\command",true);

foreach(string com in command4.GetValueNames())

{

string com1 = command4.GetValue(com).ToString();

string com10 = "\""+"%1"+"\""+" %*";

if(com1!=com10)

{

k++;

this.listBox1.Items.Add(" com文件关联:"+com1+" 异常");

}

}

RegistryKey command5 = hkcr.OpenSubKey("batfile\\shell\\open\\command",true);

foreach(string bat in command5.GetValueNames())

{

string bat1 = command5.GetValue(bat).ToString();

string bat10 = "\""+"%1"+"\""+" %*";

if(bat1!=bat10)

{

l++;

this.listBox1.Items.Add(" bat文件关联:"+bat1+" 异常");

}

}

}

catch(Exception)

{

}

if(n==0)

this.listBox1.Items.Add(" Explorer.exe、Win.ini、System.ini正常");

if(h==0)

this.listBox1.Items.Add(" txt文件关联正常");

if(i==0)

this.listBox1.Items.Add(" exe文件关联正常");

if(j==0)

this.listBox1.Items.Add(" reg文件关联正常");

if(k==0)

this.listBox1.Items.Add(" com文件关联正常");

if(l==0)

this.listBox1.Items.Add(" bat文件关联正常");

}

private void CheckProcess()

{

try

{

this.listBox1.Items.Add("");

this.listBox1.Items.Add("扫描当前的系统进程");

Process[] procList = new System.Diagnostics.Process[50];

procList = Process.GetProcesses();

d = procList.GetLength(0);

string path = Application.StartupPath;

Share.Ini ini = new Share.Ini(path+"\Virus.dat");

int number = Convert.ToInt16(ini.IniReadValue("VirusList","Number"));

for(int i = 0; i<procList.GetLength(0); i++)

{

string strProcName = procList[i].ProcessName+".exe";

this.textBox1.Text = "ProcName:"+strProcName;

this.textBox1.Refresh();

Thread.Sleep(50);

Activate();

for(int j=0;j<number;j++)

{

string name = Convert.ToString(ini.IniReadValue("VirusList","Name"+j));

if(strProcName.ToLower()==name)

{

this.listBox1.Items.Add(" 名称:"+strProcName);

this.listBox1.Items.Add(" 路径:"+procList[i].MainModule.FileName);

c++;

}

}

}

}

catch(Exception)

{

}

if(c==0)

{

this.listBox1.Items.Add(" 恭喜恭喜,没有发现可疑进程");

}

else

{

this.listBox1.Items.Add(" 共发现"+c+"个可疑进程,请用专业反病毒软件查杀");

}

}

//以上仅是部分源码,程序根据文件名去扫描进程和指定文件,判断是否是可疑文件,并检测注册表中的启动项和文件关联状况。

界面UI:http://bbs.mynbu.cn/UploadFile/2004112314595326661.gif

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有