Posts Tagged ‘BitsReader’

BitsReader: Read bits from given ByteArray

System-Binary I am working on SWF file decompiling according to the swf_file_format_spec_v9.pdf provided by adobe these days.  After I decompiled the first 8 bytes data of a sample SWF file. I found that the FrameSize is defined as a RECT structure below:

  1. RECT
  2. Field Type Comment
  3. Nbits UB[5] Bits in each rect value field
  4. Xmin SB[Nbits] x minimum position for rect
  5. Xmax SB[Nbits] x maximum position for rect
  6. Ymin SB[Nbits] y minimum position for rect
  7. Ymax SB[Nbits] y maximum position for rect

I have to read the first 5 bits from a ByteArray contains 9 bytes as the Nbits, then read 15 bits each time to get the positions for the rect.

That’s really a hard work for me to get bits from the binary data, I have never do such thing before.

I wrote a lot of codes, and tried many ways to get what I want . But I found all of them are not “beautiful” enough. At last, I got this simple class to catch what I want.

This class is used to read any amount,less than 53, bits from a given ByteArray.

Search-256x256 Demo | DownloadDownload Full Project

(more…)