C语言编写简单病毒检测程序

2025-10-09 00:40:25

1、首先打开VC++6.0

C语言编写简单病毒检测程序

2、选择文件,新建

C语言编写简单病毒检测程序

3、选择C++ source file 新建一个空白文档

C语言编写简单病毒检测程序

4、先声明头文件

#include<stdio.h>

#include<ctype.h>

#include<dos.h>

#include<dir.h>

#include<stat.h>

#include<io.h>

#include<string.h>

C语言编写简单病毒检测程序

5、主函数

int main()

{

struct ffblk ffblock;

struct date today;

struct time now;

FILE *fp;

register long int dfv;

char pat[128];

int virus=0,vsize=0;

clrscr();

printf("*********************************\n");

printf("| This is a virus test function |\n");

printf("*********************************\n\n");

printf("Testing virus.................\n\n");

/*取得当前工作路径*/

getcwd(pat,128);

/*切换目录*/

chdir(pat);

/*找到文件COMMAND.COM*/

dfv=findfirst("\\*.*",&ffblock,23);

while(!dfv)

{

if(!strcmp(ffblock.ff_name,"COMMAND.COM"));

vsize=ffblock.ff_fsize/100;

dfv=findnext(&ffblock);

}

if(vsize!=0&&vsize!=478&&vsize!=232&&vsize!=253&&vsize!=2237&&159&&vsize!=252)

{

vsize=0;

printf("This is virus in your computer\n");

virus=1;

}

if((fp=fopen("record.txt","w"))==NULL)

{

printf("Can't open the file record.txt\n");

exit(0);

}

/*取得日期时间*/

getdate(&today);

gettime(&now);

/*记录病毒信息到文件 record.txt*/

if(virus==1)

fprintf(fp,"%d-%d-%d-%d:%0d",today.da_year,today.da_mon,today.da_day,now.ti_hour,now.ti_min);

else

printf("Don't find virus in your computer\n");

fclose(fp);

getch();

return 0;

}

C语言编写简单病毒检测程序

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢