简体   繁体   中英

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. 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? 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. 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.

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/ . It often uses file-headers to determine the type of a file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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