主题:zlib 解压swf文件错误!哪位大侠帮我看看!
最近做一个东西,需要从swf文件中读取一段代码,但swf文件6。0后用zlib压缩了,所以需要写一个解压的程序,我找了好些资料,写了个程序,可是总是出错,解压不出来,如果是本程序压缩的,都能解压出来!
代码如下:
procedure Zip(Input,Output:TStream;Compress:Boolean);
const
MAXBUFSIZE=1024 * 16; //16 KB
var
CS:TCompressionStream;
DS:TDecompressionStream;
Buf:array[0..MAXBUFSIZE-1] of Byte;
BufSize:Int64;
begin
if Assigned(Input) and Assigned(Output) then
begin
if Compress then
begin
CS:=TCompressionStream.Create(clDefault,Output);
try
CS.CopyFrom(Input,0); //从开始处复制
finally
CS.Free;
end;
end else
begin
DS:=TDecompressionStream.Create(Input);
try
BufSize:=DS.Read(Buf,MAXBUFSIZE); //这里就出错了,!
while BufSize>0 do
begin
Output.Write(Buf,BufSize);
BufSize:=DS.Read(Buf,MAXBUFSIZE);
end;
finally
DS.Free;
end;
end;
end;
end;
按钮代码:
procedure TForm1.BtnSwf1Click(Sender: TObject);
var
tm,SM,dm,mm: TMemoryStream;
begin
If trim(Edit2.Text) = '' then Exit;
If trim(Edit3.Text) = '' then Exit;
SM := TMemoryStream.Create;
dm := TMemoryStream.Create;
tm := TMemoryStream.Create;
mm := TMemoryStream.Create;
try
Sm.LoadFromFile(Edit2.Text);
Sm.Position := 8; //指针移动到文件头后,
tm.CopyFrom(sm,sm.Size -8);
memo1.Lines.Add('解压前文件:'+edit2.Text+' 文件大小:'+IntToStr(tm.Size));
tm.Position := 0;
Zip(tm,dm,False);
//合并文件头和解压后body
Sm.Position := 0;
MM.CopyFrom(SM,8);
DM.Position :=0;
MM.Position := 8;
MM.CopyFrom(DM,DM.Size);
MM.SaveToFile(Edit3.Text);
memo1.Lines.Add('解压后文件:'+edit2.Text+' 文件大小:'+IntToStr(MM.Size));
finally
SM.Free;
DM.Free;
TM.Free;
MM.Free;
end;
end;
哪位大侠帮我看看,错在哪里!
代码如下:
procedure Zip(Input,Output:TStream;Compress:Boolean);
const
MAXBUFSIZE=1024 * 16; //16 KB
var
CS:TCompressionStream;
DS:TDecompressionStream;
Buf:array[0..MAXBUFSIZE-1] of Byte;
BufSize:Int64;
begin
if Assigned(Input) and Assigned(Output) then
begin
if Compress then
begin
CS:=TCompressionStream.Create(clDefault,Output);
try
CS.CopyFrom(Input,0); //从开始处复制
finally
CS.Free;
end;
end else
begin
DS:=TDecompressionStream.Create(Input);
try
BufSize:=DS.Read(Buf,MAXBUFSIZE); //这里就出错了,!
while BufSize>0 do
begin
Output.Write(Buf,BufSize);
BufSize:=DS.Read(Buf,MAXBUFSIZE);
end;
finally
DS.Free;
end;
end;
end;
end;
按钮代码:
procedure TForm1.BtnSwf1Click(Sender: TObject);
var
tm,SM,dm,mm: TMemoryStream;
begin
If trim(Edit2.Text) = '' then Exit;
If trim(Edit3.Text) = '' then Exit;
SM := TMemoryStream.Create;
dm := TMemoryStream.Create;
tm := TMemoryStream.Create;
mm := TMemoryStream.Create;
try
Sm.LoadFromFile(Edit2.Text);
Sm.Position := 8; //指针移动到文件头后,
tm.CopyFrom(sm,sm.Size -8);
memo1.Lines.Add('解压前文件:'+edit2.Text+' 文件大小:'+IntToStr(tm.Size));
tm.Position := 0;
Zip(tm,dm,False);
//合并文件头和解压后body
Sm.Position := 0;
MM.CopyFrom(SM,8);
DM.Position :=0;
MM.Position := 8;
MM.CopyFrom(DM,DM.Size);
MM.SaveToFile(Edit3.Text);
memo1.Lines.Add('解压后文件:'+edit2.Text+' 文件大小:'+IntToStr(MM.Size));
finally
SM.Free;
DM.Free;
TM.Free;
MM.Free;
end;
end;
哪位大侠帮我看看,错在哪里!