如何找到“中央目录"的开头?在 zip 文件中? [英] How does one find the start of the "Central Directory" in zip files?

查看:28
本文介绍了如何找到“中央目录"的开头?在 zip 文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

维基百科对 ZIP 文件格式有很好的描述,但中央目录"结构让我感到困惑.具体来说:

Wikipedia has an excellent description of the ZIP file format, but the "central directory" structure is confusing to me. Specifically this:

这种顺序允许一次性创建一个 ZIP 文件,但通常在最后读取中央目录进行解压.

This ordering allows a ZIP file to be created in one pass, but it is usually decompressed by first reading the central directory at the end.

问题是,即使是中央目录的尾随头也是可变长度的.那么,如何才能获得要解析的中央目录的开头?

The problem is that even the trailing header for the central directory is variable length. How then, can someone get the start of the central directory to parse?

(哦,在来这里问之前,我确实花了一些时间看 APPNOTE.TXT 白费了 :P)

(Oh, and I did spend some time looking at APPNOTE.TXT in vain before coming here and asking :P)

推荐答案

我的哀悼,阅读维基百科的描述给了我一个非常强烈的印象,你需要做大量的猜测+检查工作:

My condolences, reading the wikipedia description gives me the very strong impression that you need to do a fair amount of guess + check work:

从末尾向后搜索 0x06054b50 目录结束标记,向前查找 16 个字节以找到目录开始标记 0x02014b50 的偏移量,希望就是这样.你可以做一些完整性检查,比如在目录结束标签之后寻找注释长度和注释字符串标签,但感觉就像 Zip 解码器一样工作,因为人们不会在他们的 zip 注释、文件名等中放入有趣的字符向前.无论如何,完全基于维基百科页面.

Hunt backwards from the end for the 0x06054b50 end-of-directory tag, look forward 16 bytes to find the offset for the start-of-directory tag 0x02014b50, and hope that is it. You could do some sanity checks like looking for the comment length and comment string tags after the end-of-directory tag, but it sure feels like Zip decoders work because people don't put funny characters into their zip comments, filenames, and so forth. Based entirely on the wikipedia page, anyhow.

这篇关于如何找到“中央目录"的开头?在 zip 文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆