Jim G.
Jim G.

Reputation: 15363

From C# - Is there a way to determine if a swf is AVM1 or AVM2?

My Question:

Upvotes: 3

Views: 528

Answers (2)

Joony
Joony

Reputation: 4708

Sure. The .swf specification can be found here: http://www.adobe.com/content/dam/Adobe/en/devnet/swf/pdf/swf_file_format_spec_v10.pdf

FileAttributes, page 60, ActionScript3 UB[1]. If this bit is set then it's AVM2, otherwise it's AVM1. This is only available on .swfs of version 9 and above, but version 8 or below is guaranteed to be AVM1.

The quick way to get to that bit:

// Bytes from start of file: Signature + Version + FileLength + FrameSize + FrameRate + FrameCount + FileAttributes Header 
3 + 1 + 4 + (ceil(((swf[8] >> 3) * 4 - 3) / 8) + 1) + 2 + 2 + 2

swf[8] being the 8th byte of the swf. Read the next byte and it's the 5th bit.

You might have to decompress everything after FileLength if the file is compressed (byte 0 == 0x43). A swf is compressed using zlib and is Little Endian.

Upvotes: 6

poke
poke

Reputation: 387825

The ActionScript Virtual Machine 2 is the virtual machine for ActionScript 3. AVM1 is the virtual machine for both ActionScript 1 and 2. So if the ActionScript version is ACTIONSCRIPT2 it's AVM1, if it's ACTIONSCRIPT3 it's AVM2.

In regards to your updated question:

I don't think it is possible to read that information out with C# directly. I guess you want to include a SWF movie inside of C#; that way you basically just embed the Flash Player and tell it to play the movie. So you don't have a direct interaction with the movie from C#. It might be possible to contact the Flash Player instance and get information out but I don't know what kind of information is available (and I think it also depends on how you embed it).

You could however use Flash' ExternalInterface as a communication point (I guess, you can use the C# container as an external interface from Flash, just as you can communicate with JavaScript on a webpage) and simply “ask” the movie itself what version it is. As you are probably using some third-party files, you won't have access to their source, so you could write a wrapper SWF instead that loads the original files for you.

Regardless of how you do it, I wonder why you want that information. When you are playing an SWF movie somewhere, you basically couldn't care less what it does internally. The AVM version only matters when communicating with the movie directly.

Upvotes: 1

Related Questions