自己写了个,不过速度和压缩比都没原版的好,感觉上还可以优化,不过水平有限,希望能得到高人的指点
程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
unsigned char buf[0x2000000];
main()
{
FILE *fa,*fb,*fc;
unsigned int r=0,k=0,c=0,x=0,y=0,size,b,t=0,n,tt=0;
unsigned char ah,bh,ch,xh,yh,zh,aa,zz;
if((fa=fopen("BOSS.dat","rb"))==NULL){exit(0);}
if((fb=fopen("temp.bin","wb+"))==NULL){exit(0);}
if((fc=fopen("0.bin","wb+"))==NULL){exit(0);}
fseek(fa,0,2);
size=ftell(fa);
fseek(fa,0,0);
ah = fgetc(fa);fputc(ah,fc);fputc(ah,fb); x++;
ah = fgetc(fa);fputc(ah,fc);fputc(ah,fb); x++;
ah = fgetc(fa);fputc(ah,fc);fputc(ah,fb); x++;
for(n=0;n<size;)
{
ah = fgetc(fa);
bh = fgetc(fa);
ch = fgetc(fa);n+=3;tt=3;if(n>=size)break;
printf("%x \n", n);
if(x>0xff){c=0xff;}//回退量最大退ff字节
else{c=x;}
r=0;
fseek(fb,-c,1);
for(y=0;y<c;)
{
fseek(fb,-r,1);
c=c+r;
xh = fgetc(fb);
c--;if(c==0)break;
r=0;
if(ah==xh)
{
yh = fgetc(fb);r=1; c--;if(c==0)break;
if(bh==yh)
{
zh = fgetc(fb);r=2; c--;
if(ch==zh)
{
b=c+3;r=3;t=0;tt=0;
if(c!=0)
{
for(;;)
{
aa = fgetc(fa);
zz = fgetc(fb);
n++;if(n==size)break;//读完数据跳出
if(aa!=zz)break;//不相同跳出
r++;buf[t++] = aa; c--;if(c==0)break;//回退量最==0退出
if(r==0x3f)break;//大于复制的字节数跳出
}
}
fseek(fb,0,2);fputc(ah,fb);fputc(bh,fb);fputc(ch,fb);x+=3;
for(y=0;y<t;y++){ah = buf[y];fputc(ah,fb);x++;}
r=r+0xc0;
fwrite(&r,sizeof(char),1,fc);
fwrite(&b,sizeof(char),1,fc);
fseek(fa,-1,1); n--;
if((r==0xff)||(c==0)){fseek(fa,1,1);n++;if(n==size)break;}
goto loop;
}
}
}
}
if(n==size)break;
if(r<3)
{
if(ah<0xc0){fputc(ah,fc);}
else{fputc(0xc1,fc);fputc(ah,fc);}
fseek(fb,0,2);fputc(ah,fb);
fseek(fa,-2,1); x++;n-=2;
}
loop:;}
fputc(0xc0,fc);
fcloseall();
remove("temp.bin");
return 1;
}