hey,
Iv been working on an swf file generator following the specification, However i am currently struggling to have my binary output match the binary output of a swf file gengerated by flash CS3. The particular part i am struggling with is the file attributes tag, the specifications for the output are below :
header 10 bits, value always 69
reserved bit, value always 0
useDirectBlit.1 bit value 1 or 0
useGPU 1 bit, value 1 or 0
hasmetadata 1 bit value 1 or 0
actionscript3,1 bit value 1 or 0
supress cross domainc aching 1 bit value 1 or 0
swf relative urls.1 bit value 1 or 0
reserved bits. 2 bits both value 0
use network1 bit value 1 or 0
with that said, the output generated from my program is
10001010 00110000 10000000, or in hex 8A 30 80
Values from swf compiled in flash cs3 with the same settings are
01000100 01000100 01000100. or in hex 44 11 19
Quite a large difference at any rate considering i followed the specification letter for letter, It should be noted i tested adding in 3 extra bits at the left most part of the binary which results in hex output of 11 46 02 which was closer, however i removed it as it was not in the specification.
public String AttributeBuilder()
{
StringBuffer str = new StringBuffer();
str.append(Integer.toBinaryString(0));
str.append(Integer.toBinaryString(0));//add three reserved bits, removed is
str.append(Integer.toBinaryString(0));//further from result, dont know why its needed, not in spec
str.append(Integer.toBinaryString(69)); // ID
str.append(Integer.toBinaryString(0)); //reserved bit
str.append(Integer.toBinaryString(0)); //use blitting
str.append(Integer.toBinaryString(0)); //use GPU
str.append(Integer.toBinaryString(1)); //has meta data
str.append(Integer.toBinaryString(1)); //has actionscript 3 support
str.append(Integer.toBinaryString(0)); //domain cacheing
str.append(Integer.toBinaryString(0)); //relative urls
for(int i=0;i<2;i++)
{str.append(Integer.toBinaryString(0));} //insert reserved bits
int padlength = Integer.toBinaryString(1).length() + str.length() % 8;
str.append(padOut(Integer.toBinaryString(getUseNetwork()),padlength));
//pad final part to 8 bits to ensure no underflow prior to reserved bits
for(int i=0;i<24;i++)
{str.append(Integer.toBinaryString(0));}
//insert 24 reserved bits
String str2 = str.toString();
//final string
return str2;
}
private String padOut(String s, int len) {
if (s.length() >= len)
return s;
StringBuffer padding = new StringBuffer();
for (@SuppressWarnings("unused")
int p = 0; padding.length() + s.length() < len; p++)
padding.append("0");
return padding.toString() + s;
}
Despite the amount of time iv spent fiddling around with the values the closest i get is when i pad 3 0 values to the buffer at the start resulting in binary/hex output of 11 46 02, which is still far from what its meant to be. Any help resolving the difference would be grand :)