简体   繁体   English

读/写文件头

[英]Read / Write File Headers

I'm trying to edit a file header for a file. 我正在尝试编辑文件的文件头。 But if i get the bytes from the file (NSData) i can't see or know where the header starts and the payload starts. 但是,如果我从文件(NSData)中获取字节,我将看不到或不知道标头从何处开始以及有效负载从何处开始。 So when i would like to add a signature or something else it is impossible. 因此,当我想添加签名或其他内容时,这是不可能的。

Can somebody point me in the right direction? 有人可以指出我正确的方向吗?

And what do the fileheaders in iOS look like? iOS中的文件头是什么样的? I can't find a unified header format either, which makes it even harder to read. 我也找不到统一的标题格式,这使得阅读起来更加困难。

Summary: I would like to know where the header begins and ends. 摘要:我想知道标题的开始和结束位置。 I would like to edit this header. 我想编辑此标题。 I would like to know the structure of a fileheader. 我想知道文件头的结构。

A file header in iOS looks like a file header in any other operating system. iOS中的文件头看起来像任何其他操作系统中的文件头。 It can be whatever you want it to be and be as long or short as you wish. 它可以是您想要的任何长度,可以长短都可以。 If you want it to be variable-length then one method is to start it with a magic number (which is actually a four-letter UTF-8 string that means something significant) and then perhaps a 32-bit header length, encoded in little-endian (as iOS and OSX are little-endian) and then whatever you need to encode. 如果您希望它是可变长度的,那么一种方法是从一个魔术数字 (实际上是一个四个字母的UTF-8字符串,表示有意义的东西)开始,然后是一个32位的标头长度,以小写形式编码-endian(因为iOS和OSX是little-endian),然后进行任何编码。

For a sample of what file headers are currently in existence, look at the file command and look at the files in /usr/share/file/magic/ . 有关当前存在哪些文件头的示例,请查看file命令并查看/usr/share/file/magic/ It often uses file-headers to determine the type of a file. 它通常使用文件头来确定文件的类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM