/* Xuanmu */Houjie
I want to deduct something from the SWF file and read the format of the file for the whole 2 weeks ...... -_-#
However, the rule can be parsed almost now. At the beginning, it was a bit dizzy to see this structure. In fact, you can skip it, but if you write a complete SWFparser, this step cannot be skipped. Now we can finally figure out how to calculate it. Extract the algorithm from the program for your convenience.
The example is the default blank file, which is very rigid. According to the instructions in the file format specification, there are actually many very simple methods ......
<?
/*--------------------------------------
SWF file RECT structure algorithm PHP implementation
Author: xuanmumu [xuanmumu@gmail.com]
Date: 2009/5/26
---------------------------------------*/
$ Fp = fopen(test1.swf, "r ");
If ($ fp ){
// Fseek ($ fp, 8)
$ Sign = fread ($ fp, 3 );
If ($ sign! = "FWS" & $ sign! = "CWS "){
Echo "Wrong file ";
}
Fseek ($ fp, 8 );
$ Firstbyte = fread ($ fp, 1 );
$ Newfirstbyte = bin2hex ($ firstbyte );
$ Change_newfirstbyte = decbin (hexdec ($ newfirstbyte ));
If (strlen ($ change_newfirstbyte )! = 8 ){
$ New_change_newfirstbyte = str_pad ($ change_newfirstbyte, 8, "0", STR_PAD_LEFT );
}
// Echo $ new_change_newfirstbyte;
$ Fieldsize = ord ($ firstbyte)> 3;
Echo "RECT field size:". $ fieldsize. "<br> ";
$ Needbytes = ceil ($ fieldsize * 4/8) + 1;
// Echo $ needbytes;
For ($ I = 0; $ I <8; $ I ++ ){
$ Nextbytes = bin2hex (fread ($ fp, 1 ));
Echo $ nextbytes. "<br> ";
$ Change_bin = decbin (hexdec ($ nextbytes ));
// Echo $ change_bin. "<br> ";
If (strlen ($ change_bin) <= 8)
$ New_change_bin = str_pad ($ change_bin, 8, "0", STR_PAD_LEFT );
// Echo $ new_change_bin. "<br> ";
$ Bytes. = $ new_change_bin;
}
// Echo $ bytes;
$ Allbytes = $ new_change_newfirstbyte. $ bytes;
// Echo $ allbytes. "<br> ";
$ Thefirstfivebits = substr ($ allbytes, 0, 5 );
Echo $ thefirstfivebits. "<br> ";
$ Next1 = substr ($ allbytes, 6, 15 );
Echo $ next1. "<br> ";
$ Next2 = substr ($ allbytes, 20, 15 );
Echo $ next2. "<br> ";
$ Next3 = substr ($ allbytes, 35, 15 );
Echo $ next3. "<br> ";
$ Next4 = substr ($ allbytes, 50, 15 );
Echo $ next4. "<br> ";
Echo "RECT binary value:". (bindec ($ next1)/20). "<br> ";
Echo "RECT binary value:". (bindec ($ next2)/20). "<br> ";
Echo "RECT binary value:". (bindec ($ next3)/20). "<br> ";
Echo "RECT binary value:". (bindec ($ next4)/20). "<br> ";
}
?> The output is probably like this:
RECT field size: 15
00
05
5f
00
00
0f
A0
00
01111
000000000000000
010101011111000
000000000000000
001111101000000
RECT binary value: 0
RECT binary value: 550
RECT binary value: 0
RECT binary value: 400