[lug] magic number

Tkil tkil at scrye.com
Sun Aug 7 23:08:14 MDT 2005


>>>>> "Jason" == Jason Davis <mohadib at openactive.org> writes:

Jason> So I'm writing an app that uses a files magic number to know if
Jason> it is a MP3. I got it working mostly , however , I think I
Jason> might be confused.

First off, if you can at all use it, just use 'file' itself.  It has a
huge number of patterns in it.

Second, I was unaware that MP3s were stored in RIFF containers.  Weird.

Third, RIFF is the little-endian version of AIFF.  Any multi-byte
binary values will be written in little-endian format.  So, when
dealing with a 16-bit "short", you have to read in the least
significant byte and then the more significant byte.

When I had to solve this problem myself, I investigated the format of
WAV and RIFF files, then built objects that could read and write
themselves.  For primitives, I used objects that represented
individual little-endian bytes [identity, yes], 16-byte "shorts",
32-byte "ints" and 32-byte "floats".  Then I can just read in the
whole structure and use normal c / c++ / java structure access to get
at it.

If those two bytes do hold a 16-bit little-endian "short" value of 85
decimal, then the two byte should be: 55 00 (respectively).

Or did I totally miss the point of your question?

t.



More information about the LUG mailing list