1

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

6
  • Please check that Uint24 line. And what clues do you have? Is the first Int32 a count or a size? Commented Aug 14, 2013 at 9:00
  • What format are your trying to read? Commented Aug 14, 2013 at 9:00
  • the first int32 is the same for both actually it's the offset where the name of the entry is stored. @Henk edited the uint24 line it's was just a typo needed to be 3 bytes not 4 ;) Commented Aug 14, 2013 at 9:35
  • @BartoszKP added info to the post ,Henk the problem is i don't know wheter the next entry is a file entry or a directory entry that's the problem i'm having , the knowing , how can i see what it is is there some built-in method that can do this ? Commented Aug 14, 2013 at 9:38
  • Seems like a piece of the puzzle is missing here, this cannot be read deterministically. If it's a known format, post the name. Otherwise reread the specs for the header and flags. Commented Aug 14, 2013 at 11:05

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

ok i see, i'm a little confused now on how i would check to see if the next 4 bytes or the next n bytes are equal to one int ?
@kilianvde, by running your application with debugger attached. Don't get the wrong idea, those assumptions should help you in figuring out the actual protocol. You should not build an algorithm based on them, because it is simply not possible with info available to you.
Ok , i'm using Visual Studio pro btw
okay i got it thanks ! i've managed to find a bit that says if it is a directory or filentry :D

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.