2012-08-22 15 views
0

據我瞭解,加密狀態包含在通用位標誌中。我試着用ZipArchive :: statname()來檢查它,但似乎無法通過此方法獲取信息。如何檢查PHP中的加密Zip存檔?

我還能做什麼?閱讀檔案並解析標題?我知道我可以調用system(),但我不想使用此方法,因爲它的特殊性(某些託管此功能被禁用)。

+0

你用ZipArchive :: statname試過了什麼?你有錯誤信息嗎?請給我們更多的信息。 – Frog

+0

ZipArchive打開加密文件,但提供的信息不夠。方法'ZipArchive :: statIndex()'的返回值[示例](http://pastebin.com/ZetmVLKa)。我試圖通過'comp_method'來識別加密的檔案,但沒有發現依賴關係。 – Ticksy

+1

Ticksy我甚至爲你 – Peter

回答

4

這裏是ZIP標準:http://www.pkware.com/documents/casestudies/APPNOTE.TXT

從第4.3.7節:

4.3.7 Local file header: 

    local file header signature  4 bytes (0x04034b50) 
    version needed to extract  2 bytes 
    general purpose bit flag  2 bytes 
    compression method    2 bytes 
    ... 

從第4.4.4節:

4.4.4 general purpose bit flag: (2 bytes) 

    Bit 0: If set, indicates that the file is encrypted. 
    ... 

所以你需要檢查第七字節第一位的,而不是整個字節。您必須對每個文件進行檢查,因爲每個文件都可以單獨進行加密(第4.3.6節)。

+0

不錯,我一直懶得學習文檔 – Peter

5

ZIP文件頭:(加密文件與正常文件)

enter image description here

09 seemts是加密標誌。

檢查第7個字節爲0x09

function zip_is_encrypted($filename) { 
    $handle = fopen($filename, "rb"); 
    $contents = fread($handle, 7); 
    fclose($handle); 
    return $contents[6] == 0x09; 
} 
+1

+1做出簡單的函數來一些正式文件指定位的引用將是不錯 –

+1

@owlstead [標準](http://www.pkware.com/documents/casestudies/APPNOTE.TXT)。關於加密: '4.4.4通用位標誌:(2個字節) 位0:如果設置,表明@owlstead您需要檢查第七字節第一位的文件被encrypted.' –

+1

。 –