線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2852
推到 Plurk!
推到 Facebook!

XE7 TZipFile 開檔的問題

答題得分者是:aftcast
Main Chen
高階會員


發表:29
回覆:135
積分:127
註冊:2002-10-07

發送簡訊給我
#1 引用回覆 回覆 發表時間:2014-11-10 16:18:17 IP:175.181.xxx.xxx 訂閱
一般 zip 檔案開頭裡有 "$50 $4B $03 $04" 做為壓縮檔頭簽名.

最近用 XE7 裡的 TZipFile 去解壓一個 zip , 但該檔的檔頭簽名並不是在最開頭, 開啟時便會出現錯誤訊息 'Invalid Zip Local Header signature'

但是用一般的解壓工具, 如: WinZip, WinRAR , 皆沒有問題.

這是 Delphi 的問題嗎? 有辦法修正這個問題嗎?
aftcast
站務副站長


發表:81
回覆:1485
積分:1763
註冊:2002-11-21

發送簡訊給我
#2 引用回覆 回覆 發表時間:2014-11-10 19:45:13 IP:114.32.xxx.xxx 訂閱
方便的話,請先上傳你說的delphi開起來有目題的那個 zip 檔上來。研究一下這個zip。


===================引 用 Main Chen 文 章===================
一般 zip 檔案開頭裡有 "$50 $4B $03 $04" 做為壓縮檔頭簽名.

最近用 XE7 裡的 TZipFile 去解壓一個 zip , 但該檔的檔頭簽名並不是在最開頭, 開啟時便會出現錯誤訊息 'Invalid Zip Local Header signature'

但是用一般的解壓工具, 如: WinZip, WinRAR , 皆沒有問題.

這是 Delphi 的問題嗎? 有辦法修正這個問題嗎?
------


蕭沖
--All ideas are worthless unless implemented--

C++ Builder Delphi Taiwan G+ 社群
http://bit.ly/cbtaiwan
Main Chen
高階會員


發表:29
回覆:135
積分:127
註冊:2002-10-07

發送簡訊給我
#3 引用回覆 回覆 發表時間:2014-11-11 08:14:30 IP:175.181.xxx.xxx 訂閱
測試檔: test.zip
http://pan.baidu.com/s/1hqxgm7U

這個檔是我使用 TMS cloud 元件上傳到 Google 雲端硬碟後, 它會在前端加入:
--AaB03x
Content-Disposition: form-data; name="userfile"; filename="test.zip"
Content-Type: application/octet-stream

但原始壓縮檔裡是沒有這些內容, 我猜是 Google 雲端硬碟加的, 因為我用它上傳到 DropBox 也沒有這些內容.
這會造成 TZipFile 無法解壓.

目前也還沒有第三方支援 Firemonkey 的跨平台 ZIP 元件, 所以可能只能自行修改 System.zip.pas 才能解決了.
pcplayer99
尊榮會員


發表:146
回覆:790
積分:632
註冊:2003-01-21

發送簡訊給我
#4 引用回覆 回覆 發表時間:2014-11-11 11:19:47 IP:120.236.xxx.xxx 訂閱
我理解,你的问题是:档案前面被 GOOGLE 加上了 AaB03x 所以才有问题?

如果是这样,你下载下来的档案,先去掉前面几个 Byte 不就好了?

===================引 用 Main Chen 文 章===================
測試檔: test.zip
http://pan.baidu.com/s/1hqxgm7U

這個檔是我使用 TMS cloud 元件上傳到 Google 雲端硬碟後, 它會在前端加入:
--AaB03x
Content-Disposition: form-data; name="userfile"; filename="test.zip"
Content-Type: application/octet-stream

但原始壓縮檔裡是沒有這些內容, 我猜是 Google 雲端硬碟加的, 因為我用它上傳到 DropBox 也沒有這些內容.
這會造成 TZipFile 無法解壓.

目前也還沒有第三方支援 Firemonkey 的跨平台 ZIP 元件, 所以可能只能自行修改 System.zip.pas 才能解決了.
Main Chen
高階會員


發表:29
回覆:135
積分:127
註冊:2002-10-07

發送簡訊給我
#5 引用回覆 回覆 發表時間:2014-11-11 11:48:31 IP:175.181.xxx.xxx 訂閱
是的, 這是正確的修正方法, 但如果能由官方去修正這個問題, 不是更完美嗎?

===================引 用 pcplayer99 文 章===================
我理解,你的问题是:档案前面被 GOOGLE 加上了 AaB03x 所以才有问题?

如果是这样,你下载下来的档案,先去掉前面几个 Byte 不就好了?

===================引 用 Main Chen 文 章===================
測試檔: test.zip
http://pan.baidu.com/s/1hqxgm7U

這個檔是我使用 TMS cloud 元件上傳到 Google 雲端硬碟後, 它會在前端加入:
--AaB03x
Content-Disposition: form-data; name="userfile"; filename="test.zip"
Content-Type: application/octet-stream

但原始壓縮檔裡是沒有這些內容, 我猜是 Google 雲端硬碟加的, 因為我用它上傳到 DropBox 也沒有這些內容.
這會造成 TZipFile 無法解壓.

目前也還沒有第三方支援 Firemonkey 的跨平台 ZIP 元件, 所以可能只能自行修改 System.zip.pas 才能解決了.
aftcast
站務副站長


發表:81
回覆:1485
積分:1763
註冊:2002-11-21

發送簡訊給我
#6 引用回覆 回覆 發表時間:2014-11-11 14:17:33 IP:114.32.xxx.xxx 訂閱
 在官方沒修改源碼前,我覺得還是自救,但不儘量不要去自行改它的源碼,這樣未來相容性比較好。
此外,依wikipedia的說明:
There is no BOF or EOF marker in the .ZIP specification. Conventionally the first thing in a .ZIP file is a .ZIP entry, which can be identified easily by its local file header signature. However, this is not necessarily the case, as this not required by the .ZIP specification.
Tools that correctly read .ZIP archives must scan for the end of central directory record signature, and then, as appropriate, the other, indicated, central directory records. They must not scan for entries from the top of the ZIP file, because only the central directory specifies where a file chunk starts. Scanning could lead to false positives, as the format does not forbid other data to be between chunks, nor file data streams from containing such signatures. However, tools that attempt to recover data from damaged .ZIP archives will most likely scan the archive for local file header signatures; this is made more difficult by the fact that the compressed size of a file chunk may be stored after the file chunk, making sequential processing difficult.
Most of the signatures end with the short integer 0x4b50, which is stored in little-endian ordering. Viewed as an ASCII string this reads "PK", the initials of the inventor Phil Katz. Thus, when a .ZIP file is viewed in a text editor the first two bytes of the file are usually "PK". (DOS, OS/2 and Windows self-extracting ZIPs have an bool mayZip = false;



[/code]
------


蕭沖
--All ideas are worthless unless implemented--

C++ Builder Delphi Taiwan G+ 社群
http://bit.ly/cbtaiwan
aftcast
站務副站長


發表:81
回覆:1485
積分:1763
註冊:2002-11-21

發送簡訊給我
#7 引用回覆 回覆 發表時間:2014-11-11 14:21:54 IP:114.32.xxx.xxx 訂閱
 上面的code貼亂了! 又無法去做「修改」,因為會報錯@@  . (題外話,為了防止被連續貼文,本站的防止機制"過當"……

TMemoryStream *ms = new TMemoryStream;
ms->Position = 0;
if (ms->Size > SIG_SIZE) {
Byte *buf = (Byte*) ms->Memory;
if (buf[pos]==0x50 && buf[pos 1]==0x4b &&
mayZip = true;
break;
}
ShowMessage("Not a zip file");
}
zipStream->CopyFrom(ms,ms->Size-ms->Position);
int i = zipStream->Position;
// Byte by = buf[zipStream->Size-1];
zipFile->Open(zipStream,zmRead);
zipFile->Close();
delete zipStream;
delete ms;
------


蕭沖
--All ideas are worthless unless implemented--

C++ Builder Delphi Taiwan G+ 社群
http://bit.ly/cbtaiwan
aftcast
站務副站長


發表:81
回覆:1485
積分:1763
註冊:2002-11-21

發送簡訊給我
#8 引用回覆 回覆 發表時間:2014-11-11 17:18:01 IP:114.32.xxx.xxx 訂閱
我再補上上面例題程式碼的 hight light 貼文,比較好看,也可下載。

pastebin.com/NQXFWNG5
------


蕭沖
--All ideas are worthless unless implemented--

C++ Builder Delphi Taiwan G+ 社群
http://bit.ly/cbtaiwan
Main Chen
高階會員


發表:29
回覆:135
積分:127
註冊:2002-10-07

發送簡訊給我
#9 引用回覆 回覆 發表時間:2014-11-12 07:27:14 IP:175.181.xxx.xxx 訂閱
感謝 蕭兄 提供修正方案, 解決此一燃眉之急!

===================引 用 aftcast 文 章===================
我再補上上面例題程式碼的 hight light 貼文,比較好看,也可下載。

pastebin.com/NQXFWNG5
系統時間:2024-03-29 10:17:07
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!