Results 1 to 4 of 4
July 7th, 2010, 10:18 AM #12,702Seņor Member
Reading AS3 ABC bytecode with a hex editor?
I have tried to learn a bit of the way AS3 works behind the scenes by skimming the surface of the AS3 bytecode.
I started with this document, and so far I'm at page 25 of 278.
I tried following along a bit, opening a SWF I had laying around and exploring the header. I was able to read the first 4 bytes until I got to "FrameSize". The data type for that was RECT (found on page 16)
The problem is, the first value of the RECT is stored as 5 BITS (not bytes). Since it doesn't round up to an even 16 bits per "chunk of data", it throws the "offset" of all bits off.
This means that unless I manually copy down the SWF hex values into binary data, reading this information simply with a Hex editor would not work, correct? Or is there anything I have missed such as some form of padding to offset this etc?
July 7th, 2010, 10:29 AM #2303Registered User
some hex editors I've used had shift parameters to offset the values a certain number of bits for this very thing.
If you can't find one, there are several open source ones that you could edit. Grab one in like C# or something, it'd be easy to put the feature in.www.lordofduct.com - come read my blog!
If you want to know how to program, take a math class, take a lot of math classes!
July 7th, 2010, 11:25 AM #32,702Seņor Member
Great. I was worried I had misread the documentation in some way.
One similar question (I'd rather not make an entirely new thread), starting from the 5th byte and spanning for 4 byes (a total of 32 bits) should give me the length of the SWF file.
According to that UB32, the file is "209,832" bytes long.
According to the file system, the entire file is only "123,127" bytes long.
Am I doing something wrong? Or will I get to that part in the documentation that elaborates on the FileSize what it actually refers to?
EDIT: I checked another SWF. The header says "1,020" bytes, and the file system says "657" bytes. There is definitely a relation between the two.
July 7th, 2010, 01:12 PM #4
If the SWF is compressed (which is true if the very first byte of the file is 0x43), then that filesize field refers to the size of the entire file after it's uncompressed. The first 8 bytes of a file are never compressed, but the rest can be uncompressed with ByteArray#uncompress.
You should look at senocular's SWFReader class: http://senocular.com/flash/actionscr...s/SWFReader.as
It doesn't parse bytecode, but it parses the SWF file to the point where you can get a ByteArray of each of the DoABC tags in the file, and then you could write a parser for that yourself (check your PMs for more on that).