Take the 2-minute tour ×
Reverse Engineering Stack Exchange is a question and answer site for researchers and developers who explore the principles of a system through analysis of its structure, function, and operation. It's 100% free, no registration required.

I have got a file which contains other files. I know where the subfiles start (header) but how do I know where the subfiles end ?

Edit: Files are like: sound files (.wav) and images (.bmp, png, jpeg)

Example:

file1
file2
data
file3

How do I know where file2 starts and file2 ends ?

share|improve this question
    
Do you know the file types? You haven't given us much information, try to modify your question with more info. –  0xea May 2 '14 at 18:13
    
Checkout binwalk. –  caffinatedmonkey May 2 '14 at 21:04

3 Answers 3

up vote 3 down vote accepted

Technically speaking what you're describing is an archive. If the archiving data structure was properly designed, in the header you must find either the start offset & the size or the start & end offsets of each file entry in the header, unless the files are all stored one after the other. In that latter case all you need to know is the start offset of each file because (suppose file0 comes first, followed by file1) file1's start offset is file0's end offset.

The example below shows the latter case :

  Offset00:file0
  Offset10:file1
  Offset30:file2
  Offset35:file3
share|improve this answer

In addition to what yaspr said, i'd suggest looking for specification of those contained files. Most file formats have their size specified in the header somewhere. That would allow you to carve the file from the archive, without even knowing the archive structure.

This is what tools like scalpel are doing to carve files. They match the header to a known file type, and then lookup the file size in that header. Some file formats have specific endings which you could also use to carve them out (for example, every png file has IEND and the end).

Try your luck with scalpel and similar file carving tools.

share|improve this answer
    
WAV (a RIFF format), BMP, and PNG have sufficient information in their headers to do just this. (Does JPEG as well? I believe it does not.) Anyway, knowing the supposed file size ties nicely in to yaspr's answer of how and where to locate the archive's own metadata. –  Jongware May 2 '14 at 22:47

Check out hachoir-subfile. Example from their repo.

$ hachoir-subfile chiens.PPS
[+] Start search (828.5 KB)

[+] Found file at 0: Microsoft Office document
[+] Found file at 537 size=28449 (27.8 KB): JPEG picture: 433x300 pixels
[+] Found file at 29011 size=34761 (33.9 KB): JPEG picture: 433x300 pixels
[+] Found file at 63797 size=40326 (39.4 KB): JPEG picture: 433x300 pixels
[+] Found file at 104148 size=30641 (29.9 KB): JPEG picture: 433x300 pixels
[+] Found file at 134814 size=22782 (22.2 KB): JPEG picture: 384x325 pixels
[+] Found file at 157621 size=24744 (24.2 KB): JPEG picture: 443x313 pixels
[+] Found file at 182390 size=27241 (26.6 KB): JPEG picture: 443x290 pixels
[+] Found file at 209656 size=27407 (26.8 KB): JPEG picture: 443x336 pixels
[+] Found file at 237088 size=30088 (29.4 KB): JPEG picture: 388x336 pixels
[+] Found file at 267201 size=30239 (29.5 KB): JPEG picture: 366x336 pixels
[+] Found file at 297465 size=81634 (79.7 KB): JPEG picture: 630x472 pixels
[+] Found file at 379124 size=36142 (35.3 KB): JPEG picture: 599x432 pixels
[+] Found file at 415291 size=28801 (28.1 KB): JPEG picture: 443x303 pixels
[+] Found file at 444117 size=28283 (27.6 KB): JPEG picture: 433x300 pixels
[+] Found file at 472425 size=95913 (93.7 KB): PNG picture: 433x431x8
[+] Found file at 568363 size=219252 (214.1 KB): PNG picture: 532x390x8
[+] Found file at 811308 size=20644 (20.2 KB): Microsoft Windows Metafile (WMF) picture

ExtractSubFile can be used if you need to carve out the files.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.