能帮我翻译这个程序吗?kv3000杀毒(200分)

  • 主题发起人 空山鸣涧
  • 开始时间

空山鸣涧

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

Similar threads

I
回复
0
查看
694
import
I
I
回复
0
查看
675
import
I
I
回复
0
查看
758
import
I
I
回复
0
查看
764
import
I
I
回复
0
查看
547
import
I
顶部