空
空山鸣涧
Unregistered / Unconfirmed
GUEST, unregistred user!
这是一个简单的kv3000杀毒代码,c写的,可以编译成功,我想改为D的,但是对我难度太大了。想请高人帮忙,不过这是体力活儿,没有耐性没有时间就算了。<br> 如果有类似的现成D代码那就更加感激了!<br>//////////////////////////////////////////////////////////////////////////////<br>#include <stdio.h><br>#include <string.h><br>#include <dos.h><br>#include <io.h><br>#include <alloc.h><br>#include <conio.h><br>#include <fcntl.h><br>#include <stdlib.h><br>#include <ctype.h><br>#include <dir.h><br><br>#define ITEM 100<br>FILE *file;<br>unsigned char dat[ITEM][256],d[2];<br>unsigned char string[ITEM][256];<br>unsigned char vn[ITEM];<br><br>int vl;<br>int find (unsigned char *dat1,unsigned char *hex)<br>{<br> unsigned long len=strlen(dat1);<br> unsigned long num=0,hnum=0;<br> unsigned long i;<br> for (i=0;i<len;i++) {<br> if (dat1!=hex[hnum]) {<br> if (dat1=='?') {<br> i++;hnum=hnum+2;continue;<br> }<br> if (dat1=='%') {<br> i++;<br> for (num=0;num<32;num++) {<br> if (dat1[i+1]==hex[hnum+num]) {<br> if (find(&dat1[i+1],&hex[hnum+num])==1) return 1;<br> }<br> }<br> }<br> return 0;<br> }<br> hnum++;<br> }<br> return 1;<br>}<br><br>int findvirus (char *filename)<br>{<br> int fh;<br> int rnum=1;<br> unsigned char *buf;<br> unsigned char *hex;<br> unsigned char x1,x2;<br> unsigned long rsize=5000;<br> unsigned long flen,i,j;<br> int v;<br> memset (vn,'0',ITEM-1);<br> if ((hex=(unsigned char *)farmalloc(10000))==NULL) {<br> puts ("Out of memory ."return 1;<br> }<br> if ((buf=(unsigned char *)farmalloc(5000))==NULL) {<br> puts ("Out of memory ."return 1;<br> }<br> fh=open (filename,O_BINARY);<br> flen=filelength(fh);<br> if (flen<=rsize) {<br> rsize=flen;rnum=0;<br> }<br> for (j=0;j<=rnum;j++) {<br> if (j==1) lseek (fh,-rsize,2);<br> else lseek (fh,0,0);<br> if (read(fh,buf,rsize)==-1) {<br> puts ("Read file ERROR ."return 0;<br> }<br> for (i=0;i<rsize;i++) {<br> x1=buf/16;<br> x2=buf-x1*16;<br> hex[2*i]=x1<10?x1+0x30:x1-10+0x41;<br> hex[2*i+1]=x2<10?x2+0x30:x2-10+0x41;<br> }<br> for (v=0;v<=vl;v++) {<br> for (i=0;i<rsize;i++) {<br> if (hex[2*i]==dat[v][0]&&hex[2*i+1]==dat[v][1])<br> if (find(dat[v],&hex[2*i])==1) {<br> if (vn[v]=='0') {<br> vn[v]='1';<br> puts (" "<br> puts (string[v]);<br> }<br> }<br> }<br> }<br> }<br> farfree (hex);<br> farfree (buf);<br> close (fh);<br> return 0;<br>}<br><br>void findfile()<br>{<br> int p,hav,x,y,len;<br> struct ffblk dirment,fname;<br> char path[256];<br> getcwd (path,256);<br> hav=findfirst ("*.*",&fname,FA_RDONLY|FA_HIDDEN|FA_SYSTEM);<br> while (!hav) {<br> x=wherex();<br> len=strlen(path);<br> clreol();<br> if (len!=3) printf ("Scaning %s//%s",path,fname.ff_name);<br> else printf ("Scaning %s%s",path,fname.ff_name);<br> if ((strstr(fname.ff_name,".EXE"!=NULL)||(strstr(fname.ff_name,".COM"!=NULL))<br> findvirus (fname.ff_name);<br> y=wherey();<br> gotoxy (x,y);<br> hav=findnext (&fname);<br> }<br> p=findfirst ("*.*",&dirment,0x3f);<br> if (!p&&dirment.ff_name[0]=='.') {<br> p=findnext (&dirment);<br> p=findnext (&dirment);<br> }<br> while (!p) {<br> if ((dirment.ff_attrib&0x10)==FA_DIREC) {<br> chdir (dirment.ff_name);<br> findfile();<br> chdir(".."<br> }<br> p=findnext (&dirment);<br> }<br>}<br><br>main (int argc,char *argv[])<br>{<br> char curdrive=getdisk();<br> char curpath[256],drive,virdat[16];<br> unsigned long n;<br> unsigned long dnum;<br> int end=0;<br> if (argc<2||argv[1][1]!=':') {<br> puts ("Usage: KILL driveath [virusdata]"<br> return 1;<br> }<br> if (argc==2) strcpy (virdat,"VIRUS.DAT"<br> else strcpy (virdat,argv[2]);<br> file=fopen (virdat,"r"<br> if (file==NULL) exit(0);<br> fseek (file,1,0);<br> for (vl=0;vl<ITEM;vl++) {<br> for (dnum=0,n=0;dnum<256;dnum++) {<br> fread (d,1,1,file);<br> if (d[0]=='"') { dat[vl][n]='/0';break;}<br> if (d[0]==' ') continue;<br> dat[vl][n]=d[0];<br> n++;<br> }<br> for (dnum=0,n=0;dnum<256;dnum++) {<br> if (fread (d,1,1,file)==NULL) { string[vl][n]='/0';end=1;break;}<br> if (d[0]=='"') { string[vl][n]='/0';break;}<br> if (d[0]<0x20) continue;<br> string[vl][n]=d[0];<br> n++;<br> }<br> strupr (dat[vl]);<br> if (end==1) break;<br> }<br> getcwd (curpath,256);<br> drive=toupper(argv[1][0])-'A';<br> setdisk (drive);<br> chdir ("//"<br> chdir (argv[1]);<br> findfile();<br> setdisk (curdrive);<br> chdir (curpath);<br> fclose(file);<br> return 0;<br>}<br>////////////////////////////////////////////////////////////////////////////////<br> 这个的功能太简单了,我的意思大家肯定明白,就是想学习一下杀毒软件的编写。本人大三,纯属爱好,没有其他想法。