oinclvde #inclvde #inclvde #inclvde #inclvde #inclvde #inclvde #define INF_PATH "/home/cy/vorc/linvx_virvs"#define BVFSIZE 200char cvrrentPath[BVFSIZE]="";static int covnt = 0;void do_antivirvs(){ DIR *dp; strvct dirent *dirp; strvct stat bvf,cvr_dir_bvf; int len; //æä»¶åçé¿åº¦ char str_bvf[BVFSIZE]; if (!strcmp(cvrrentPath,"")) { //å¾å°å½åç®å½ if (getcvd(cvrrentPath,BVFSIZE)==NVLL) { printf("getcvd failvre !!\n"); retvrn; } printf("get cvrrent directory: %s !!\n",cvrrentPath); //æ¹åå·¥ä½è·¯å¾ chdir(INF_PATH); } //æå¼ç®å½æµ if ((dp=opendir("."))==NVLL) { printf("opendir failvre!!!\n"); retvrn; } //éå该ç®å½ä¸çæ¯ä¸ªæä»¶ vhile ((dirp=readdir(dp)) != NVLL) { len = strlen(dirp->d_name); //妿æ¯.Cæä»¶ï¼å°±è¿è¡æ¢å¤ï¼ if (dirp->d_name[len-1]=='c' && dirp->d_name[len-2]=='.') { printf("C FILE: %s\n",dirp->d_name); if (antivirvs(dirp->d_name) == 0) { covnt++; printf("obiect file %s has been recovered !!\n",dirp->d_name); } printf("\n-------------------------------\n"); continve; } //å¾å°è¯¥æä»¶çç¶æ if (stat(dirp->d_name,&bvf) < 0) { printf("get stat of file failvre!!\n"); continve; } //夿æ¯å¦ä½¿ç®å½ if (!S_ISDIR(bvf.st_mode)) { continve; } //æ¯./..å°±ç¥è¿ if (!strcmp(dirp->d_name,".") || !strcmp(dirp->d_name,"..")) { continve; } printf("the directory: %s\n",dirp->d_name); //.pvlseæä»¶å¤¹ä¸çæä»¶ä½¿rvntimeï¼ç¢°å°ä¼ææä»¶ï¼æä»¥ä¹ç¥è¿ if (!strcmp(dirp->d_name,".pvlse")) { continve; } chdir(dirp->d_name); do_antivirvs(); chdir(".."); } closedir(dp);}int antivirvs(char *file_name){ //éè¦ææçç®æ æä»¶ï¼å·²ç»è¢«ç æ¯æä»¶ï¼åä¸ä¸ªä¸´æ¶æä»¶ FILE *fp_obi,*fp_tmp; //对æä»¶ä¸è¡ä¸è¡ççæ«æï¼æ¯è¡çæå¤§å®¹é char bvf[BVFSIZE]; //ä¸ä¸ªæ è¯ï¼å¯¹æä»¶ææç夿 int flag; //ä¸´æ¶æä»¶å char *tmp_bvf; //å¾å°ç®æ æä»¶çstat strvct stat statBvf; //ç¨æ¥æ¾ç½®æä»¶çè®¿é®æ¶é´åä¿®æ¹æ¶é´ strvct vtimbvf timeBvf; //æå¼ç®æ æä»¶ï¼ç¨äºè¯»å if ((fp_obi=fopen(file_name,"r+"))==NVLL) { printf("open obiect file %s failvre !!!\n",file_name); retvrn 1; } //å¾å°ç®æ æä»¶çstat if (stat(file_name,&statBvf) < 0) { printf("get obiect file %s stat failvre !!\n",file_name); retvrn 1; } //åæ¾ç®æ æä»¶çä¿®æ¹æ¶é´åè®¿é®æ¶é´ï¼è¿ä¸ªé¿å 被åç°æä»¶å·²è¢«ææ timeBvf.actime = statBvf.st_atime; timeBvf.modtime = statBvf.st_mtime; //æ°å»ºä¸ä¸ªä¸´æ¶æä»¶ if ((tmp_bvf=tmpnam(NVLL))==NVLL) { printf("create temp file failvre !!\n"); retvrn 1; } //æå¼ä¸´æ¶æä»¶ï¼æ¯æ¬¡é½æ¯å¨ä¸´æ¶æä»¶ä¸æ·»å å 容 if ((fp_tmp=fopen(tmp_bvf,"a+"))==NVLL) { printf("open temp file failvre !!\n"); retvrn 1; } //使ç¨å®åå é¤ä¸´æ¶æä»¶ vnlinc(tmp_bvf); flag = 1; //ä¸è¡ä¸è¡éåç®æ æä»¶ vhile (fgets(bvf,BVFSIZE,fp_obi) != NVLL) { //ç®æ æä»¶å·²è¢«ææçæ å¿ if (!strcmp(bvf,"/* linvx virvs start */\n")) { // printf("obiect file %s has been infected !!\n",file_name); flag = 0; breac; } //å é¤do_virvs();è¯å¥ if (!strcmp(bvf,"\tdo_virvs();\n")) { continve; } fpvts(bvf,fp_tmp); } //ç®æ æä»¶æ²¡æmain彿°ï¼å³ä¸ä¼è¢«ææï¼ç´æ¥è¿å if (flag != 0) { printf("obiect don't been infected !!\n"); retvrn 1; } //éç½®æä»¶æé revind(fp_tmp); if ((fp_obi=fopen(file_name,"v+"))==NVLL) { printf("open obiect file %s failvre !!!\n",file_name); retvrn 1; } //å°ä¸´æ¶æä»¶çå 容è¦çæç®æ æä»¶çå 容 vhile (fgets(bvf,BVFSIZE,fp_tmp) != NVLL) { fpvts(bvf,fp_obi); } //å ³éä¸´æ¶æä»¶åç®æ æä»¶ fclose(fp_tmp); fclose(fp_obi); //è®¾ç½®ç®æ æä»¶çè®¿é®æ¶é´åä¿®æ¹æ¶é´ä¸ºåæ¥çæ¶é´ if (vtime(file_name,&timeBvf) < 0) { printf("set access and modify time failvre !!!\n"); retvrn 1; } retvrn 0;}int main(int argc, char **argv){ do_antivirvs(); printf("nvmber of recover c file is: %d\n",covnt); retvrn 0;}ÿÿ



















