Question

I'm trying to read in an archive file that contains directories and file entries. I've managed to read out the header of the file and get the info.

You can find info about the format here

now the file contains a Table of contents module starting after 2048 bytes from the origin of the file.

What i know is is that the TOC can contain 2 things :

A directory entry that follows the following structure:

  • 4bytes :int32 : Name offset of where the entry name is stored
  • 4bytes : int32 : Information flags , each bit of the 4 bytes contain info about something
  • 4bytes : Uint32 : Content entry index
  • 4bytes : uint32 : Content entry count

The fileentry follows this structure:

  • 4bytes : int32 : Name offset
  • 4bytes : int32 : File Size
  • 3bytes : Uint24 : Offset of where the file is stored
  • 1byte : Uchar8 : Resource type
  • 4byte : uint32 : Information flags

Now this is for every directory entry or file entry the same.

The problem is i don't know what is first in the toc or what the order is from every entry , it's unkown.

What i do know is from the file header , is the entry count so how many entries there are and the table of contents size.

Is there anyway to find out with the binary reader in what form i need to read every entry in or to find out what specific type of entry it is ?

I will use a for loop for this since i know the entry count from the header.

Any help is apreciated

Was it helpful?

Solution

Well, binary reader can not determine which data type it reads on its own. It simply reads a sequence of bytes. You are the one, who should interpret those bytes. If the protocol used to write your source file is unknown to you, then your best bet is to try figuring it out by trial and error, doing educated guesses. You can assume that the directory entry goes first, you can assume that file entries start after the first content index of first directory entry. Etc. Then you should run your application and see, if those guesses make sense.

If there was no protocol in the first place, and the initial data was written in random order - then there is no way to distict between the entries with information you have.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top